]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
qom: use object_new_with_class when possible
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 29 Oct 2024 09:45:51 +0000 (10:45 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 31 Oct 2024 17:28:32 +0000 (18:28 +0100)
A small optimization/code simplification, that also makes it clear that
we won't look for a type in a not-loaded-yet module---the module will
have been loaded by a call to module_object_class_by_name(), if present.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/core/qdev.c
qom/object_interfaces.c
qom/qom-qmp-cmds.c

index db36f54d914ac8efc0e3a60f29708748790471da..2f740fa55e96b78192d5c4ae4b9b329d2f788551 100644 (file)
@@ -167,10 +167,11 @@ DeviceState *qdev_new(const char *name)
 
 DeviceState *qdev_try_new(const char *name)
 {
-    if (!module_object_class_by_name(name)) {
+    ObjectClass *oc = module_object_class_by_name(name);
+    if (!oc) {
         return NULL;
     }
-    return DEVICE(object_new(name));
+    return DEVICE(object_new_with_class(oc));
 }
 
 static QTAILQ_HEAD(, DeviceListener) device_listeners
index e0833c8bfe48e8e9627e21846e70c3d53d969fc8..1f2aa1330667dcb200f32aad8d78d473f446b3c3 100644 (file)
@@ -108,7 +108,7 @@ Object *user_creatable_add_type(const char *type, const char *id,
     }
 
     assert(qdict);
-    obj = object_new(type);
+    obj = object_new_with_class(klass);
     object_set_properties_from_qdict(obj, qdict, v, &local_err);
     if (local_err) {
         goto out;
index e91a2353472a54dac852494a27a037228134bce8..69a8e17aa80dd7e3e152747f57c7086e76f87d6d 100644 (file)
@@ -141,7 +141,7 @@ ObjectPropertyInfoList *qmp_device_list_properties(const char *typename,
         return NULL;
     }
 
-    obj = object_new(typename);
+    obj = object_new_with_class(klass);
 
     object_property_iter_init(&iter, obj);
     while ((prop = object_property_iter_next(&iter))) {