diff mbox series

[v2,38/44] qapi: Smooth another visitor error checking pattern

Message ID 20200702155000.3455325-39-armbru@redhat.com
State Superseded
Headers show
Series Less clumsy error checking | expand

Commit Message

Markus Armbruster July 2, 2020, 3:49 p.m. UTC
Convert

    visit_type_FOO(v, ..., &ptr, &err);
    ...
    if (err) {
	...
    }

to

    visit_type_FOO(v, ..., &ptr, errp);
    ...
    if (!ptr) {
	...
    }

for functions that set @ptr to non-null / null on success / error.

Eliminate error_propagate() that are now unnecessary.  Delete @err
that are now unused.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 block/nfs.c          |  7 ++-----
 block/parallels.c    |  6 ++----
 block/qcow.c         |  6 ++----
 block/qcow2.c        |  7 ++-----
 block/qed.c          |  6 ++----
 block/rbd.c          |  7 ++-----
 block/sheepdog.c     |  6 ++----
 block/ssh.c          |  6 ++----
 block/vdi.c          |  7 ++-----
 block/vhdx.c         |  6 ++----
 block/vpc.c          |  6 ++----
 hw/acpi/core.c       |  4 ++--
 hw/block/xen-block.c |  6 ++----
 hw/core/numa.c       |  7 +++----
 monitor/monitor.c    | 21 +++++++--------------
 15 files changed, 36 insertions(+), 72 deletions(-)
diff mbox series

Patch

diff --git a/block/nfs.c b/block/nfs.c
index b1718d125a..61a249a9fc 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -563,18 +563,15 @@  static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options,
     BlockdevOptionsNfs *opts = NULL;
     Visitor *v;
     const QDictEntry *e;
-    Error *local_err = NULL;
 
     v = qobject_input_visitor_new_flat_confused(options, errp);
     if (!v) {
         return NULL;
     }
 
-    visit_type_BlockdevOptionsNfs(v, NULL, &opts, &local_err);
+    visit_type_BlockdevOptionsNfs(v, NULL, &opts, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!opts) {
         return NULL;
     }
 
diff --git a/block/parallels.c b/block/parallels.c
index c259799111..f489c0d4ba 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -667,11 +667,9 @@  static int coroutine_fn parallels_co_create_opts(BlockDriver *drv,
         goto done;
     }
 
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto done;
     }
diff --git a/block/qcow.c b/block/qcow.c
index 7913d12d50..c22d1bf6b8 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -994,11 +994,9 @@  static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
         goto fail;
     }
 
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto fail;
     }
diff --git a/block/qcow2.c b/block/qcow2.c
index a9137a535b..9ed2396c88 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3683,7 +3683,6 @@  static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
     Visitor *v;
     BlockDriverState *bs = NULL;
     BlockDriverState *data_bs = NULL;
-    Error *local_err = NULL;
     const char *val;
     int ret;
 
@@ -3779,11 +3778,9 @@  static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
         goto finish;
     }
 
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto finish;
     }
diff --git a/block/qed.c b/block/qed.c
index 3d5ddd86f2..7fa7f880f6 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -770,11 +770,9 @@  static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv,
         goto fail;
     }
 
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto fail;
     }
diff --git a/block/rbd.c b/block/rbd.c
index 617553b022..688074c64b 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -681,7 +681,6 @@  static int qemu_rbd_convert_options(QDict *options, BlockdevOptionsRbd **opts,
                                     Error **errp)
 {
     Visitor *v;
-    Error *local_err = NULL;
 
     /* Convert the remaining options into a QAPI object */
     v = qobject_input_visitor_new_flat_confused(options, errp);
@@ -689,11 +688,9 @@  static int qemu_rbd_convert_options(QDict *options, BlockdevOptionsRbd **opts,
         return -EINVAL;
     }
 
-    visit_type_BlockdevOptionsRbd(v, NULL, opts, &local_err);
+    visit_type_BlockdevOptionsRbd(v, NULL, opts, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!opts) {
         return -EINVAL;
     }
 
diff --git a/block/sheepdog.c b/block/sheepdog.c
index a6a91442c9..6c487c8322 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -2193,11 +2193,9 @@  static int coroutine_fn sd_co_create_opts(BlockDriver *drv,
         goto fail;
     }
 
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto fail;
     }
