Skip to contentSkip to conversation

hw/i386: convert object props to class props

PATCH Superseded Mark Cave-Ayland 5 participants 15 messages Sep 2 – Sep 21

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover hw/i386: convert object props to class props

Since the use of object props is effectively deprecated, here is an attempt to convert all use of object props in hw/i386 to class props. The eventual aim is to continue working through the codebase, removing all remaining uses of object props.

In order to facilitate the conversion of alias properties, this series introduces a couple of new QOM functions: object_class_property_add_alias() and object_property_set_alias() to declare the property and to set it within an instance accordingly. This implementation is hugely inspired by the existing link class property code: many thanks to Marc-André for doing this initial work.

The series is lightly tested: it passes "make check", GitLab CI and some simple local tests. I'm mostly interested for feedback on the conversion strategy, and to get a feel for the best way to merge this series since once the basic conversion patterns are in place, the same patterns can be applied elsewhere and it would be good to minimise the merge window for such changes.

(Patches still needing review: 1-4)

v3:
- Rebase onto master

- Add R-B tags from Phil

- Add kernel-doc to patch 2 for the object_class_property_add_alias() function

- Update refcounting for alias class properties according to the description in the kernel-doc for object_property_set_alias() which is taken from the existing object_property_add_alias() kernel-doc

v2:
- Rebase onto master

- Add R-B tags from Daniel

- Update comment on patch 7 to explicitly describe the change in behaviour of the pflash0 and pflash1 PC machine properties

Mark Cave-Ayland (8):
qom/object.c: introduce object_alias_get_targetp() lookup function qom/object.c: introduce object_class_property_add_alias() qom/object.c: introduce object_property_set_alias() function hw/i386/pc.c: convert pcspk-audiodev object prop to a class prop hw/i386/pc.c: convert rtc-time object prop to a class prop hw/i386/pc.c: convert PC_MACHINE_ACPI_DEVICE_PROP from object prop to
class prop
hw/i386/pc_sysfw.c: convert pflash0 and pflash1 object props to class
props
hw/i386/sgx-epc.c: convert SGX_EPC_SIZE_PROP object prop to class prop

 include/hw/i386/pc.h |   5 ++
 include/qom/object.h |  42 +++++++++++++
 hw/i386/pc.c         |  29 +++++++--
 hw/i386/pc_piix.c    |   5 --
 hw/i386/pc_q35.c     |   5 --
 hw/i386/pc_sysfw.c   |   7 +--
 hw/i386/sgx-epc.c    |  12 ++--
 qom/object.c         | 146 ++++++++++++++++++++++++++++++++++++++++---
 8 files changed, 213 insertions(+), 38 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/8 qom/object.c: introduce object_alias_get_targetp() lookup function

This will be used later to add support for alias class properties.

---
 qom/object.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
qom/object.c +12 -3
index 85bbd7f9fe..a904f53ed6 100644
@@ -3043,13 +3043,20 @@ typedef struct {
     char *target_name;
 } AliasProperty;
 
+static Object **
+object_alias_get_targetp(Object *obj, AliasProperty *lprop)
+{
+    return &lprop->target_obj;
+}
+
 static void property_get_alias(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
     AliasProperty *prop = opaque;
+    Object **target_obj = object_alias_get_targetp(obj, prop);
     Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
 
-    object_property_get(prop->target_obj, prop->target_name, alias_v, errp);
+    object_property_get(*target_obj, prop->target_name, alias_v, errp);
     visit_free(alias_v);
 }
 
@@ -3057,9 +3064,10 @@ static void property_set_alias(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
     AliasProperty *prop = opaque;
+    Object **target_obj = object_alias_get_targetp(obj, prop);
     Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
 
-    object_property_set(prop->target_obj, prop->target_name, alias_v, errp);
+    object_property_set(*target_obj, prop->target_name, alias_v, errp);
     visit_free(alias_v);
 }
 
@@ -3067,8 +3075,9 @@ static Object *property_resolve_alias(Object *obj, void *opaque,
                                       const char *part)
 {
     AliasProperty *prop = opaque;
+    Object **target_obj = object_alias_get_targetp(obj, prop);
 
-    return object_resolve_path_component(prop->target_obj, prop->target_name);
+    return object_resolve_path_component(*target_obj, prop->target_name);
 }
 
 static void property_release_alias(Object *obj, const char *name, void *opaque)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/8 qom/object.c: introduce object_class_property_add_alias()

In reply to Mark Cave-Ayland

This is eventually intended to be a replacement for object_property_add_alias() which uses an object property instead of a class property.

With the advent of class properties, it is possible that QOM may attempt to set or retrieve the value of an unset alias property. Update the existing property_get_alias() and property_set_alias() functions to use the null visitor if the alias target has not been set, and property_resolve_alias() to return NULL for the same case.

This ensures that unset class alias properties accessed e.g. via the monitor do not cause QEMU to crash.

---
 include/qom/object.h |  25 +++++++++++
 qom/object.c         | 100 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 113 insertions(+), 12 deletions(-)
include/qom/object.h +25 -0
index e24f0a2b2d..96c76975ef 100644
@@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
                                           const uint64_t *v,
                                           ObjectPropertyFlags flags);
 
