From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Te3w5-0001zH-59 for qemu-devel@nongnu.org; Thu, 29 Nov 2012 08:13:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Te3vz-0003og-2L for qemu-devel@nongnu.org; Thu, 29 Nov 2012 08:13:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Te3vy-0003oW-QW for qemu-devel@nongnu.org; Thu, 29 Nov 2012 08:13:42 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qATDDgKX019840 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 29 Nov 2012 08:13:42 -0500 From: Gerd Hoffmann Date: Thu, 29 Nov 2012 14:13:39 +0100 Message-Id: <1354194820-7767-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1354194820-7767-1-git-send-email-kraxel@redhat.com> References: <1354194820-7767-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 2/3] usb: fail usbdevice_create() when there is no USB bus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann , Stefan Hajnoczi 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 --- hw/usb/bus.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 99aac7a..55d0edd 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -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); -- 1.7.1