From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MrGhM-0006as-C4 for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:20 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MrGhH-0006V7-5r for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:19 -0400 Received: from [199.232.76.173] (port=56063 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MrGhG-0006Ur-7z for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15421) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MrGhF-0004g8-Lt for qemu-devel@nongnu.org; Fri, 25 Sep 2009 15:43:13 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8PJhCi9002529 for ; Fri, 25 Sep 2009 15:43:13 -0400 From: Gerd Hoffmann Date: Fri, 25 Sep 2009 21:42:47 +0200 Message-Id: <1253907769-1067-23-git-send-email-kraxel@redhat.com> In-Reply-To: <1253907769-1067-1-git-send-email-kraxel@redhat.com> References: <1253907769-1067-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 22/24] refactor drive_hot_add List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann move pci device lookup into the "case IF_SCSI" section, so we can do something else for other interface types. Signed-off-by: Gerd Hoffmann --- hw/pci-hotplug.c | 38 +++++++++++++++++++------------------- 1 files changed, 19 insertions(+), 19 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 6a08555..562b6b8 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -54,48 +54,48 @@ void drive_hot_add(Monitor *mon, const QDict *qdict) int dom, pci_bus; unsigned slot; int type, bus; - int success = 0; PCIDevice *dev; - DriveInfo *dinfo; + DriveInfo *dinfo = NULL; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); const char *opts = qdict_get_str(qdict, "opts"); BusState *scsibus; - if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) { - return; - } - - dev = pci_find_device(pci_bus, slot, 0); - if (!dev) { - monitor_printf(mon, "no pci device with address %s\n", pci_addr); - return; - } - dinfo = add_init_drive(opts); if (!dinfo) - return; + goto err; if (dinfo->devaddr) { monitor_printf(mon, "Parameter addr not supported\n"); - return; + goto err; } type = dinfo->type; bus = drive_get_max_bus (type); switch (type) { case IF_SCSI: - success = 1; + if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) { + goto err; + } + dev = pci_find_device(pci_bus, slot, 0); + if (!dev) { + monitor_printf(mon, "no pci device with address %s\n", pci_addr); + goto err; + } scsibus = QLIST_FIRST(&dev->qdev.child_bus); scsi_bus_legacy_add_drive(DO_UPCAST(SCSIBus, qbus, scsibus), dinfo, dinfo->unit); + monitor_printf(mon, "OK bus %d, unit %d\n", + dinfo->bus, + dinfo->unit); break; default: monitor_printf(mon, "Can't hot-add drive to type %d\n", type); + goto err; } + return; - if (success) - monitor_printf(mon, "OK bus %d, unit %d\n", - dinfo->bus, - dinfo->unit); +err: + if (dinfo) + drive_uninit(dinfo); return; } -- 1.6.2.5