device_add usb-hub causes segfault in qemu-1.0
Bug #904617 reported by
Erik Rull
This bug affects 1 person
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
QEMU |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
When calling the command
(qemu) device_add usb-hub,
qemu replies
Error: usb port 4 (bus usb.0) not found (in use?)
Then qemu crashes with a segfault:
[ 1546.177627] qemu-system-
Maybe it might be related to the docs/usb2.txt where UHCI has only 2 ports. But a mistake in the port number should not cause qemu to crash
To post a comment you must log in.
Commit f462141f18ffdd7 5847f6459ef83d9 0b831d12c0 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 5847f6459ef83d9 0b831d12c0 but it's necessary.
usb_qdev_init() code path. It's not as pretty as the unified error
handling in f462141f18ffdd7
Signed-off-by: Stefan Hajnoczi <email address hidden>
---
hw/usb-bus.c | 12 +++++-------
1 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/hw/usb-bus.c b/hw/usb-bus.c init(DeviceStat e *qdev, DeviceInfo *base) INIT(&dev- >strings) ; port(dev) ; >init(dev) ; port(dev) ; attach( dev); exit(qdev) ; exit(qdev) ;
index 8cafb76..8203390 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -77,23 +77,21 @@ static int usb_qdev_
QLIST_
rc = usb_claim_
if (rc != 0) {
- goto err;
+ return rc;
}
rc = dev->info-
if (rc != 0) {
- goto err;
+ usb_release_
+ return rc;
}
if (dev->auto_attach) {
rc = usb_device_
if (rc != 0) {
- goto err;
+ usb_qdev_
+ return rc;
}
}
return 0;
-
-err:
- usb_qdev_
- return rc;
}
static int usb_qdev_ exit(DeviceStat e *qdev)
--
1.7.7.3