Skip to contentSkip to conversation

usb: fail usbdevice_create() when there is no USB bus

PATCH In review Stefan Hajnoczi 2 participants 2 messages Nov 26, 2012 – Nov 27, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: fail usbdevice_create() when there is no USB bus

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.

---
 hw/usb/bus.c | 7 +++++++
 1 file changed, 7 insertions(+)
hw/usb/bus.c +7 -0
index 99aac7a..55d0edd 100644
@@ -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);
Signature · 1 line
1.8.0
#1 lore raw
Quoted 9 lines · Stefan Hajnoczi

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
Quoted 4 lines

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

Patch added to usb patch queue.

thanks,
Gerd