]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
usb: fail usbdevice_create() when there is no USB bus
authorStefan Hajnoczi <stefanha@redhat.com>
Sun, 25 Nov 2012 15:49:15 +0000 (16:49 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Thu, 29 Nov 2012 07:04:13 +0000 (08:04 +0100)
Report an error instead of segfaulting when attaching a USB device to a
machine with no USB busses:

  $ qemu-system-arm -machine vexpress-a9 \
      -sd Fedora-17-armhfp-vexpress-mmcblk0.img \
      -kernel vmlinuz-3.4.2-3.fc17.armv7hl \
      -initrd initramfs-3.4.2-3.fc17.armv7hl.img \
      -usbdevice disk:format=raw:test.img

Note that the vexpress-a9 machine does not have a USB host controller.

Reported-by: David Abdurachmanov <David.Abdurachmanov@cern.ch>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
hw/usb/bus.c

index 99aac7a2c02abc69ffc26229528024221bd649d6..55d0edd5c347797836b7681b592470b4bcf3cd01 100644 (file)
@@ -590,6 +590,13 @@ USBDevice *usbdevice_create(const char *cmdline)
         return NULL;
     }
 
+    if (!bus) {
+        error_report("Error: no usb bus to attach usbdevice %s, "
+                     "please try -machine usb=on and check that "
+                     "the machine model supports USB", driver);
+        return NULL;
+    }
+
     if (!f->usbdevice_init) {
         if (*params) {
             error_report("usbdevice %s accepts no params", driver);