From d91cc51f193509d60dc98dc76831e104c4f68c34 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 17 Feb 2012 09:52:25 +0100 Subject: [PATCH 4/5] usb: fix usb_qdev_init error handling. RH-Author: Gerd Hoffmann Message-id: <1329472346-21224-4-git-send-email-kraxel@redhat.com> Patchwork-id: 37406 O-Subject: [RHEL-6.3 qemu-kvm PATCH 3/4] usb: fix usb_qdev_init error handling. Bugzilla: 754349 RH-Acked-by: Markus Armbruster RH-Acked-by: Amit Shah RH-Acked-by: Hans de Goede qdev doesn't call the ->exit callback on ->init failures, so we have to take care ourself that we cleanup property on errors. Signed-off-by: Gerd Hoffmann (cherry picked from commit f462141f18ffdd75847f6459ef83d90b831d12c0) --- hw/usb-bus.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) Signed-off-by: Michal Novotny --- hw/usb-bus.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index bca746f..ca69c9d 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -9,6 +9,7 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); static char *usb_get_dev_path(DeviceState *dev); static char *usb_get_fw_dev_path(DeviceState *qdev); +static int usb_qdev_exit(DeviceState *qdev); static struct BusInfo usb_bus_info = { .name = "USB", @@ -75,12 +76,23 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base) dev->auto_attach = 1; QLIST_INIT(&dev->strings); rc = usb_claim_port(dev); - if (rc == 0) { - rc = dev->info->init(dev); + if (rc != 0) { + goto err; } - if (rc == 0 && dev->auto_attach) { + rc = dev->info->init(dev); + if (rc != 0) { + goto err; + } + if (dev->auto_attach) { rc = usb_device_attach(dev); + if (rc != 0) { + goto err; + } } + return 0; + +err: + usb_qdev_exit(qdev); return rc; } -- 1.7.7.6