Patchwork [v9,2/3] qom: call class destructor before unparent

login
register
mail settings
Submitter Michael S. Tsirkin
Date March 21, 2013, 12:07 p.m.
Message ID <ff3eb77fc8260e634941cef66e7aa754ae9f91ee.1363633627.git.mst@redhat.com>
Download mbox | patch
Permalink /patch/229638/
State New
Headers show

Comments

Michael S. Tsirkin - March 21, 2013, 12:07 p.m.
Make sure object is valid when destructor is called.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 qom/object.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Paolo Bonzini - March 21, 2013, 12:25 p.m.
Il 21/03/2013 13:07, Michael S. Tsirkin ha scritto:
> Make sure object is valid when destructor is called.

"Make sure the object still has a canonical path while the unparent
callback is running".

Otherwise, the series looks good.

Paolo

> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
>  qom/object.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/qom/object.c b/qom/object.c
> index 3d638ff..a0e3cbe 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -363,12 +363,12 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
>  void object_unparent(Object *obj)
>  {
>      object_ref(obj);
> -    if (obj->parent) {
> -        object_property_del_child(obj->parent, obj, NULL);
> -    }
>      if (obj->class->unparent) {
>          (obj->class->unparent)(obj);
>      }
> +    if (obj->parent) {
> +        object_property_del_child(obj->parent, obj, NULL);
> +    }
>      object_unref(obj);
>  }
>  
>
Michael S. Tsirkin - March 21, 2013, 12:30 p.m.
On Thu, Mar 21, 2013 at 01:25:50PM +0100, Paolo Bonzini wrote:
> Il 21/03/2013 13:07, Michael S. Tsirkin ha scritto:
> > Make sure object is valid when destructor is called.
> 
> "Make sure the object still has a canonical path while the unparent
> callback is running".
> 
> Otherwise, the series looks good.
> 
> Paolo

Worth respinning for?

> > Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> > ---
> >  qom/object.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/qom/object.c b/qom/object.c
> > index 3d638ff..a0e3cbe 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -363,12 +363,12 @@ static void object_property_del_child(Object *obj, Object *child, Error **errp)
> >  void object_unparent(Object *obj)
> >  {
> >      object_ref(obj);
> > -    if (obj->parent) {
> > -        object_property_del_child(obj->parent, obj, NULL);
> > -    }
> >      if (obj->class->unparent) {
> >          (obj->class->unparent)(obj);
> >      }
> > +    if (obj->parent) {
> > +        object_property_del_child(obj->parent, obj, NULL);
> > +    }
> >      object_unref(obj);
> >  }
> >  
> >
Paolo Bonzini - March 21, 2013, 12:47 p.m.
Il 21/03/2013 13:30, Michael S. Tsirkin ha scritto:
> On Thu, Mar 21, 2013 at 01:25:50PM +0100, Paolo Bonzini wrote:
> > Il 21/03/2013 13:07, Michael S. Tsirkin ha scritto:
> > > Make sure object is valid when destructor is called.
> > 
> > "Make sure the object still has a canonical path while the unparent
> > callback is running".
> > 
> > Otherwise, the series looks good.
> > 
> 
> Worth respinning for?

If it goes through the pci branch, of course not but still make the
change.  Otherwise, probably not.

Paolo

Patch

diff --git a/qom/object.c b/qom/object.c
index 3d638ff..a0e3cbe 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -363,12 +363,12 @@  static void object_property_del_child(Object *obj, Object *child, Error **errp)
 void object_unparent(Object *obj)
 {
     object_ref(obj);
-    if (obj->parent) {
-        object_property_del_child(obj->parent, obj, NULL);
-    }
     if (obj->class->unparent) {
         (obj->class->unparent)(obj);
     }
+    if (obj->parent) {
+        object_property_del_child(obj->parent, obj, NULL);
+    }
     object_unref(obj);
 }