diff mbox series

[5/7] qom: Replace void* parameter with Property* on PropertyInfo.release

Message ID 20201104172512.2381656-6-ehabkost@redhat.com
State New
Headers show
Series qom: Field properties type safety | expand

Commit Message

Eduardo Habkost Nov. 4, 2020, 5:25 p.m. UTC
The release function must interpret the third argument as
Property*.  Change the signature of PropertyInfo.release to
indicate that.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Cc: Stefan Berger <stefanb@linux.vnet.ibm.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Cc: qemu-devel@nongnu.org
---
 include/qom/field-property.h     | 11 ++++++++++-
 backends/tpm/tpm_util.c          |  3 +--
 hw/core/qdev-properties-system.c |  6 ++----
 qom/field-property.c             | 13 +++++++++++--
 qom/property-types.c             |  3 +--
 5 files changed, 25 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/include/qom/field-property.h b/include/qom/field-property.h
index 438bb25896..1d3bf9699b 100644
--- a/include/qom/field-property.h
+++ b/include/qom/field-property.h
@@ -66,6 +66,15 @@  typedef void FieldAccessor(Object *obj, Visitor *v,
                            const char *name, Property *prop,
                            Error **errp);
 
+/**
+ * typedef FieldRelease:
+ * @obj: the object instance
+ * @name: the name of the property
+ * @prop: Field property definition
+ */
+typedef void FieldRelease(Object *obj, const char *name, Property *prop);
+
+
 /**
  * struct PropertyInfo: information on a specific QOM property type
  */
@@ -91,7 +100,7 @@  struct PropertyInfo {
      * @release: Optional release function, called when the object
      * is destroyed
      */
-    ObjectPropertyRelease *release;
+    FieldRelease *release;
 };
 
 /**
diff --git a/backends/tpm/tpm_util.c b/backends/tpm/tpm_util.c
index e8837938e5..556e21388c 100644
--- a/backends/tpm/tpm_util.c
+++ b/backends/tpm/tpm_util.c
@@ -63,9 +63,8 @@  static void set_tpm(Object *obj, Visitor *v, const char *name,
     g_free(str);
 }
 
-static void release_tpm(Object *obj, const char *name, void *opaque)
+static void release_tpm(Object *obj, const char *name, Property *prop)
 {
-    Property *prop = opaque;
     TPMBackend **be = object_field_prop_ptr(obj, prop);
 
     if (*be) {
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 4c649cb4b2..2fdd5863bb 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -176,10 +176,9 @@  static void set_drive_iothread(Object *obj, Visitor *v, const char *name,
     set_drive_helper(obj, v, name, prop, true, errp);
 }
 
-static void release_drive(Object *obj, const char *name, void *opaque)
+static void release_drive(Object *obj, const char *name, Property *prop)
 {
     DeviceState *dev = DEVICE(obj);
-    Property *prop = opaque;
     BlockBackend **ptr = object_field_prop_ptr(obj, prop);
 
     if (*ptr) {
@@ -257,9 +256,8 @@  static void set_chr(Object *obj, Visitor *v, const char *name,
     g_free(str);
 }
 
-static void release_chr(Object *obj, const char *name, void *opaque)
+static void release_chr(Object *obj, const char *name, Property *prop)
 {
-    Property *prop = opaque;
     CharBackend *be = object_field_prop_ptr(obj, prop);
 
     qemu_chr_fe_deinit(be, false);
diff --git a/qom/field-property.c b/qom/field-property.c
index 25a818bb69..865d4929a3 100644
--- a/qom/field-property.c
+++ b/qom/field-property.c
@@ -47,6 +47,15 @@  static ObjectPropertyAccessor *field_prop_setter(const PropertyInfo *info)
     return info->set ? field_prop_set : NULL;
 }
 
+static void field_prop_release(Object *obj, const char *name, void *opaque)
+{
+    Property *prop = opaque;
+    if (prop->info->release) {
+        prop->info->release(obj, name, prop);
+    }
+}
+
+
 ObjectProperty *
 object_property_add_field(Object *obj, const char *name, Property *prop,
                           ObjectPropertyAllowSet allow_set)
@@ -59,7 +68,7 @@  object_property_add_field(Object *obj, const char *name, Property *prop,
     op = object_property_add(obj, name, prop->info->name,
                              field_prop_getter(prop->info),
                              field_prop_setter(prop->info),
-                             prop->info->release,
+                             field_prop_release,
                              prop);
 
     object_property_set_description(obj, name,
@@ -92,7 +101,7 @@  object_class_property_add_field(ObjectClass *oc, const char *name,
                                        name, prop->info->name,
                                        field_prop_getter(prop->info),
                                        field_prop_setter(prop->info),
-                                       prop->info->release,
+                                       field_prop_release,
                                        prop);
     }
     if (prop->set_default) {
diff --git a/qom/property-types.c b/qom/property-types.c
index 82a5932f4a..0182a73e38 100644
--- a/qom/property-types.c
+++ b/qom/property-types.c
@@ -321,9 +321,8 @@  const PropertyInfo prop_info_int64 = {
 
 /* --- string --- */
 
-static void release_string(Object *obj, const char *name, void *opaque)
+static void release_string(Object *obj, const char *name, Property *prop)
 {
-    Property *prop = opaque;
     g_free(*(char **)object_field_prop_ptr(obj, prop));
 }