diff mbox series

[39/46] qom: Smooth error checking manually

Message ID 20200624164344.3778251-40-armbru@redhat.com
State New
Headers show
Series [01/46] error: Improve examples in error.h's big comment | expand

Commit Message

Markus Armbruster June 24, 2020, 4:43 p.m. UTC
When foo(..., &err) is followed by error_propagate(errp, err), we can
often just as well do foo(..., errp).  The previous commit did that
for simple cases with Coccinelle.  Do it for a few more manually.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/core/bus.c              |  6 +-----
 hw/s390x/s390-virtio-ccw.c | 15 +++++++--------
 qom/object.c               |  9 ++-------
 qom/qom-qobject.c          |  5 +----
 target/i386/cpu.c          | 19 +++++--------------
 5 files changed, 16 insertions(+), 38 deletions(-)
diff mbox series

Patch

diff --git a/hw/core/bus.c b/hw/core/bus.c
index 00d1d31762..6b987b6946 100644
--- a/hw/core/bus.c
+++ b/hw/core/bus.c
@@ -166,11 +166,7 @@  BusState *qbus_create(const char *typename, DeviceState *parent, const char *nam
 
 bool qbus_realize(BusState *bus, Error **errp)
 {
-    Error *err = NULL;
-
-    object_property_set_bool(OBJECT(bus), "realized", true, &err);
-    error_propagate(errp, err);
-    return !err;
+    return object_property_set_bool(OBJECT(bus), "realized", true, errp);
 }
 
 void qbus_unrealize(BusState *bus)
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 62af349c31..877ea2af9d 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -69,20 +69,19 @@  static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
                               Error **errp)
 {
     S390CPU *cpu = S390_CPU(object_new(typename));
-    Error *err = NULL;
+    S390CPU *ret = NULL;
 
-    if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, &err)) {
+    if (!object_property_set_int(OBJECT(cpu), "core-id", core_id, errp)) {
         goto out;
     }
-    qdev_realize(DEVICE(cpu), NULL, &err);
+    if (!qdev_realize(DEVICE(cpu), NULL, errp)) {
+        goto out;
+    }
+    ret = cpu;
 
 out:
     object_unref(OBJECT(cpu));
-    if (err) {
-        error_propagate(errp, err);
-        cpu = NULL;
-    }
-    return cpu;
+    return ret;
 }
 
 static void s390_init_cpus(MachineState *machine)
diff --git a/qom/object.c b/qom/object.c
index eb814e41be..684540a09f 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -547,7 +547,6 @@  bool object_initialize_child_with_propsv(Object *parentobj,
                               void *childobj, size_t size, const char *type,
                               Error **errp, va_list vargs)
 {
-    Error *local_err = NULL;
     bool ok = false;
     Object *obj;
     UserCreatable *uc;
@@ -563,7 +562,7 @@  bool object_initialize_child_with_propsv(Object *parentobj,
 
     uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
     if (uc) {
-        if (!user_creatable_complete(uc, &local_err)) {
+        if (!user_creatable_complete(uc, errp)) {
             object_unparent(obj);
             goto out;
         }
@@ -581,8 +580,6 @@  out:
      * the reference taken by object_property_add_child().
      */
     object_unref(obj);
-
-    error_propagate(errp, local_err);
     return ok;
 }
 
@@ -735,7 +732,6 @@  Object *object_new_with_propv(const char *typename,
 {
     Object *obj;
     ObjectClass *klass;
-    Error *local_err = NULL;
     UserCreatable *uc;
 
     klass = object_class_by_name(typename);
@@ -760,7 +756,7 @@  Object *object_new_with_propv(const char *typename,
 
     uc = (UserCreatable *)object_dynamic_cast(obj, TYPE_USER_CREATABLE);
     if (uc) {
-        if (!user_creatable_complete(uc, &local_err)) {
+        if (!user_creatable_complete(uc, errp)) {
             if (id != NULL) {
                 object_unparent(obj);
             }
@@ -772,7 +768,6 @@  Object *object_new_with_propv(const char *typename,
     return obj;
 
  error:
-    error_propagate(errp, local_err);
     object_unref(obj);
     return NULL;
 }
diff --git a/qom/qom-qobject.c b/qom/qom-qobject.c
index 62ac5e07ac..21ce22de94 100644
--- a/qom/qom-qobject.c
+++ b/qom/qom-qobject.c
@@ -34,15 +34,12 @@  QObject *object_property_get_qobject(Object *obj, const char *name,
                                      Error **errp)
 {
     QObject *ret = NULL;
-    Error *local_err = NULL;
     Visitor *v;
 
     v = qobject_output_visitor_new(&ret);
-    object_property_get(obj, name, v, &local_err);
-    if (!local_err) {
+    if (object_property_get(obj, name, v, errp)) {
         visit_complete(v, &ret);
     }
-    error_propagate(errp, local_err);
     visit_free(v);
     return ret;
 }
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 26ba40656d..b7c9f0fa72 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5251,16 +5251,13 @@  static void x86_cpu_to_dict_full(X86CPU *cpu, QDict *props)
 static void object_apply_props(Object *obj, QDict *props, Error **errp)
 {
     const QDictEntry *prop;
-    Error *err = NULL;
 
     for (prop = qdict_first(props); prop; prop = qdict_next(props, prop)) {
         if (!object_property_set_qobject(obj, qdict_entry_key(prop),
-                                         qdict_entry_value(prop), &err)) {
+                                         qdict_entry_value(prop), errp)) {
             break;
         }
     }
-
-    error_propagate(errp, err);
 }
 
 /* Create X86CPU object according to model+props specification */
@@ -6318,19 +6315,18 @@  static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
     FeatureWord w;
     int i;
     GList *l;
-    Error *local_err = NULL;
 
     for (l = plus_features; l; l = l->next) {
         const char *prop = l->data;
-        if (!object_property_set_bool(OBJECT(cpu), prop, true, &local_err)) {
-            goto out;
+        if (!object_property_set_bool(OBJECT(cpu), prop, true, errp)) {
+            return;
         }
     }
 
     for (l = minus_features; l; l = l->next) {
         const char *prop = l->data;
-        if (!object_property_set_bool(OBJECT(cpu), prop, false, &local_err)) {
-            goto out;
+        if (!object_property_set_bool(OBJECT(cpu), prop, false, errp)) {
+            return;
         }
     }
 
@@ -6428,11 +6424,6 @@  static void x86_cpu_expand_features(X86CPU *cpu, Error **errp)
     if (env->cpuid_xlevel2 == UINT32_MAX) {
         env->cpuid_xlevel2 = env->cpuid_min_xlevel2;
     }
-
-out:
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
-    }
 }
 
 /*