diff mbox series

[16/36] qdev: Make qdev_class_add_property() more flexible

Message ID 20201029220246.472693-17-ehabkost@redhat.com
State New
Headers show
Series Make qdev static property API usable by any QOM type | expand

Commit Message

Eduardo Habkost Oct. 29, 2020, 10:02 p.m. UTC
Support Property.set_default and PropertyInfo.description even if
PropertyInfo.create is set.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.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
---
 hw/core/qdev-properties.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Comments

Marc-André Lureau Oct. 30, 2020, 9:45 a.m. UTC | #1
On Fri, Oct 30, 2020 at 2:13 AM Eduardo Habkost <ehabkost@redhat.com> wrote:

> Support Property.set_default and PropertyInfo.description even if
> PropertyInfo.create is set.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.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
> ---
>  hw/core/qdev-properties.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
>
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 89e292dc25..ad685f371d 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -912,24 +912,25 @@ void qdev_property_add_static(DeviceState *dev,
> Property *prop)
>  static void qdev_class_add_property(DeviceClass *klass, Property *prop)
>  {
>      ObjectClass *oc = OBJECT_CLASS(klass);
> +    ObjectProperty *op;
>
>      if (prop->info->create) {
> -        prop->info->create(oc, prop);
> +        op = prop->info->create(oc, prop);
>      } else {
> -        ObjectProperty *op;
> -
>          op = object_class_property_add(oc,
>                                         prop->name, prop->info->name,
>                                         static_prop_getter(prop->info),
>                                         static_prop_setter(prop->info),
>                                         prop->info->release,
>                                         prop);
> -        if (prop->set_default) {
> -            prop->info->set_default_value(op, prop);
> -        }
>      }
> -    object_class_property_set_description(oc, prop->name,
> -                                          prop->info->description);
> +    if (prop->set_default) {
> +        prop->info->set_default_value(op, prop);
> +    }
> +    if (prop->info->description) {
> +        object_class_property_set_description(oc, prop->name,
> +                                            prop->info->description);
>

indentation is off, other than that:
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

+    }
>  }
>
>  /**
> --
> 2.28.0
>
>
>
diff mbox series

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 89e292dc25..ad685f371d 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -912,24 +912,25 @@  void qdev_property_add_static(DeviceState *dev, Property *prop)
 static void qdev_class_add_property(DeviceClass *klass, Property *prop)
 {
     ObjectClass *oc = OBJECT_CLASS(klass);
+    ObjectProperty *op;
 
     if (prop->info->create) {
-        prop->info->create(oc, prop);
+        op = prop->info->create(oc, prop);
     } else {
-        ObjectProperty *op;
-
         op = object_class_property_add(oc,
                                        prop->name, prop->info->name,
                                        static_prop_getter(prop->info),
                                        static_prop_setter(prop->info),
                                        prop->info->release,
                                        prop);
-        if (prop->set_default) {
-            prop->info->set_default_value(op, prop);
-        }
     }
-    object_class_property_set_description(oc, prop->name,
-                                          prop->info->description);
+    if (prop->set_default) {
+        prop->info->set_default_value(op, prop);
+    }
+    if (prop->info->description) {
+        object_class_property_set_description(oc, prop->name,
+                                            prop->info->description);
+    }
 }
 
 /**