Patchwork [09/10] mon: release dev's ref hold by qdev_get_peripheral

login
register
mail settings
Submitter pingfan liu
Date Aug. 24, 2012, 9:49 a.m.
Message ID <1345801763-24227-10-git-send-email-qemulist@gmail.com>
Download mbox | patch
Permalink /patch/179807/
State New
Headers show

Comments

pingfan liu - Aug. 24, 2012, 9:49 a.m.
From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>

When add it at qdev_device_add(), so need to release it
at qmp_device_del().

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 hw/qdev-monitor.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

Patch

diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index fdd9539..29ace17 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -599,6 +599,7 @@  int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
 void qmp_device_del(const char *id, Error **errp)
 {
     DeviceState *dev;
+    int ret;
 
     dev = qdev_find_recursive(sysbus_get_default(), id);
     if (NULL == dev) {
@@ -606,7 +607,12 @@  void qmp_device_del(const char *id, Error **errp)
         return;
     }
 
-    qdev_unplug_req(dev, errp);
+    ret = qdev_unplug_req(dev, errp);
+    if (ret == 0) {
+        /* to here,  dev->id is not zero, so need to release */
+        object_property_del_child(qdev_get_peripheral(),
+                    OBJECT(dev), NULL);
+    }
 }
 
 void qdev_machine_init(void)