From patchwork Fri Nov 23 07:47:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 201247 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 7B5032C0097 for ; Fri, 23 Nov 2012 18:48:42 +1100 (EST) Received: from localhost ([::1]:35832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbo08-0003jq-FX for incoming@patchwork.ozlabs.org; Fri, 23 Nov 2012 02:48:40 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbnzt-0003f2-L7 for qemu-devel@nongnu.org; Fri, 23 Nov 2012 02:48:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tbnzs-0001sL-FS for qemu-devel@nongnu.org; Fri, 23 Nov 2012 02:48:25 -0500 Received: from mail-ia0-f173.google.com ([209.85.210.173]:48447) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbnzs-0001sF-9f for qemu-devel@nongnu.org; Fri, 23 Nov 2012 02:48:24 -0500 Received: by mail-ia0-f173.google.com with SMTP id w21so4838334iac.4 for ; Thu, 22 Nov 2012 23:48:23 -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=J+fFlPBIMmdZhusthSFEdy3f9m0EQVHyO3hfnREfQ8lKGh90uZiU8zkbJ4oV7FnIuq FEoO7LlCe1y/vLm31xAKSI1p5ojX2TGFUZiHRlSgiHn+fDgwesq15VECDl+p1evGatgJ 4JPGNan5Bez7/mLquWTaSvZEI33hb9xNXlbD/6mg5OA2VYi7CJmMS1bZdaPRd3Vsg7kl LeAPqsBsropz26ygh/OJylRzK7+iakeBi9Z+C6sLllgxSCaS+fTF6WhGqQ01WY2iRl4+ vi2cd5KWoY7cyhTiZ6AdeyA1nkYMSL6i+k8hJrpmneMC0uv1l2IOUyA5QMNSIiO3edn1 Srfg== Received: by 10.50.1.170 with SMTP id 10mr2836343ign.2.1353656903761; Thu, 22 Nov 2012 23:48:23 -0800 (PST) Received: from localhost.localdomain ([202.108.130.194]) by mx.google.com with ESMTPS id az6sm3859043igb.11.2012.11.22.23.48.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 22 Nov 2012 23:48:23 -0800 (PST) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Fri, 23 Nov 2012 15:47:37 +0800 Message-Id: <1353656865-20910-3-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1353656865-20910-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1353656865-20910-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 V6 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);