Patchwork [v2,08/12] qdev: add reference for the bus while it is referred to by the DeviceState

login
register
mail settings
Submitter Paolo Bonzini
Date Jan. 21, 2013, 12:30 p.m.
Message ID <1358771422-14282-9-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/214155/
State New
Headers show

Comments

Paolo Bonzini - Jan. 21, 2013, 12:30 p.m.
Now that the unparent callbacks are complete, we can correctly account
more missing references.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/qdev.c | 3 +++
 1 file changed, 3 insertions(+)

Patch

diff --git a/hw/qdev.c b/hw/qdev.c
index aad360f..24bb19a 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -100,6 +100,7 @@  static void bus_add_child(BusState *bus, DeviceState *child)
 void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
 {
     dev->parent_bus = bus;
+    object_ref(OBJECT(bus));
     bus_add_child(bus, dev);
 }
 
@@ -773,6 +774,8 @@  static void device_unparent(Object *obj)
     }
     if (dev->parent_bus) {
         bus_remove_child(dev->parent_bus, dev);
+        object_unref(OBJECT(dev->parent_bus));
+        dev->parent_bus = NULL;
     }
 }