Received: from eggs.gnu.org ([2001:4830:134:3::10]:53155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOTka-0005Te-44 for qemu-devel@nongnu.org; Thu, 19 Feb 2015 11:14:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOTkW-0000he-0A for qemu-devel@nongnu.org; Thu, 19 Feb 2015 11:14:52 -0500 Received: from mail-we0-x236.google.com ([2a00:1450:400c:c03::236]:41534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOTkV-0000ha-Ph for qemu-devel@nongnu.org; Thu, 19 Feb 2015 11:14:47 -0500 Received: by wevm14 with SMTP id m14so673788wev.8 for ; Thu, 19 Feb 2015 08:14:47 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 19 Feb 2015 17:14:41 +0100 Message-Id: <1424362481-54561-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] scsi: give device a parent before setting properties List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: armbru@redhat.com This mimics what is done in qdev_device_add, and lets the device be freed in case something goes wrong. Otherwise, object_unparent returns immediately without freeing the device, which is on the other hand left in the parent bus's list of children. scsi_bus_legacy_handle_cmdline then returns an error, and the HBA is destroyed as well with object_unparent. But the lingering device that was not removed in scsi_bus_legacy_add_drive cannot be removed now either, and bus_unparent gets stuck in an infinite loop trying to empty the list of children. The right fix of course would be to assert in bus_add_child that the device already has a bus, and remove the "safety net" that adds the drive to the QOM tree in device_set_realized. I am not yet sure whether that would entail changing all callers to qdev_create (as well as isa_create and usb_create and the corresponding _try_create versions). Reported-by: Markus Armbruster Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-bus.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c index db39ae0..dca9576 100644 --- a/hw/scsi/scsi-bus.c +++ b/hw/scsi/scsi-bus.c @@ -221,11 +221,16 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk, const char *serial, Error **errp) { const char *driver; + char *name; DeviceState *dev; Error *err = NULL; driver = blk_is_sg(blk) ? "scsi-generic" : "scsi-disk"; dev = qdev_create(&bus->qbus, driver); + name = g_strdup_printf("legacy[%d]", unit); + object_property_add_child(OBJECT(bus), name, OBJECT(dev), NULL); + g_free(name); + qdev_prop_set_uint32(dev, "scsi-id", unit); if (bootindex >= 0) { object_property_set_int(OBJECT(dev), bootindex, "bootindex", -- 2.3.0