summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2010-06-02 17:19:54 -0300
committerAurelien Jarno <aurelien@aurel32.net>2010-06-09 12:44:56 +0200
commitcc7ed88f281729ed77e6df5254c11d96651eed4d (patch)
treea0c0300af55c21d4de69e10465368ff24bbf2c23
parentFix multiboot compilation (diff)
downloadqemu-kvm-cc7ed88f281729ed77e6df5254c11d96651eed4d.tar.gz
qemu-kvm-cc7ed88f281729ed77e6df5254c11d96651eed4d.tar.bz2
qemu-kvm-cc7ed88f281729ed77e6df5254c11d96651eed4d.zip
Fix -usbdevice crash
If -usbdevice is used on a machine with no USB busses, usb_create will fail and return NULL. Patch below handles this failure gracefully rather than crashing when we try to init the device. Signed-off-by: Paul Brook <paul@codesourcery.com> (cherry picked from commit d44168fffa07fc57e61a37da65e9348661dec887)
-rw-r--r--hw/usb-bus.c3
-rw-r--r--hw/usb-msd.c3
-rw-r--r--hw/usb-net.c3
-rw-r--r--hw/usb-serial.c3
4 files changed, 12 insertions, 0 deletions
diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index 54027dfc4..7c823147a 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -102,6 +102,9 @@ USBDevice *usb_create(USBBus *bus, const char *name)
USBDevice *usb_create_simple(USBBus *bus, const char *name)
{
USBDevice *dev = usb_create(bus, name);
+ if (!dev) {
+ hw_error("Failed to create USB device '%s'\n", name);
+ }
qdev_init_nofail(&dev->qdev);
return dev;
}
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 1fb62ad13..9d8d0443d 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -592,6 +592,9 @@ static USBDevice *usb_msd_init(const char *filename)
/* create guest device */
dev = usb_create(NULL /* FIXME */, "usb-storage");
+ if (!dev) {
+ return NULL;
+ }
qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
if (qdev_init(&dev->qdev) < 0)
return NULL;
diff --git a/hw/usb-net.c b/hw/usb-net.c
index cfd2f62e0..6875f112f 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1491,6 +1491,9 @@ static USBDevice *usb_net_init(const char *cmdline)
}
dev = usb_create(NULL /* FIXME */, "usb-net");
+ if (!dev) {
+ return NULL;
+ }
qdev_set_nic_properties(&dev->qdev, &nd_table[idx]);
qdev_init_nofail(&dev->qdev);
return dev;
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index c3f340137..1410b11b2 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -594,6 +594,9 @@ static USBDevice *usb_serial_init(const char *filename)
return NULL;
dev = usb_create(NULL /* FIXME */, "usb-serial");
+ if (!dev) {
+ return NULL;
+ }
qdev_prop_set_chr(&dev->qdev, "chardev", cdrv);
if (vendorid)
qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid);