From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uuwfk-0004D9-3L for qemu-devel@nongnu.org; Thu, 04 Jul 2013 23:27:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uuwfj-0000jg-8H for qemu-devel@nongnu.org; Thu, 04 Jul 2013 23:27:00 -0400 Received: from mail-pa0-x233.google.com ([2607:f8b0:400e:c03::233]:62274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uuwfj-0000jb-15 for qemu-devel@nongnu.org; Thu, 04 Jul 2013 23:26:59 -0400 Received: by mail-pa0-f51.google.com with SMTP id lf11so1802515pab.38 for ; Thu, 04 Jul 2013 20:26:57 -0700 (PDT) From: Liu Ping Fan Date: Fri, 5 Jul 2013 11:26:07 +0800 Message-Id: <1372994767-29506-1-git-send-email-pingfank@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH] qom: trigger unrealized when device_finalize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Currently, unrealized is triggered in device_unparent(). But unrealized normally involves the reclaim of resource occupied by DeviceState. To obey the idiom that reclaiming resource when refcnt reach zero, move it on the path of object_finalize(). As for device_unparent(), it would be the place to detach the device from the other system. Signed-off-by: Liu Ping Fan --- hw/core/qdev.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 9190a7e..4258d8a 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -768,6 +768,10 @@ static void device_initfn(Object *obj) static void device_finalize(Object *obj) { DeviceState *dev = DEVICE(obj); + + if (dev->realized) { + object_property_set_bool(obj, false, "realized", NULL); + } if (dev->opts) { qemu_opts_del(dev->opts); } @@ -794,9 +798,6 @@ static void device_unparent(Object *obj) bus = QLIST_FIRST(&dev->child_bus); qbus_free(bus); } - if (dev->realized) { - object_property_set_bool(obj, false, "realized", NULL); - } if (dev->parent_bus) { bus_remove_child(dev->parent_bus, dev); object_unref(OBJECT(dev->parent_bus)); -- 1.8.1.4