summary refs log tree commit diff stats
path: root/hw/qdev.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-11-23 09:47:13 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2012-11-26 13:41:00 -0600
commit667d22d1ae59da46b4c1fbd094ca61145f19b8c3 (patch)
treedb6acb0b6dce798eb5588ef8d05a9873e8114ddc /hw/qdev.c
parent764b63125a77dab54ed405d493452a4e05679c2e (diff)
downloadfocaccia-qemu-667d22d1ae59da46b4c1fbd094ca61145f19b8c3.tar.gz
focaccia-qemu-667d22d1ae59da46b4c1fbd094ca61145f19b8c3.zip
qdev: move bus removal to object_unparent
Add an ObjectClass method that is done at object_unparent time.  It
should remove any backlinks to the object in the composition tree,
so that object_delete will be able to drop the last reference and
free the object.

Use it for qdev buses.

Reviewed-by: Andreas Färber <afaerber@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev.c')
-rw-r--r--hw/qdev.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/hw/qdev.c b/hw/qdev.c
index 7ddcd24299..f43717baa5 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -705,9 +705,6 @@ static void device_finalize(Object *obj)
             qemu_opts_del(dev->opts);
         }
     }
-    if (dev->parent_bus) {
-        bus_remove_child(dev->parent_bus, dev);
-    }
 }
 
 static void device_class_base_init(ObjectClass *class, void *data)
@@ -720,6 +717,18 @@ static void device_class_base_init(ObjectClass *class, void *data)
     klass->props = NULL;
 }
 
+static void qdev_remove_from_bus(Object *obj)
+{
+    DeviceState *dev = DEVICE(obj);
+
+    bus_remove_child(dev->parent_bus, dev);
+}
+
+static void device_class_init(ObjectClass *class, void *data)
+{
+    class->unparent = qdev_remove_from_bus;
+}
+
 void device_reset(DeviceState *dev)
 {
     DeviceClass *klass = DEVICE_GET_CLASS(dev);
@@ -747,6 +756,7 @@ static TypeInfo device_type_info = {
     .instance_init = device_initfn,
     .instance_finalize = device_finalize,
     .class_base_init = device_class_base_init,
+    .class_init = device_class_init,
     .abstract = true,
     .class_size = sizeof(DeviceClass),
 };