From patchwork Sun Nov 25 15:49:15 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 201646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3578A2C008E for ; Mon, 26 Nov 2012 21:17:49 +1100 (EST) Received: from localhost ([::1]:51388 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tcvl4-0004go-T3 for incoming@patchwork.ozlabs.org; Mon, 26 Nov 2012 05:17:46 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tcvkp-0004ga-G2 for qemu-devel@nongnu.org; Mon, 26 Nov 2012 05:17:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tcvkj-0004Et-PA for qemu-devel@nongnu.org; Mon, 26 Nov 2012 05:17:31 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tcvkj-0004Eo-HP for qemu-devel@nongnu.org; Mon, 26 Nov 2012 05:17:25 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAQAHNIO017326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 26 Nov 2012 05:17:23 -0500 Received: from localhost (ovpn-112-34.ams2.redhat.com [10.36.112.34]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qAQAHLVs022664; Mon, 26 Nov 2012 05:17:22 -0500 From: Stefan Hajnoczi To: Date: Sun, 25 Nov 2012 16:49:15 +0100 Message-Id: <1353858555-29592-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Maydell , Gerd Hoffmann , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] usb: fail usbdevice_create() when there is no USB bus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/usb/bus.c | 7 +++++++ 1 file changed, 7 insertions(+) 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);