From patchwork Sun Oct 14 12:51:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 191355 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 DD2AC2C008B for ; Mon, 15 Oct 2012 00:14:18 +1100 (EST) Received: from localhost ([::1]:56424 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNO1I-0001dN-VT for incoming@patchwork.ozlabs.org; Sun, 14 Oct 2012 09:14:16 -0400 Received: from eggs.gnu.org ([208.118.235.92]:36109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNNfu-000571-JD for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TNNft-0003YM-BR for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:10 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:52257) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TNNfs-0003X4-2K for qemu-devel@nongnu.org; Sun, 14 Oct 2012 08:52:09 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so4084857pbb.4 for ; Sun, 14 Oct 2012 05:52:01 -0700 (PDT) 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=rh1ZK94J4cXaAOp/3JYui0bdHKmxVdMY7PQ2sQUVO537yC9txOKSWmn7F6Ub0q685C rHM/gifvCxZqqHb0G+o71tF5gGyU8fd4UKw5MXCrKjpFTMrl7Y7K2IXbSvYHRnaHhQom WGYdrBg217sUoAnIs594hPWCc8vke14SOiI/G+z/Y3j8jgCIxlBlkH5eToQ9z1FJ5FdV 4JKxVbnVolaFJASzGRI/1TxJaI4iBC6bOhYajy27l+6q0LoYCgaQmlMTlSg6+9bn91/h M8Hv+NXBdik0UznkJ6uuJFbpb8Wk/2AnTeaFLu0kN4KOV3BozowdbDI8Jvd4CYvAOfpO /E0Q== Received: by 10.68.195.195 with SMTP id ig3mr29267857pbc.108.1350219121149; Sun, 14 Oct 2012 05:52:01 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id nt7sm7447649pbb.33.2012.10.14.05.51.58 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 14 Oct 2012 05:52:00 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Sun, 14 Oct 2012 20:51:27 +0800 Message-Id: <1350219095-3378-3-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1350219095-3378-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1350219095-3378-1-git-send-email-wdongxu@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: kwolf@redhat.com, Dong Xu Wang , Luiz Capitulino Subject: [Qemu-devel] [PATCH V3 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);