From patchwork Thu Dec 6 06:47:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 204148 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 790702C0189 for ; Thu, 6 Dec 2012 17:48:16 +1100 (EST) Received: from localhost ([::1]:53876 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVFm-0006EL-El for incoming@patchwork.ozlabs.org; Thu, 06 Dec 2012 01:48:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVFT-00067J-Bt for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:47:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TgVFO-0005JM-42 for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:47:55 -0500 Received: from mail-ia0-f173.google.com ([209.85.210.173]:35819) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TgVFN-0005JB-Vc for qemu-devel@nongnu.org; Thu, 06 Dec 2012 01:47:50 -0500 Received: by mail-ia0-f173.google.com with SMTP id w21so4510809iac.4 for ; Wed, 05 Dec 2012 22:47:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=dmYY5by0aed+1rYylf25nnPJFO+n5yJoe8FGJ3oi7s8=; b=Q3+UKVZQ5XZbkosTBCP/gslKkxJzr9BwHsqywTHzYIrbSkga7X06L51RDY6BnROYbN ghVfM905w71M64N3mXBl4ggcSQRlk7Mx8a9wQRXJK7Rnqazc4SGsYGm2k5/TbsD8IC7F UzG6JF56mnpoFuicP5aWdtOBMfY6Fwr/4ninw2InYN17wVG62Nw+Arb1q29ZFb7oBo6Q e7uNebKGKoMpA6dRNeT40kgObn9awc0hZITpK1elM4LN+gTqRmZX4WYQ3Il+Dh75EFut ziO8BQj75XAdbXkrEvFlss0Wqx8s7PculDNedaoyKAnSbnwihrbVT6geR7ROtOYkRk4T ORCQ== Received: by 10.43.9.131 with SMTP id ow3mr428279icb.21.1354776469174; Wed, 05 Dec 2012 22:47:49 -0800 (PST) Received: from localhost.localdomain ([202.108.130.153]) by mx.google.com with ESMTPS id kp4sm6494017igc.1.2012.12.05.22.47.46 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Dec 2012 22:47:48 -0800 (PST) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 6 Dec 2012 14:47:19 +0800 Message-Id: <1354776447-12041-3-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1354776447-12041-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1354776447-12041-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.210.173 Cc: kwolf@redhat.com, Dong Xu Wang , Luiz Capitulino Subject: [Qemu-devel] [PATCH V7 02/10] qemu-option: qemu_opts_validate(): fix duplicated code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Use opts_accepts_any() and find_desc_by_name(). Signed-off-by: Luiz Capitulino Signed-off-by: Dong Xu Wang --- qemu-option.c | 14 +++----------- 1 files changed, 3 insertions(+), 11 deletions(-) diff --git a/qemu-option.c b/qemu-option.c index 375daaa..74321bb 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -1076,23 +1076,15 @@ void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp) QemuOpt *opt; Error *local_err = NULL; - assert(opts->list->desc[0].name == NULL); + assert(opts_accepts_any(opts)); QTAILQ_FOREACH(opt, &opts->head, next) { - int i; - - for (i = 0; desc[i].name != NULL; i++) { - if (strcmp(desc[i].name, opt->name) == 0) { - break; - } - } - if (desc[i].name == NULL) { + opt->desc = find_desc_by_name(desc, opt->name); + if (!opt->desc) { error_set(errp, QERR_INVALID_PARAMETER, opt->name); return; } - opt->desc = &desc[i]; - qemu_opt_parse(opt, &local_err); if (error_is_set(&local_err)) { error_propagate(errp, local_err);