[2/2] qom: fix device hot-unplug

Submitted by Paolo Bonzini on Feb. 28, 2012, 8:54 a.m.

Details

Message ID 1330419255-5566-3-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini Feb. 28, 2012, 8:54 a.m.
Property removal modifies the list, so it is not safe to continue
iteration.  We know anyway that each object can have only one
parent (see object_property_add_child), so exit after finding
the requested object.

Reported-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 qom/object.c |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)

Comments

Andreas Färber March 10, 2012, 1:12 p.m.
Am 28.02.2012 09:54, schrieb Paolo Bonzini:
> Property removal modifies the list, so it is not safe to continue
> iteration.  We know anyway that each object can have only one
> parent (see object_property_add_child), so exit after finding
> the requested object.
> 
> Reported-by: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  qom/object.c |    7 ++-----
>  1 files changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index aa037d2..39cbcb9 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -304,12 +304,9 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
>      ObjectProperty *prop;
>  
>      QTAILQ_FOREACH(prop, &obj->properties, node) {
> -        if (!strstart(prop->type, "child<", NULL)) {
> -            continue;
> -        }
> -
> -        if (prop->opaque == child) {
> +        if (strstart(prop->type, "child<", NULL) && prop->opaque == child) {

Didn't someone post a patch introducing an object_property_is_child() or
so? Would be handy here.

Otherwise looks okay.

Andreas

>              object_property_del(obj, prop->name, errp);
> +            break;
>          }
>      }
>  }

Patch hide | download patch | download mbox

diff --git a/qom/object.c b/qom/object.c
index aa037d2..39cbcb9 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -304,12 +304,9 @@  static void object_property_del_child(Object *obj, Object *child, Error **errp)
     ObjectProperty *prop;
 
     QTAILQ_FOREACH(prop, &obj->properties, node) {
-        if (!strstart(prop->type, "child<", NULL)) {
-            continue;
-        }
-
-        if (prop->opaque == child) {
+        if (strstart(prop->type, "child<", NULL) && prop->opaque == child) {
             object_property_del(obj, prop->name, errp);
+            break;
         }
     }
 }