Patchwork [24/43] qemu-option: qemu_opts_validate(): fix duplicated code

login
register
mail settings
Submitter Kevin Wolf
Date Dec. 13, 2012, 3:10 p.m.
Message ID <1355411450-12761-25-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/206143/
State New
Headers show

Comments

Kevin Wolf - Dec. 13, 2012, 3:10 p.m.
From: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>

Use opts_accepts_any() and find_desc_by_name().

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-option.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)

Patch

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);