From patchwork Thu Sep 27 05:14:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Wang X-Patchwork-Id: 187274 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 CF16E2C0094 for ; Thu, 27 Sep 2012 15:14:36 +1000 (EST) Received: from localhost ([::1]:34036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TH6Qk-0007RE-Qu for incoming@patchwork.ozlabs.org; Thu, 27 Sep 2012 01:14:34 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55188) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TH6QR-0007Es-42 for qemu-devel@nongnu.org; Thu, 27 Sep 2012 01:14:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TH6QQ-0003YT-6d for qemu-devel@nongnu.org; Thu, 27 Sep 2012 01:14:15 -0400 Received: from mail-oa0-f45.google.com ([209.85.219.45]:37197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TH6QP-0003X6-Vt for qemu-devel@nongnu.org; Thu, 27 Sep 2012 01:14:14 -0400 Received: by mail-oa0-f45.google.com with SMTP id i18so1324797oag.4 for ; Wed, 26 Sep 2012 22:14:13 -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=iNDkio1w0uvkSXuUPeLdVHj2e/2OkUB3eLyrNlIo0xI=; b=C/GB7eLhPGW408buF10uMRepR+nWLbICMS8GiBs9/IQjStIuOzB/JP0VdqwG5z/JJx 0Pp9rytR9p8DMg5JsogqmXP5QvnKeFWNMElbyBLN2UMKF745fp9BOnfwdUILYL/3OHd0 6+kTi1ksw/miFryiH8gxdIym9w5QsgY70w+9JljQsBc7kPQJ0+gCslhXhTuvvGzpm9be oUTfQokQZpY2BPboNa/BqWQZTOIYz8URQdbQWQrGjOPx4Yo5TnHwMHLWAleMqtFeVzwb a4zKEB8bBgyEzgTxhEe8cdD5Vrg5HJoOX7ZyhfW2G96MZCBF/kw5Dtna6cOg7TzZ5eqN wfBA== Received: by 10.60.170.200 with SMTP id ao8mr2178350oec.104.1348722853790; Wed, 26 Sep 2012 22:14:13 -0700 (PDT) Received: from localhost.localdomain ([202.108.130.138]) by mx.google.com with ESMTPS id q6sm3833954oec.7.2012.09.26.22.14.11 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Sep 2012 22:14:13 -0700 (PDT) From: Dong Xu Wang To: qemu-devel@nongnu.org Date: Thu, 27 Sep 2012 13:14:21 +0800 Message-Id: <1348722865-20564-4-git-send-email-wdongxu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1348722865-20564-1-git-send-email-wdongxu@linux.vnet.ibm.com> References: <1348722865-20564-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.219.45 Cc: kwolf@redhat.com, Dong Xu Wang , armbru@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [RFC v2 3/7] 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 d8b0988..b7baacc 100644 --- a/qemu-option.c +++ b/qemu-option.c @@ -1050,23 +1050,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);