diff mbox

[v5,1/3] Check if GlobalProperty exists before registering

Message ID 1340733111-9166-1-git-send-email-vianac@linux.vnet.ibm.com
State New
Headers show

Commit Message

Crístian Viana June 26, 2012, 5:51 p.m. UTC
If a GlobalProperty has already been registered, it won't have its
value overwritten.

Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com>
---

Changes since v4: 
- Only register a GlobalProperty if it hasn't already been registered. That
  avoids the property values to be overwritten (fix previous known bug).

 hw/qdev-properties.c |    8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Anthony Liguori July 11, 2012, 5:52 p.m. UTC | #1
Crístian Viana <vianac@linux.vnet.ibm.com> writes:

> If a GlobalProperty has already been registered, it won't have its
> value overwritten.
>
> Signed-off-by: Crístian Viana <vianac@linux.vnet.ibm.com>
> ---
>
> Changes since v4: 
> - Only register a GlobalProperty if it hasn't already been registered. That
>   avoids the property values to be overwritten (fix previous known bug).
>
>  hw/qdev-properties.c |    8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 099a7aa..fda94dd 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -1105,6 +1105,14 @@ static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(glob
>
>  static void qdev_prop_register_global(GlobalProperty *prop)
>  {
> +    GlobalProperty *p;
> +
> +    QTAILQ_FOREACH(p, &global_props, next) {
> +        if (strcmp(prop->driver, p->driver) == 0) {
> +            return;
> +        }
> +    }
> +
>      QTAILQ_INSERT_TAIL(&global_props, prop, next);
>  }

This is relying on a very subtle characteristic: that -global properties
are registered before machine options.  We probably need to be more
explicit about who we want to win.  In the very least, you should add a
comment here that says this check is specifically to allow -global to
"win" over machine options.

Regards,

Anthony Liguori

>  
> -- 
> 1.7.9.5
diff mbox

Patch

diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 099a7aa..fda94dd 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -1105,6 +1105,14 @@  static QTAILQ_HEAD(, GlobalProperty) global_props = QTAILQ_HEAD_INITIALIZER(glob
 
 static void qdev_prop_register_global(GlobalProperty *prop)
 {
+    GlobalProperty *p;
+
+    QTAILQ_FOREACH(p, &global_props, next) {
+        if (strcmp(prop->driver, p->driver) == 0) {
+            return;
+        }
+    }
+
     QTAILQ_INSERT_TAIL(&global_props, prop, next);
 }