diff mbox series

[RFC,01/40] qdev: Don't always force the global property array non-null

Message ID 20230103181646.55711-2-richard.henderson@linaro.org
State New
Headers show
Series Toward class init of cpu features | expand

Commit Message

Richard Henderson Jan. 3, 2023, 6:16 p.m. UTC
Only qdev_prop_register_global requires a non-null array.
The other instances can simply exit early.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 hw/core/qdev-properties.c | 43 ++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 16 deletions(-)

Comments

Philippe Mathieu-Daudé Jan. 5, 2023, 9:56 p.m. UTC | #1
On 3/1/23 19:16, Richard Henderson wrote:
> Only qdev_prop_register_global requires a non-null array.
> The other instances can simply exit early.
> 
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   hw/core/qdev-properties.c | 43 ++++++++++++++++++++++++---------------
>   1 file changed, 27 insertions(+), 16 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 357b8761b5..f7775d0ea4 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -739,29 +739,31 @@  void qdev_prop_set_enum(DeviceState *dev, const char *name, int value)
                             &error_abort);
 }
 
-static GPtrArray *global_props(void)
-{
-    static GPtrArray *gp;
-
-    if (!gp) {
-        gp = g_ptr_array_new();
-    }
-
-    return gp;
-}
+static GPtrArray *global_properties;
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    g_ptr_array_add(global_props(), prop);
+    GPtrArray *props = global_properties;
+
+    if (!props) {
+        props = g_ptr_array_new();
+        global_properties = props;
+    }
+
+    g_ptr_array_add(props, prop);
 }
 
 const GlobalProperty *qdev_find_global_prop(Object *obj,
                                             const char *name)
 {
-    GPtrArray *props = global_props();
+    GPtrArray *props = global_properties;
     const GlobalProperty *p;
     int i;
 
+    if (!props) {
+        return NULL;
+    }
+
     for (i = 0; i < props->len; i++) {
         p = g_ptr_array_index(props, i);
         if (object_dynamic_cast(obj, p->driver)
@@ -774,14 +776,19 @@  const GlobalProperty *qdev_find_global_prop(Object *obj,
 
 int qdev_prop_check_globals(void)
 {
+    GPtrArray *props = global_properties;
     int i, ret = 0;
 
-    for (i = 0; i < global_props()->len; i++) {
+    if (!props) {
+        return 0;
+    }
+
+    for (i = 0; i < props->len; i++) {
         GlobalProperty *prop;
         ObjectClass *oc;
         DeviceClass *dc;
 
-        prop = g_ptr_array_index(global_props(), i);
+        prop = g_ptr_array_index(props, i);
         if (prop->used) {
             continue;
         }
@@ -806,8 +813,12 @@  int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    object_apply_global_props(OBJECT(dev), global_props(),
-                              dev->hotplugged ? NULL : &error_fatal);
+    GPtrArray *props = global_properties;
+
+    if (props) {
+        object_apply_global_props(OBJECT(dev), props,
+                                  dev->hotplugged ? NULL : &error_fatal);
+    }
 }
 
 /* --- 64bit unsigned int 'size' type --- */