From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56472) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TfeqC-0002Mv-OP for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:50:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TfeqB-0003w2-Bp for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:50:20 -0500 Sender: fluxion From: Michael Roth Date: Mon, 3 Dec 2012 16:44:38 -0600 Message-Id: <1354574681-28954-9-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1354572547-21271-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1354572547-21271-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 41/43] usb: fail usbdevice_create() when there is no USB bus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-stable@nongnu.org Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org From: 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 Note that the vexpress-a9 machine does not have a USB host controller. Reported-by: David Abdurachmanov Signed-off-by: Stefan Hajnoczi Signed-off-by: Gerd Hoffmann (cherry picked from commit c128d6a6d785eb9235a4f6dbd52f405ab8c60bee) Signed-off-by: Michael Roth --- hw/usb/bus.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index b649360..1f73a52 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -585,6 +585,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); -- 1.7.9.5