From 3a14a02f29161de34d892265364d5b095164d724 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 17 Feb 2012 09:52:23 +0100 Subject: [PATCH 2/5] Fix -usbdevice crash RH-Author: Gerd Hoffmann Message-id: <1329472346-21224-2-git-send-email-kraxel@redhat.com> Patchwork-id: 37402 O-Subject: [RHEL-6.3 qemu-kvm PATCH 1/4] Fix -usbdevice crash Bugzilla: 754349 RH-Acked-by: Markus Armbruster RH-Acked-by: Amit Shah RH-Acked-by: Hans de Goede 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 (cherry picked from commit d44168fffa07fc57e61a37da65e9348661dec887) Conflicts: hw/usb-msd.c --- hw/usb-bus.c | 3 +++ hw/usb-net.c | 3 +++ hw/usb-serial.c | 3 +++ 3 files changed, 9 insertions(+), 0 deletions(-) Signed-off-by: Michal Novotny --- hw/usb-bus.c | 3 +++ hw/usb-net.c | 3 +++ hw/usb-serial.c | 3 +++ 3 files changed, 9 insertions(+), 0 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index cd9f98c..67e0531 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -139,6 +139,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-net.c b/hw/usb-net.c index 3937190..5dfc4f1 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -1412,6 +1412,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 7133467..8947b34 100644 --- a/hw/usb-serial.c +++ b/hw/usb-serial.c @@ -542,6 +542,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); -- 1.7.7.6