diff mbox series

[v2,2/3] qom/object_interfaces: Make object_set_properties_from_qdict return bool

Message ID 20240318033211.459006-3-zhenzhong.duan@intel.com (mailing list archive)
State New, archived
Headers show
Series Simplify user_creatable_add_type error path | expand

Commit Message

Duan, Zhenzhong March 18, 2024, 3:32 a.m. UTC
Make object_set_properties_from_qdict() return bool, so that
user_creatable_add_type() could check its return value instead
of local_err pointer.

Opportunistically, do the same change to check return value of
object_property_try_add_child() instead of local_err pointer.

Suggested-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
 qom/object_interfaces.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

Comments

Zhao Liu March 18, 2024, 8:56 a.m. UTC | #1
On Mon, Mar 18, 2024 at 11:32:09AM +0800, Zhenzhong Duan wrote:
> Date: Mon, 18 Mar 2024 11:32:09 +0800
> From: Zhenzhong Duan <zhenzhong.duan@intel.com>
> Subject: [PATCH v2 2/3] qom/object_interfaces: Make
>  object_set_properties_from_qdict return bool
> X-Mailer: git-send-email 2.34.1
> 
> Make object_set_properties_from_qdict() return bool, so that
> user_creatable_add_type() could check its return value instead
> of local_err pointer.
> 
> Opportunistically, do the same change to check return value of
> object_property_try_add_child() instead of local_err pointer.
> 
> Suggested-by: Zhao Liu <zhao1.liu@intel.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> ---
>  qom/object_interfaces.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
diff mbox series

Patch

diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c
index 70179877f1..e17e2de46d 100644
--- a/qom/object_interfaces.c
+++ b/qom/object_interfaces.c
@@ -43,22 +43,25 @@  bool user_creatable_can_be_deleted(UserCreatable *uc)
     }
 }
 
-static void object_set_properties_from_qdict(Object *obj, const QDict *qdict,
+static bool object_set_properties_from_qdict(Object *obj, const QDict *qdict,
                                              Visitor *v, Error **errp)
 {
     const QDictEntry *e;
+    bool ret;
 
     if (!visit_start_struct(v, NULL, NULL, 0, errp)) {
-        return;
+        return false;
     }
     for (e = qdict_first(qdict); e; e = qdict_next(qdict, e)) {
-        if (!object_property_set(obj, e->key, v, errp)) {
+        ret = object_property_set(obj, e->key, v, errp);
+        if (!ret) {
             goto out;
         }
     }
-    visit_check_struct(v, errp);
+    ret = visit_check_struct(v, errp);
 out:
     visit_end_struct(v, NULL);
+    return ret;
 }
 
 void object_set_properties_from_keyval(Object *obj, const QDict *qdict,
@@ -109,17 +112,13 @@  Object *user_creatable_add_type(const char *type, const char *id,
 
     assert(qdict);
     obj = object_new(type);
-    object_set_properties_from_qdict(obj, qdict, v, &local_err);
-    if (local_err) {
+    if (!object_set_properties_from_qdict(obj, qdict, v, &local_err)) {
         goto err;
     }
 
-    if (id != NULL) {
-        object_property_try_add_child(object_get_objects_root(),
-                                      id, obj, &local_err);
-        if (local_err) {
+    if (id != NULL && !object_property_try_add_child(object_get_objects_root(),
+                                                     id, obj, &local_err)) {
             goto err;
-        }
     }
 
     if (!user_creatable_complete(USER_CREATABLE(obj), &local_err)) {