f375e62
From cf0ad23ce4dc68d0617b01cc5eefdd133f87cafc Mon Sep 17 00:00:00 2001
f375e62
From: Stefan Hajnoczi <stefanha@redhat.com>
f375e62
Date: Sun, 25 Nov 2012 16:49:15 +0100
f375e62
Subject: [PATCH] usb: fail usbdevice_create() when there is no USB bus
f375e62
f375e62
Report an error instead of segfaulting when attaching a USB device to a
f375e62
machine with no USB busses:
f375e62
f375e62
  $ qemu-system-arm -machine vexpress-a9 \
f375e62
      -sd Fedora-17-armhfp-vexpress-mmcblk0.img \
f375e62
      -kernel vmlinuz-3.4.2-3.fc17.armv7hl \
f375e62
      -initrd initramfs-3.4.2-3.fc17.armv7hl.img \
f375e62
      -usbdevice disk:format=raw:test.img
f375e62
f375e62
Note that the vexpress-a9 machine does not have a USB host controller.
f375e62
f375e62
Reported-by: David Abdurachmanov <David.Abdurachmanov@cern.ch>
f375e62
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
f375e62
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
f375e62
(cherry picked from commit c128d6a6d785eb9235a4f6dbd52f405ab8c60bee)
f375e62
f375e62
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
f375e62
---
f375e62
 hw/usb/bus.c | 7 +++++++
f375e62
 1 file changed, 7 insertions(+)
f375e62
f375e62
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
f375e62
index b649360..1f73a52 100644
f375e62
--- a/hw/usb/bus.c
f375e62
+++ b/hw/usb/bus.c
f375e62
@@ -585,6 +585,13 @@ USBDevice *usbdevice_create(const char *cmdline)
f375e62
         return NULL;
f375e62
     }
f375e62
 
f375e62
+    if (!bus) {
f375e62
+        error_report("Error: no usb bus to attach usbdevice %s, "
f375e62
+                     "please try -machine usb=on and check that "
f375e62
+                     "the machine model supports USB", driver);
f375e62
+        return NULL;
f375e62
+    }
f375e62
+
f375e62
     if (!f->usbdevice_init) {
f375e62
         if (*params) {
f375e62
             error_report("usbdevice %s accepts no params", driver);