diff --git a/block/ssh.c b/block/ssh.c
index 3aa40410da..ebe3d8b631 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -635,11 +635,9 @@  static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
         goto fail;
     }
 
-    visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err);
+    visit_type_BlockdevOptionsSsh(v, NULL, &result, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!result) {
         goto fail;
     }
 
diff --git a/block/vdi.c b/block/vdi.c
index 2f506a01ba..0a60be773e 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -907,7 +907,6 @@  static int coroutine_fn vdi_co_create_opts(BlockDriver *drv,
     uint64_t block_size = DEFAULT_CLUSTER_SIZE;
     bool is_static = false;
     Visitor *v;
-    Error *local_err = NULL;
     int ret;
 
     /* Parse options and convert legacy syntax.
@@ -958,11 +957,9 @@  static int coroutine_fn vdi_co_create_opts(BlockDriver *drv,
         ret = -EINVAL;
         goto done;
     }
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto done;
     }
diff --git a/block/vhdx.c b/block/vhdx.c
index 3e175ed440..eed9c3b860 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -2107,11 +2107,9 @@  static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv,
         goto fail;
     }
 
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto fail;
     }
diff --git a/block/vpc.c b/block/vpc.c
index b6053da17b..77043c2424 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -1134,11 +1134,9 @@  static int coroutine_fn vpc_co_create_opts(BlockDriver *drv,
         goto fail;
     }
 
-    visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err);
+    visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!create_options) {
         ret = -EINVAL;
         goto fail;
     }
diff --git a/hw/acpi/core.c b/hw/acpi/core.c
index 226f2496ac..f6d9ec4f13 100644
--- a/hw/acpi/core.c
+++ b/hw/acpi/core.c
@@ -248,11 +248,11 @@  void acpi_table_add(const QemuOpts *opts, Error **errp)
         Visitor *v;
 
         v = opts_visitor_new(opts);
-        visit_type_AcpiTableOptions(v, NULL, &hdrs, &err);
+        visit_type_AcpiTableOptions(v, NULL, &hdrs, errp);
         visit_free(v);
     }
 
-    if (err) {
+    if (!hdrs) {
         goto out;
     }
     if (hdrs->has_file == hdrs->has_data) {
diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c
index 96c6c009c7..a775fba7c0 100644
--- a/hw/block/xen-block.c
+++ b/hw/block/xen-block.c
@@ -682,11 +682,9 @@  static char *xen_block_blockdev_add(const char *id, QDict *qdict,
     trace_xen_block_blockdev_add(node_name);
 
     v = qobject_input_visitor_new(QOBJECT(qdict));
-    visit_type_BlockdevOptions(v, NULL, &options, &local_err);
+    visit_type_BlockdevOptions(v, NULL, &options, errp);
     visit_free(v);
-
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!options) {
         goto fail;
     }
 
diff --git a/hw/core/numa.c b/hw/core/numa.c
index d208fd5008..c83f1f01c4 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -516,10 +516,10 @@  static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
     Error *err = NULL;
     Visitor *v = opts_visitor_new(opts);
 
-    visit_type_NumaOptions(v, NULL, &object, &err);
+    visit_type_NumaOptions(v, NULL, &object, errp);
     visit_free(v);
-    if (err) {
-        goto end;
+    if (!object) {
+        return -1;
     }
 
     /* Fix up legacy suffix-less format */
@@ -530,7 +530,6 @@  static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
 
     set_numa_options(ms, object, &err);
 
-end:
     qapi_free_NumaOptions(object);
     if (err) {
         error_propagate(errp, err);
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 125494410a..47167ac2a3 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -656,25 +656,18 @@  int monitor_init_opts(QemuOpts *opts, Error **errp)
 {
     Visitor *v;
     MonitorOptions *options;
-    Error *local_err = NULL;
+    int ret;
 
     v = opts_visitor_new(opts);
-    visit_type_MonitorOptions(v, NULL, &options, &local_err);
+    visit_type_MonitorOptions(v, NULL, &options, errp);
     visit_free(v);
-
-    if (local_err) {
-        goto out;
-    }
-
-    monitor_init(options, true, &local_err);
-    qapi_free_MonitorOptions(options);
-
-out:
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (!options) {
         return -1;
     }
-    return 0;
+
+    ret = monitor_init(options, true, errp);
+    qapi_free_MonitorOptions(options);
+    return ret;
 }
 
 QemuOptsList qemu_mon_opts = {