提交 c128d6a6 编写于 作者: S Stefan Hajnoczi 提交者: Gerd Hoffmann

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.
Reported-by: NDavid Abdurachmanov <David.Abdurachmanov@cern.ch>
Signed-off-by: NStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: NGerd Hoffmann <kraxel@redhat.com>
上级 6c2d1c32
...@@ -590,6 +590,13 @@ USBDevice *usbdevice_create(const char *cmdline) ...@@ -590,6 +590,13 @@ USBDevice *usbdevice_create(const char *cmdline)
return NULL; 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 (!f->usbdevice_init) {
if (*params) { if (*params) {
error_report("usbdevice %s accepts no params", driver); error_report("usbdevice %s accepts no params", driver);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册