+typedef enum {
+    /* private */
+    OBJ_PROP_ALIAS_CLASS = 0x1,
+} ObjectPropertyAliasFlags;
+
 /**
  * object_property_add_alias:
  * @obj: the object to add a property to
@@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
 ObjectProperty *object_property_add_alias(Object *obj, const char *name,
                                Object *target_obj, const char *target_name);
 
+/**
+ * object_class_property_add_alias:
+ * @klass: the object class to add a property to
+ * @name: the name of the property
+ * @offset: the offset from the object instance where the object alias is
+ *   stored
+ * @target_type: QOM type we expect the alias to resolve to
+ * @target_name: the name of the property on the forwarded object
+ *
+ * Add an alias for a property on an object.  This function will add a property
+ * of the same type as the forwarded property.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.
+ */
+ObjectProperty *
+object_class_property_add_alias(ObjectClass *klass, const char *name,
+                                ptrdiff_t offset,
+                                const char *target_type,
+                                const char *target_name);
+
 /**
  * object_property_add_const_link:
  * @obj: the object to add a property to
qom/object.c +88 -12

155 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias()

Hi

Quoted 42 lines · Mark Cave-Ayland

This is eventually intended to be a replacement for object_property_add_alias() which uses an object property instead of a class property.

With the advent of class properties, it is possible that QOM may attempt to set or retrieve the value of an unset alias property. Update the existing property_get_alias() and property_set_alias() functions to use the null visitor if the alias target has not been set, and property_resolve_alias() to return NULL for the same case.

This ensures that unset class alias properties accessed e.g. via the monitor do not cause QEMU to crash.

---
 include/qom/object.h |  25 +++++++++++
 qom/object.c         | 100 +++++++++++++++++++++++++++++++++++++------
 2 files changed, 113 insertions(+), 12 deletions(-)
include/qom/object.h +8 -0
index e24f0a2b2d..96c76975ef 100644
@@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
                                           const uint64_t *v,
                                           ObjectPropertyFlags flags);
 
+typedef enum {
+    /* private */
+    OBJ_PROP_ALIAS_CLASS = 0x1,
+} ObjectPropertyAliasFlags;
+
 /**
  * object_property_add_alias:
  * @obj: the object to add a property to
@@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
 ObjectProperty *object_property_add_alias(Object *obj, const char *name,
                                Object *target_obj, const char *target_name);
 
+/**
+ * object_class_property_add_alias:
+ * @klass: the object class to add a property to

include/qom/object.h ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass, · line 2303

Quoted 10 lines
include/qom/object.h +10 -0
+ * @name: the name of the property
+ * @offset: the offset from the object instance where the object alias is
+ *   stored
+ * @target_type: QOM type we expect the alias to resolve to
+ * @target_name: the name of the property on the forwarded object
+ *
+ * Add an alias for a property on an object.  This function will add a property
+ * of the same type as the forwarded property.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.

actually, it assert() on error and never returns NULL.

Quoted 57 lines
include/qom/object.h +7 -0
+ */
+ObjectProperty *
+object_class_property_add_alias(ObjectClass *klass, const char *name,
+                                ptrdiff_t offset,
+                                const char *target_type,
+                                const char *target_name);
+
 /**
  * object_property_add_const_link:
  * @obj: the object to add a property to
qom/object.c +13 -6
index a904f53ed6..9a05e189ea 100644
@@ -34,6 +34,7 @@
 #include "qom/qom-qobject.h"
 #include "qobject/qbool.h"
 #include "qobject/qlist.h"
+#include "qobject/qnull.h"
 #include "qobject/qnum.h"
 #include "qobject/qstring.h"
 #include "qemu/error-report.h"
@@ -3039,14 +3040,22 @@ object_class_static_property_add_uint64_ptr(ObjectClass *klass,
 }
 
 typedef struct {
-    Object *target_obj;
+    union {
+        Object *target_obj; /* if !OBJ_PROP_ALIAS_CLASS */
+        ptrdiff_t offset;   /* if OBJ_PROP_ALIAS_CLASS */
+    };
     char *target_name;
+    ObjectPropertyAliasFlags flags;
 } AliasProperty;
 
 static Object **
