mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 03:59:52 +00:00
usb: fix usb_qdev_init() error handling again
Commitf462141f18
introduced clean up code when usb_qdev_init() fails. Unfortunately it calls .handle_destroy() when .init() was never invoked or failed. This can lead to crashes when .handle_destroy() tries to clean up things that were never initialized. This patch is careful to undo only those steps that completed along the usb_qdev_init() code path. It's not as pretty as the unified error handling inf462141f18
but it's necessary. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
56384e8b1e
commit
db3a5ed7e4
12
hw/usb-bus.c
12
hw/usb-bus.c
@ -77,23 +77,21 @@ static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base)
|
||||
QLIST_INIT(&dev->strings);
|
||||
rc = usb_claim_port(dev);
|
||||
if (rc != 0) {
|
||||
goto err;
|
||||
return rc;
|
||||
}
|
||||
rc = dev->info->init(dev);
|
||||
if (rc != 0) {
|
||||
goto err;
|
||||
usb_release_port(dev);
|
||||
return rc;
|
||||
}
|
||||
if (dev->auto_attach) {
|
||||
rc = usb_device_attach(dev);
|
||||
if (rc != 0) {
|
||||
goto err;
|
||||
usb_qdev_exit(qdev);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
err:
|
||||
usb_qdev_exit(qdev);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int usb_qdev_exit(DeviceState *qdev)
|
||||
|
Loading…
Reference in New Issue
Block a user