aboutsummaryrefslogtreecommitdiff
path: root/hw/usb-bus.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2011-11-22 12:48:14 +0100
committerGerd Hoffmann <kraxel@redhat.com>2011-11-22 14:12:32 +0100
commitf462141f18ffdd75847f6459ef83d90b831d12c0 (patch)
tree5b574f35441db5b8a229561f72840cbc457761f7 /hw/usb-bus.c
parent2af2a1b8d05a1a64c5005ed930137632b9d5aa22 (diff)
downloadqemu-f462141f18ffdd75847f6459ef83d90b831d12c0.zip
qemu-f462141f18ffdd75847f6459ef83d90b831d12c0.tar.gz
qemu-f462141f18ffdd75847f6459ef83d90b831d12c0.tar.bz2
usb: fix usb_qdev_init error handling.
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 <kraxel@redhat.com>
Diffstat (limited to 'hw/usb-bus.c')
-rw-r--r--hw/usb-bus.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index f8b9807..8cafb76 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;
}