-object_alias_get_targetp(Object *obj, AliasProperty *lprop)
+object_alias_get_targetp(Object *obj, AliasProperty *aprop)
 {
-    return &lprop->target_obj;
+    if (aprop->flags & OBJ_PROP_ALIAS_CLASS) {
+        return (void *)obj + aprop->offset;
+    } else {
+        return &aprop->target_obj;
+    }
 }
 
 static void property_get_alias(Object *obj, Visitor *v, const char *name,
@@ -3054,10 +3063,18 @@ static void property_get_alias(Object *obj, Visitor *v, const char *name,
 {
     AliasProperty *prop = opaque;
     Object **target_obj = object_alias_get_targetp(obj, prop);
-    Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
 
-    object_property_get(*target_obj, prop->target_name, alias_v, errp);
-    visit_free(alias_v);
+    if (*target_obj) {

qom/object.c static void property_get_alias(Object *obj, Visitor *v, const char *name, · line 3077

Quoted 10 lines
qom/object.c +10 -0
+        Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
+
+        object_property_get(*target_obj, prop->target_name, alias_v, errp);
+        visit_free(alias_v);
+    } else {
+        QNull *null = NULL;
+
+        visit_type_null(v, NULL, &null, errp);
+        qnull_unref(null);
+    };

extra ;

Quoted 11 lines
qom/object.c +0 -3
 }
 
 static void property_set_alias(Object *obj, Visitor *v, const char *name,
@@ -3065,10 +3082,18 @@ static void property_set_alias(Object *obj, Visitor *v, const char *name,
 {
     AliasProperty *prop = opaque;
     Object **target_obj = object_alias_get_targetp(obj, prop);
-    Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
 
-    object_property_set(*target_obj, prop->target_name, alias_v, errp);
-    visit_free(alias_v);

qom/object.c static void property_set_alias(Object *obj, Visitor *v, const char *name, · line 3095

Quoted 10 lines
qom/object.c +10 -0
+    if (*target_obj) {
+        Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
+
+        object_property_set(*target_obj, prop->target_name, alias_v, errp);
+        visit_free(alias_v);
+    } else {
+        QNull *null = NULL;
+
+        visit_type_null(v, NULL, &null, errp);
+        qnull_unref(null);

Why not return an error?

Quoted 91 lines
qom/object.c +55 -4
+    }
 }
 
 static Object *property_resolve_alias(Object *obj, void *opaque,
@@ -3077,15 +3102,21 @@ static Object *property_resolve_alias(Object *obj, void *opaque,
     AliasProperty *prop = opaque;
     Object **target_obj = object_alias_get_targetp(obj, prop);
 
-    return object_resolve_path_component(*target_obj, prop->target_name);
+    if (*target_obj) {
+        return object_resolve_path_component(*target_obj, prop->target_name);
+    } else {
+        return NULL;
+    }
 }
 
 static void property_release_alias(Object *obj, const char *name, void *opaque)
 {
     AliasProperty *prop = opaque;
 
-    g_free(prop->target_name);
-    g_free(prop);
+    if (!(prop->flags & OBJ_PROP_ALIAS_CLASS)) {
+        g_free(prop->target_name);
+        g_free(prop);
+    }
 }
 
 ObjectProperty *
@@ -3110,6 +3141,7 @@ object_property_add_alias(Object *obj, const char *name,
     prop = g_malloc(sizeof(*prop));
     prop->target_obj = target_obj;
     prop->target_name = g_strdup(target_name);
+    prop->flags = 0;
 
     op = object_property_add(obj, name, prop_type,
                              property_get_alias,
@@ -3126,6 +3158,50 @@ object_property_add_alias(Object *obj, const char *name,
     return op;
 }
 
+ObjectProperty *
+object_class_property_add_alias(ObjectClass *klass, const char *name,
+                                ptrdiff_t offset,
+                                const char *target_type,
+                                const char *target_name)
+{
+    AliasProperty *prop;
+    ObjectProperty *op;
+    ObjectProperty *target_prop;
+    ObjectClass *target_class;
+    g_autofree char *prop_type = NULL;
+
+    target_class = object_class_by_name(target_type);
+    assert(target_class);
+    target_prop = object_class_property_find(target_class, target_name);
+    assert(target_prop);
+
+    if (object_property_is_child(target_prop)) {
+        prop_type = g_strdup_printf("link%s",
+                                    target_prop->type + strlen("child"));
+    } else {
+        prop_type = g_strdup(target_prop->type);
+    }
+
+    prop = g_malloc(sizeof(*prop));
+    prop->offset = offset;
+    prop->target_name = g_strdup(target_name);
+    prop->flags = OBJ_PROP_ALIAS_CLASS;
+
+    op = object_class_property_add(klass, name, prop_type,
+                                   property_get_alias,
+                                   property_set_alias,
+                                   property_release_alias,
+                                   prop);
+    op->resolve = property_resolve_alias;
+    if (target_prop->defval) {
+        op->defval = qobject_ref(target_prop->defval);
+    }
+
+    object_class_property_set_description(klass, op->name,
+                                          target_prop->description);
+    return op;
+}
+
 void object_property_set_description(Object *obj, const char *name,
                                      const char *description)
 {
--

2.43.0

#4 lore raw

Re: [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias()

Quoted 43 lines · Marc-André Lureau

Hi

Quoted 39 lines · Mark Cave-Ayland

This is eventually intended to be a replacement for object_property_add_alias() which uses an object property instead of a class property.

With the advent of class properties, it is possible that QOM may attempt to set or retrieve the value of an unset alias property. Update the existing property_get_alias() and property_set_alias() functions to use the null visitor if the alias target has not been set, and property_resolve_alias() to return NULL for the same case.

This ensures that unset class alias properties accessed e.g. via the monitor do not cause QEMU to crash.

---
  include/qom/object.h |  25 +++++++++++
  qom/object.c         | 100 +++++++++++++++++++++++++++++++++++++------
  2 files changed, 113 insertions(+), 12 deletions(-)
include/qom/object.h +5 -0
index e24f0a2b2d..96c76975ef 100644
@@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
                                            const uint64_t *v,
                                            ObjectPropertyFlags flags);
 
+typedef enum {
+    /* private */
+    OBJ_PROP_ALIAS_CLASS = 0x1,
+} ObjectPropertyAliasFlags;
+
  /**
   * object_property_add_alias:
   * @obj: the object to add a property to
@@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
  ObjectProperty *object_property_add_alias(Object *obj, const char *name,
                                 Object *target_obj, const char *target_name);
 
Quoted 15 lines

include/qom/object.h ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass, · line 2303

Quoted 13 lines
include/qom/object.h +13 -0
+/**
+ * object_class_property_add_alias:
+ * @klass: the object class to add a property to
+ * @name: the name of the property
+ * @offset: the offset from the object instance where the object alias is
+ *   stored
+ * @target_type: QOM type we expect the alias to resolve to
+ * @target_name: the name of the property on the forwarded object
+ *
+ * Add an alias for a property on an object.  This function will add a property
+ * of the same type as the forwarded property.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.

actually, it assert() on error and never returns NULL.

I was able to reproduce this by attempting to add a class alias property with the same name again, and then started to look at other related functions do to understand what the behaviour should be. There seems to be a number of existing issues here:

- object_property_try_add() returns NULL in the case a property cannot be created (which seems to be only when an attempt to make add a property that already exists). However since object_property_add() always passes &error_abort, then QEMU terminates immediately without returning the NULL.

- object_class_property_add() will currently assert() if an attempt is made to add a duplicate property: it is fairly trivial to update it to return the same error that object_property_add() does, however it is interesting to note that the kernel-doc states that error_setg(&error_abort, ...) should NOT be used. However in this case it appears to return a genuinely helpful message which I think is worth keeping.

- There are several places in qom/object.c that do not check the return value of object_property_add() / object_class_property_add() such as object_add_link_prop(), object_property_add_alias() which could potentially dereference a NULL pointer.

It feels like the assumption is actually that these functions will &error_abort rather than returning NULL as indicated by the kernel-doc. Any thoughts on what we should do here? Ideally we want the same behaviour between the object_property*() and object_class_property*() functions to aid the transition.

Quoted 54 lines
Quoted 54 lines
include/qom/object.h +7 -0
+ */
+ObjectProperty *
+object_class_property_add_alias(ObjectClass *klass, const char *name,
+                                ptrdiff_t offset,
+                                const char *target_type,
+                                const char *target_name);
+
  /**
   * object_property_add_const_link:
   * @obj: the object to add a property to
qom/object.c +12 -4
index a904f53ed6..9a05e189ea 100644
@@ -34,6 +34,7 @@
  #include "qom/qom-qobject.h"
  #include "qobject/qbool.h"
  #include "qobject/qlist.h"
+#include "qobject/qnull.h"
  #include "qobject/qnum.h"
  #include "qobject/qstring.h"
  #include "qemu/error-report.h"
@@ -3039,14 +3040,22 @@ object_class_static_property_add_uint64_ptr(ObjectClass *klass,
  }
 
  typedef struct {
-    Object *target_obj;
+    union {
+        Object *target_obj; /* if !OBJ_PROP_ALIAS_CLASS */
+        ptrdiff_t offset;   /* if OBJ_PROP_ALIAS_CLASS */
+    };
      char *target_name;
+    ObjectPropertyAliasFlags flags;
  } AliasProperty;
 
  static Object **
-object_alias_get_targetp(Object *obj, AliasProperty *lprop)
+object_alias_get_targetp(Object *obj, AliasProperty *aprop)
  {
-    return &lprop->target_obj;
+    if (aprop->flags & OBJ_PROP_ALIAS_CLASS) {
+        return (void *)obj + aprop->offset;
+    } else {
+        return &aprop->target_obj;
+    }
  }
 
  static void property_get_alias(Object *obj, Visitor *v, const char *name,
@@ -3054,10 +3063,18 @@ static void property_get_alias(Object *obj, Visitor *v, const char *name,
  {
      AliasProperty *prop = opaque;
      Object **target_obj = object_alias_get_targetp(obj, prop);
-    Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
 
Quoted 15 lines

qom/object.c static void property_get_alias(Object *obj, Visitor *v, const char *name, · line 3077

Quoted 13 lines
qom/object.c +11 -2
-    object_property_get(*target_obj, prop->target_name, alias_v, errp);
-    visit_free(alias_v);
+    if (*target_obj) {
+        Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
+
+        object_property_get(*target_obj, prop->target_name, alias_v, errp);
+        visit_free(alias_v);
+    } else {
+        QNull *null = NULL;
+
+        visit_type_null(v, NULL, &null, errp);
+        qnull_unref(null);
+    };

extra ;

Ooops, thanks.

Quoted 9 lines
Quoted 9 lines
qom/object.c +0 -1
  }
 
  static void property_set_alias(Object *obj, Visitor *v, const char *name,
@@ -3065,10 +3082,18 @@ static void property_set_alias(Object *obj, Visitor *v, const char *name,
  {
      AliasProperty *prop = opaque;
      Object **target_obj = object_alias_get_targetp(obj, prop);
-    Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
 
Quoted 14 lines

qom/object.c static void property_set_alias(Object *obj, Visitor *v, const char *name, · line 3095

Quoted 12 lines
qom/object.c +10 -2
-    object_property_set(*target_obj, prop->target_name, alias_v, errp);
-    visit_free(alias_v);
+    if (*target_obj) {
+        Visitor *alias_v = visitor_forward_field(v, prop->target_name, name);
+
+        object_property_set(*target_obj, prop->target_name, alias_v, errp);
+        visit_free(alias_v);
+    } else {
+        QNull *null = NULL;
+
+        visit_type_null(v, NULL, &null, errp);
+        qnull_unref(null);

Why not return an error?

I think that would make sense in the context of the discussion above.

Quoted 82 lines
Quoted 82 lines
qom/object.c +52 -3
+    }
  }
 
  static Object *property_resolve_alias(Object *obj, void *opaque,
@@ -3077,15 +3102,21 @@ static Object *property_resolve_alias(Object *obj, void *opaque,
      AliasProperty *prop = opaque;
      Object **target_obj = object_alias_get_targetp(obj, prop);
 
-    return object_resolve_path_component(*target_obj, prop->target_name);
+    if (*target_obj) {
+        return object_resolve_path_component(*target_obj, prop->target_name);
+    } else {
+        return NULL;
+    }
  }
 
  static void property_release_alias(Object *obj, const char *name, void *opaque)
  {
      AliasProperty *prop = opaque;
 
-    g_free(prop->target_name);
-    g_free(prop);
+    if (!(prop->flags & OBJ_PROP_ALIAS_CLASS)) {
+        g_free(prop->target_name);
+        g_free(prop);
+    }
  }
 
  ObjectProperty *
@@ -3110,6 +3141,7 @@ object_property_add_alias(Object *obj, const char *name,
      prop = g_malloc(sizeof(*prop));
      prop->target_obj = target_obj;
      prop->target_name = g_strdup(target_name);
+    prop->flags = 0;
 
      op = object_property_add(obj, name, prop_type,
                               property_get_alias,
@@ -3126,6 +3158,50 @@ object_property_add_alias(Object *obj, const char *name,
      return op;
  }
 
+ObjectProperty *
+object_class_property_add_alias(ObjectClass *klass, const char *name,
+                                ptrdiff_t offset,
+                                const char *target_type,
+                                const char *target_name)
+{
+    AliasProperty *prop;
+    ObjectProperty *op;
+    ObjectProperty *target_prop;
+    ObjectClass *target_class;
+    g_autofree char *prop_type = NULL;
+
+    target_class = object_class_by_name(target_type);
+    assert(target_class);
+    target_prop = object_class_property_find(target_class, target_name);
+    assert(target_prop);
+
+    if (object_property_is_child(target_prop)) {
+        prop_type = g_strdup_printf("link%s",
+                                    target_prop->type + strlen("child"));
+    } else {
+        prop_type = g_strdup(target_prop->type);
+    }
+
+    prop = g_malloc(sizeof(*prop));
+    prop->offset = offset;
+    prop->target_name = g_strdup(target_name);
+    prop->flags = OBJ_PROP_ALIAS_CLASS;
+
+    op = object_class_property_add(klass, name, prop_type,
+                                   property_get_alias,
+                                   property_set_alias,
+                                   property_release_alias,
+                                   prop);
+    op->resolve = property_resolve_alias;
+    if (target_prop->defval) {
+        op->defval = qobject_ref(target_prop->defval);
+    }
+
+    object_class_property_set_description(klass, op->name,
+                                          target_prop->description);
Quoted 8 lines
Quoted 8 lines
qom/object.c +3 -1
+    return op;
+}
+
  void object_property_set_description(Object *obj, const char *name,
                                       const char *description)
  {
--

2.43.0

ATB,

Mark.

#5 lore raw

Re: [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias()

Quoted 59 lines · Mark Cave-Ayland
Quoted 42 lines · Marc-André Lureau

Hi

Quoted 39 lines · Mark Cave-Ayland

This is eventually intended to be a replacement for object_property_add_alias() which uses an object property instead of a class property.

With the advent of class properties, it is possible that QOM may attempt to set or retrieve the value of an unset alias property. Update the existing property_get_alias() and property_set_alias() functions to use the null visitor if the alias target has not been set, and property_resolve_alias() to return NULL for the same case.

This ensures that unset class alias properties accessed e.g. via the monitor do not cause QEMU to crash.

---
  include/qom/object.h |  25 +++++++++++
  qom/object.c         | 100 +++++++++++++++++++++++++++++++++++++------
  2 files changed, 113 insertions(+), 12 deletions(-)
include/qom/object.h +5 -0
index e24f0a2b2d..96c76975ef 100644
@@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
                                            const uint64_t *v,
                                            ObjectPropertyFlags flags);
 
+typedef enum {
+    /* private */
+    OBJ_PROP_ALIAS_CLASS = 0x1,
+} ObjectPropertyAliasFlags;
+
  /**
   * object_property_add_alias:
   * @obj: the object to add a property to
@@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
  ObjectProperty *object_property_add_alias(Object *obj, const char *name,
                                 Object *target_obj, const char *target_name);
 
Quoted 14 lines

include/qom/object.h ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass, · line 2303

Quoted 13 lines
include/qom/object.h +13 -0
+/**
+ * object_class_property_add_alias:
+ * @klass: the object class to add a property to
+ * @name: the name of the property
+ * @offset: the offset from the object instance where the object alias is
+ *   stored
+ * @target_type: QOM type we expect the alias to resolve to
+ * @target_name: the name of the property on the forwarded object
+ *
+ * Add an alias for a property on an object.  This function will add a property
+ * of the same type as the forwarded property.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.

actually, it assert() on error and never returns NULL.

Quoted 7 lines

I was able to reproduce this by attempting to add a class alias property with the same name again, and then started to look at other related functions do to understand what the behaviour should be. There seems to be a number of existing issues here:

- object_property_try_add() returns NULL in the case a property cannot be created (which seems to be only when an attempt to make add a property that already exists). However since object_property_add() always passes &error_abort, then QEMU terminates immediately without returning the NULL.

Convention: when we have a pair of functions FOO_try_BAR() and FOO_BAR(), the former can fail and the latter cannot. The latter is useful when failure would be a programming error.

When FOO_try_BAR() sets an Error on failure, FOO_BAR() is a thin wrapper that passes &error_abort.

We pass &error_abort when failure would be a programming error. It's more concise than "call then assert it didn't fail". Concise is good.

The wrapper makes calls that cannot fail even more concise. Worth having only when there are plenty of callers that profit from that. Someone decided this is the case for object_property_try_add() / object_property_add().

Quoted 7 lines

- object_class_property_add() will currently assert() if an attempt is made to add a duplicate property: it is fairly trivial to update it to return the same error that object_property_add() does, however it is interesting to note that the kernel-doc states that error_setg(&error_abort, ...) should NOT be used. However in this case it appears to return a genuinely helpful message which I think is worth keeping.

The only difference between object_class_property_add() and object_property_add() should be where the property is recorded (class vs. object). In particular, they should treat failure the same way.

This may make object_class_property_try_add() necessary.

Quoted 4 lines

- There are several places in qom/object.c that do not check the return value of object_property_add() / object_class_property_add() such as object_add_link_prop(), object_property_add_alias() which could potentially dereference a NULL pointer.

object_property_add() is specified not to fail, i.e. not to return null. It's a programming error if it does. Letting the program crash on programming errors by dereferencing a null pointer is just fine. We can dress up the crash with assert(obj), but I wouldn't bother.

Use object_property_add() when failure is a programming error. Use object_property_try_add() and handle the error when it's not.

Quoted 1 line

It feels like the assumption is actually that these functions will &error_abort rather than returning NULL as indicated by the kernel-doc. Any thoughts on what we should do here? Ideally we want the same behaviour between the object_property*() and object_class_property*() functions to aid the transition.

Hope this helps!

[...]

#6 lore raw

Re: [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias()

Quoted 92 lines · Markus Armbruster
Quoted 59 lines · Mark Cave-Ayland
Quoted 42 lines · Marc-André Lureau

Hi

Quoted 39 lines · Mark Cave-Ayland

This is eventually intended to be a replacement for object_property_add_alias() which uses an object property instead of a class property.

With the advent of class properties, it is possible that QOM may attempt to set or retrieve the value of an unset alias property. Update the existing property_get_alias() and property_set_alias() functions to use the null visitor if the alias target has not been set, and property_resolve_alias() to return NULL for the same case.

This ensures that unset class alias properties accessed e.g. via the monitor do not cause QEMU to crash.

---
  include/qom/object.h |  25 +++++++++++
  qom/object.c         | 100 +++++++++++++++++++++++++++++++++++++------
  2 files changed, 113 insertions(+), 12 deletions(-)
include/qom/object.h +5 -0
index e24f0a2b2d..96c76975ef 100644
@@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
                                            const uint64_t *v,
                                            ObjectPropertyFlags flags);
 
+typedef enum {
+    /* private */
+    OBJ_PROP_ALIAS_CLASS = 0x1,
+} ObjectPropertyAliasFlags;
+
  /**
   * object_property_add_alias:
   * @obj: the object to add a property to
@@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
  ObjectProperty *object_property_add_alias(Object *obj, const char *name,
                                 Object *target_obj, const char *target_name);
 
Quoted 14 lines

include/qom/object.h ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass, · line 2303

Quoted 13 lines
include/qom/object.h +13 -0
+/**
+ * object_class_property_add_alias:
+ * @klass: the object class to add a property to
+ * @name: the name of the property
+ * @offset: the offset from the object instance where the object alias is
+ *   stored
+ * @target_type: QOM type we expect the alias to resolve to
+ * @target_name: the name of the property on the forwarded object
+ *
+ * Add an alias for a property on an object.  This function will add a property
+ * of the same type as the forwarded property.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.

actually, it assert() on error and never returns NULL.

Quoted 7 lines

I was able to reproduce this by attempting to add a class alias property with the same name again, and then started to look at other related functions do to understand what the behaviour should be. There seems to be a number of existing issues here:

- object_property_try_add() returns NULL in the case a property cannot be created (which seems to be only when an attempt to make add a property that already exists). However since object_property_add() always passes &error_abort, then QEMU terminates immediately without returning the NULL.

Convention: when we have a pair of functions FOO_try_BAR() and FOO_BAR(), the former can fail and the latter cannot. The latter is useful when failure would be a programming error.

When FOO_try_BAR() sets an Error on failure, FOO_BAR() is a thin wrapper that passes &error_abort.

We pass &error_abort when failure would be a programming error. It's more concise than "call then assert it didn't fail". Concise is good.

The wrapper makes calls that cannot fail even more concise. Worth having only when there are plenty of callers that profit from that. Someone decided this is the case for object_property_try_add() / object_property_add().

Quoted 7 lines

- object_class_property_add() will currently assert() if an attempt is made to add a duplicate property: it is fairly trivial to update it to return the same error that object_property_add() does, however it is interesting to note that the kernel-doc states that error_setg(&error_abort, ...) should NOT be used. However in this case it appears to return a genuinely helpful message which I think is worth keeping.

Quoted 5 lines

The only difference between object_class_property_add() and object_property_add() should be where the property is recorded (class vs. object). In particular, they should treat failure the same way.

This may make object_class_property_try_add() necessary.

IMHO such a method should not exist. A class must have a well-defined set of properties that is invariant. Any scenario where a object_class_property_try_add() method could fail would be 100% repeatable and at the same time a significant programmer error.

When we had properties against objects 'try_add' was passable, as we're dynamically adding props and different instances can have different props, even when the same time. This is all a terrible idea, and ideally object_property_try_add would not exist either but it is probably more trouble than its worth right now to attempt removing object_property_try_add. Just don't mirror it into class properties.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#7 lore raw

Re: [PATCH v3 2/8] qom/object.c: introduce object_class_property_add_alias()

Quoted 105 lines · Daniel P. Berrangé
Quoted 92 lines · Markus Armbruster
Quoted 59 lines · Mark Cave-Ayland
Quoted 42 lines · Marc-André Lureau

Hi

Quoted 39 lines · Mark Cave-Ayland

This is eventually intended to be a replacement for object_property_add_alias() which uses an object property instead of a class property.

With the advent of class properties, it is possible that QOM may attempt to set or retrieve the value of an unset alias property. Update the existing property_get_alias() and property_set_alias() functions to use the null visitor if the alias target has not been set, and property_resolve_alias() to return NULL for the same case.

This ensures that unset class alias properties accessed e.g. via the monitor do not cause QEMU to crash.

---
  include/qom/object.h |  25 +++++++++++
  qom/object.c         | 100 +++++++++++++++++++++++++++++++++++++------
  2 files changed, 113 insertions(+), 12 deletions(-)
include/qom/object.h +5 -0
index e24f0a2b2d..96c76975ef 100644
@@ -2263,6 +2263,11 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
                                            const uint64_t *v,
                                            ObjectPropertyFlags flags);
 
+typedef enum {
+    /* private */
+    OBJ_PROP_ALIAS_CLASS = 0x1,
+} ObjectPropertyAliasFlags;
+
  /**
   * object_property_add_alias:
   * @obj: the object to add a property to
@@ -2283,6 +2288,26 @@ ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass,
  ObjectProperty *object_property_add_alias(Object *obj, const char *name,
                                 Object *target_obj, const char *target_name);
 
Quoted 14 lines

include/qom/object.h ObjectProperty *object_class_static_property_add_uint64_ptr(ObjectClass *klass, · line 2303

Quoted 13 lines
include/qom/object.h +13 -0
+/**
+ * object_class_property_add_alias:
+ * @klass: the object class to add a property to
+ * @name: the name of the property
+ * @offset: the offset from the object instance where the object alias is
+ *   stored
+ * @target_type: QOM type we expect the alias to resolve to
+ * @target_name: the name of the property on the forwarded object
+ *
+ * Add an alias for a property on an object.  This function will add a property
+ * of the same type as the forwarded property.
+ *
+ * Returns: The newly added property on success, or %NULL on failure.

actually, it assert() on error and never returns NULL.

Quoted 7 lines

I was able to reproduce this by attempting to add a class alias property with the same name again, and then started to look at other related functions do to understand what the behaviour should be. There seems to be a number of existing issues here:

- object_property_try_add() returns NULL in the case a property cannot be created (which seems to be only when an attempt to make add a property that already exists). However since object_property_add() always passes &error_abort, then QEMU terminates immediately without returning the NULL.

Convention: when we have a pair of functions FOO_try_BAR() and FOO_BAR(), the former can fail and the latter cannot. The latter is useful when failure would be a programming error.

When FOO_try_BAR() sets an Error on failure, FOO_BAR() is a thin wrapper that passes &error_abort.

We pass &error_abort when failure would be a programming error. It's more concise than "call then assert it didn't fail". Concise is good.

The wrapper makes calls that cannot fail even more concise. Worth having only when there are plenty of callers that profit from that. Someone decided this is the case for object_property_try_add() / object_property_add().

Quoted 7 lines

- object_class_property_add() will currently assert() if an attempt is made to add a duplicate property: it is fairly trivial to update it to return the same error that object_property_add() does, however it is interesting to note that the kernel-doc states that error_setg(&error_abort, ...) should NOT be used. However in this case it appears to return a genuinely helpful message which I think is worth keeping.

Quoted 5 lines

The only difference between object_class_property_add() and object_property_add() should be where the property is recorded (class vs. object). In particular, they should treat failure the same way.

This may make object_class_property_try_add() necessary.

IMHO such a method should not exist. A class must have a well-defined set of properties that is invariant. Any scenario where a object_class_property_try_add() method could fail would be 100% repeatable and at the same time a significant programmer error.

Quoted 7 lines

When we had properties against objects 'try_add' was passable, as we're dynamically adding props and different instances can have different props, even when the same time. This is all a terrible idea, and ideally object_property_try_add would not exist either but it is probably more trouble than its worth right now to attempt removing object_property_try_add. Just don't mirror it into class properties.

Good points. Work into object.h comments?

#8 lore raw

PATCH v3 3/8 qom/object.c: introduce object_property_set_alias() function

In reply to Mark Cave-Ayland

This will be used to set the class alias property for a specific object. Note that this function is only required for class properties, and will assert at runtime if an attempt is made to use it on an object alias property.

Update the existing property_release_alias() function to reflect the documented refcount behaviour.

---
 include/qom/object.h | 17 +++++++++++++++++
 qom/object.c         | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)
include/qom/object.h +17 -0
index 96c76975ef..bb65218aa3 100644
@@ -2308,6 +2308,23 @@ object_class_property_add_alias(ObjectClass *klass, const char *name,
                                 const char *target_type,
                                 const char *target_name);
 
+/**
+ * object_property_set_alias:
+ * @obj: the object upon which to set the alias property
+ * @name: the name of the alias property
+ * @target_obj: the object to forward property access to
+ *
+ * Set an alias property on an object to point to @target_obj.  This is only
+ * required for class properties, and will assert at runtime if used on an
+ * object property.
+ *
+ * This function ensures that @target_obj stays alive as long as @obj exists
+ * by taking a reference if @target_obj is not a child object or an alias on
+ * the same object.
+ */
+void object_property_set_alias(Object *obj, const char *name,
+                               Object *target_obj);
+
 /**
  * object_property_add_const_link:
  * @obj: the object to add a property to
qom/object.c +41 -0

53 lines not on this page · raw message

Signature · 1 line
2.43.0
#9 lore raw

PATCH v3 4/8 hw/i386/pc.c: convert pcspk-audiodev object prop to a class prop

In reply to Mark Cave-Ayland
---
 include/hw/i386/pc.h | 2 ++
 hw/i386/pc.c         | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)
include/hw/i386/pc.h +2 -0
index ac03da97b6..bd800e7ff0 100644
@@ -38,6 +38,8 @@ typedef struct PCMachineState {
     DeviceState *iommu;
     BusState *idebus[MAX_IDE_BUS];
 
+    Object *alias_pcspk;
+
     /* Configuration options: */
     uint64_t max_ram_below_4g;
     OnOffAuto vmport;
hw/i386/pc.c +6 -3
index e9e4fc262b..5293c59d66 100644
@@ -1643,8 +1643,8 @@ static void pc_machine_initfn(Object *obj)
 
     pc_system_flash_create(pcms);
     pcms->pcspk = isa_new(TYPE_PC_SPEAKER);
-    object_property_add_alias(OBJECT(pcms), "pcspk-audiodev",
-                              OBJECT(pcms->pcspk), "audiodev");
+    object_property_set_alias(OBJECT(pcms), "pcspk-audiodev",
+                              OBJECT(pcms->pcspk));
     if (pcmc->pci_enabled) {
         cxl_machine_init(obj, &pcms->cxl_devices_state);
     }
@@ -1788,7 +1788,10 @@ static void pc_machine_class_init(ObjectClass *oc, const void *data)
                                           "Set IGVM configuration");
 #endif
 
-
+    object_class_property_add_alias(oc, "pcspk-audiodev",
+                                    offsetof(PCMachineState, alias_pcspk),
+                                    TYPE_PC_SPEAKER,
+                                    "audiodev");
 }
 
 static const TypeInfo pc_machine_info = {
Signature · 1 line
2.43.0
#11 lore raw

PATCH v3 5/8 hw/i386/pc.c: convert rtc-time object prop to a class prop

In reply to Mark Cave-Ayland
---
 include/hw/i386/pc.h | 1 +
 hw/i386/pc.c         | 7 +++++--
 2 files changed, 6 insertions(+), 2 deletions(-)
include/hw/i386/pc.h +1 -0
index bd800e7ff0..0b925ccd8f 100644
@@ -39,6 +39,7 @@ typedef struct PCMachineState {
     BusState *idebus[MAX_IDE_BUS];
 
     Object *alias_pcspk;
+    Object *alias_rtc_time;
 
     /* Configuration options: */
     uint64_t max_ram_below_4g;
hw/i386/pc.c +5 -2
index 5293c59d66..f8969ddebc 100644
@@ -1097,8 +1097,7 @@ void pc_basic_device_init(struct PCMachineState *pcms,
         qdev_connect_gpio_out(DEVICE(rtc_state), 0, rtc_irq);
     }
 
-    object_property_add_alias(OBJECT(pcms), "rtc-time", OBJECT(rtc_state),
-                              "date");
+    object_property_set_alias(OBJECT(pcms), "rtc-time", OBJECT(rtc_state));
 
 #ifdef CONFIG_XEN_EMU
     if (xen_mode == XEN_EMULATE) {
@@ -1792,6 +1791,10 @@ static void pc_machine_class_init(ObjectClass *oc, const void *data)
                                     offsetof(PCMachineState, alias_pcspk),
                                     TYPE_PC_SPEAKER,
                                     "audiodev");
+    object_class_property_add_alias(oc, "rtc-time",
+                                    offsetof(PCMachineState, alias_rtc_time),
+                                    TYPE_MC146818_RTC,
+                                    "date");
 }
 
 static const TypeInfo pc_machine_info = {
Signature · 1 line
2.43.0
#12 lore raw

PATCH v3 6/8 hw/i386/pc.c: convert PC_MACHINE_ACPI_DEVICE_PROP from object prop to class prop

In reply to Mark Cave-Ayland
---
 hw/i386/pc.c      | 5 +++++
 hw/i386/pc_piix.c | 5 -----
 hw/i386/pc_q35.c  | 5 -----
 3 files changed, 5 insertions(+), 10 deletions(-)
hw/i386/pc.c +5 -0
index f8969ddebc..876ebaadb8 100644
@@ -1795,6 +1795,11 @@ static void pc_machine_class_init(ObjectClass *oc, const void *data)
                                     offsetof(PCMachineState, alias_rtc_time),
                                     TYPE_MC146818_RTC,
                                     "date");
+    object_class_property_add_link(oc, PC_MACHINE_ACPI_DEVICE_PROP,
+                                   TYPE_HOTPLUG_HANDLER,
+                                   offsetof(X86MachineState, acpi_dev),
+                                   object_property_allow_set_link,
+                                   OBJ_PROP_LINK_STRONG);
 }
 
 static const TypeInfo pc_machine_info = {
hw/i386/pc_piix.c +0 -5
index a929cc4dec..63c4667ea3 100644
@@ -306,11 +306,6 @@ static void pc_init1(MachineState *machine, const char *pci_type)
         /* TODO: Populate SPD eeprom data.  */
         smbus_eeprom_init(pcms->smbus, 8, NULL, 0);
 
-        object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
-                                 TYPE_HOTPLUG_HANDLER,
-                                 (Object **)&x86ms->acpi_dev,
-                                 object_property_allow_set_link,
-                                 OBJ_PROP_LINK_STRONG);
         object_property_set_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
                                  piix4_pm, &error_abort);
     }
hw/i386/pc_q35.c +0 -5
index 94cd71124b..c3ce9c5649 100644
@@ -247,11 +247,6 @@ static void pc_q35_init(MachineState *machine)
 
     x86ms->rtc = ISA_DEVICE(object_resolve_path_component(OBJECT(lpc), "rtc"));
 
-    object_property_add_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
-                             TYPE_HOTPLUG_HANDLER,
-                             (Object **)&x86ms->acpi_dev,
-                             object_property_allow_set_link,
-                             OBJ_PROP_LINK_STRONG);
     object_property_set_link(OBJECT(machine), PC_MACHINE_ACPI_DEVICE_PROP,
                              OBJECT(lpc), &error_abort);
 
Signature · 1 line
2.43.0
#13 lore raw

PATCH v3 7/8 hw/i386/pc_sysfw.c: convert pflash0 and pflash1 object props to class props

In reply to Mark Cave-Ayland

Now that the pflash0 and pflash1 machine properties are class properties, if they are unspecified then QOM returns an empty string as opposed to returning a property not found error.

Before this patch:

$ ./build/qemu-system-x86_64 -M q35 -monitor stdio
QEMU 11.1.50 monitor - type 'help' for more information
(qemu) qom-get /machine pflash0
Error: Property 'pc-q35-11.1-machine.pflash0' not found

After this patch:

$ ./build/qemu-system-x86_64 -M q35 -monitor stdio
QEMU 11.1.50 monitor - type 'help' for more information
(qemu) qom-get /machine pflash0
""
---
 include/hw/i386/pc.h | 2 ++
 hw/i386/pc.c         | 8 ++++++++
 hw/i386/pc_sysfw.c   | 7 +------
 3 files changed, 11 insertions(+), 6 deletions(-)
include/hw/i386/pc.h +2 -0
index 0b925ccd8f..8369263691 100644
@@ -40,6 +40,8 @@ typedef struct PCMachineState {
 
     Object *alias_pcspk;
     Object *alias_rtc_time;
+    Object *alias_pflash0;
+    Object *alias_pflash1;
 
     /* Configuration options: */
     uint64_t max_ram_below_4g;
hw/i386/pc.c +8 -0
index 876ebaadb8..ddb75a2ec0 100644
@@ -1800,6 +1800,14 @@ static void pc_machine_class_init(ObjectClass *oc, const void *data)
                                    offsetof(X86MachineState, acpi_dev),
                                    object_property_allow_set_link,
                                    OBJ_PROP_LINK_STRONG);
+    object_class_property_add_alias(oc, "pflash0",
+                                    offsetof(PCMachineState, alias_pflash0),
+                                    TYPE_PFLASH_CFI01,
+                                    "drive");
+    object_class_property_add_alias(oc, "pflash1",
+                                    offsetof(PCMachineState, alias_pflash1),
+                                    TYPE_PFLASH_CFI01,
+                                    "drive");
 }
 
 static const TypeInfo pc_machine_info = {
hw/i386/pc_sysfw.c +1 -6
index 1a41a5972b..441e777191 100644
@@ -85,8 +85,7 @@ static PFlashCFI01 *pc_pflash_create(PCMachineState *pcms,
     qdev_prop_set_uint8(dev, "width", 1);
     qdev_prop_set_string(dev, "name", name);
     object_property_add_child(OBJECT(pcms), name, OBJECT(dev));
-    object_property_add_alias(OBJECT(pcms), alias_prop_name,
-                              OBJECT(dev), "drive");
+    object_property_set_alias(OBJECT(pcms), alias_prop_name, OBJECT(dev));
     /*
      * The returned reference is tied to the child property and
      * will be removed with object_unparent.
@@ -109,16 +108,12 @@ void pc_system_flash_create(PCMachineState *pcms)
 
 void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
-    char *prop_name;
     int i;
 
     assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled);
 
     for (i = 0; i < ARRAY_SIZE(pcms->flash); i++) {
         if (!qdev_is_realized(DEVICE(pcms->flash[i]))) {
-            prop_name = g_strdup_printf("pflash%d", i);
-            object_property_del(OBJECT(pcms), prop_name);
-            g_free(prop_name);
             object_unparent(OBJECT(pcms->flash[i]));
             pcms->flash[i] = NULL;
         }
Signature · 1 line
2.43.0
#14 lore raw

PATCH v3 8/8 hw/i386/sgx-epc.c: convert SGX_EPC_SIZE_PROP object prop to class prop

In reply to Mark Cave-Ayland

Remove sgx_epc_init() since it is no longer required.

---
 hw/i386/sgx-epc.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
hw/i386/sgx-epc.c +5 -7
index d3fe10028c..29cda843c9 100644
@@ -41,12 +41,6 @@ static void sgx_epc_get_size(Object *obj, Visitor *v, const char *name,
     visit_type_uint64(v, name, &value, errp);
 }
 
-static void sgx_epc_init(Object *obj)
-{
-    object_property_add(obj, SGX_EPC_SIZE_PROP, "uint64", sgx_epc_get_size,
-                        NULL, NULL, NULL);
-}
-
 static void sgx_epc_realize(DeviceState *dev, Error **errp)
 {
     PCMachineState *pcms = PC_MACHINE(qdev_get_machine());
@@ -164,13 +158,17 @@ static void sgx_epc_class_init(ObjectClass *oc, const void *data)
     mdc->get_plugged_size = sgx_epc_md_get_plugged_size;
     mdc->get_memory_region = sgx_epc_md_get_memory_region;
     mdc->fill_device_info = sgx_epc_md_fill_device_info;
+
+    object_class_property_add(oc, SGX_EPC_SIZE_PROP, "uint64",
+                              sgx_epc_get_size,
+                              NULL,
+                              NULL, NULL);
 }
 
 static const TypeInfo sgx_epc_info = {
     .name          = TYPE_SGX_EPC,
     .parent        = TYPE_DEVICE,
     .instance_size = sizeof(SGXEPCDevice),
-    .instance_init = sgx_epc_init,
     .class_init    = sgx_epc_class_init,
     .class_size    = sizeof(DeviceClass),
     .interfaces = (const InterfaceInfo[]) {
Signature · 1 line
2.43.0