From patchwork Wed Jun 2 20:19:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 54428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CC94CB7D51 for ; Thu, 3 Jun 2010 06:25:08 +1000 (EST) Received: from localhost ([127.0.0.1]:49463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJuUr-00088Z-CP for incoming@patchwork.ozlabs.org; Wed, 02 Jun 2010 16:25:05 -0400 Received: from [140.186.70.92] (port=57008 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJuQL-0005I4-Ky for qemu-devel@nongnu.org; Wed, 02 Jun 2010 16:20:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJuQG-0003f6-K5 for qemu-devel@nongnu.org; Wed, 02 Jun 2010 16:20:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49601) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJuQG-0003et-Dc for qemu-devel@nongnu.org; Wed, 02 Jun 2010 16:20:20 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o52KKBQv005694 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 2 Jun 2010 16:20:11 -0400 Received: from localhost (vpn-10-141.rdu.redhat.com [10.11.10.141]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o52KK9mt032611; Wed, 2 Jun 2010 16:20:10 -0400 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Wed, 2 Jun 2010 17:19:54 -0300 Message-Id: <1275509996-25823-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1275509996-25823-1-git-send-email-lcapitulino@redhat.com> References: <1275509996-25823-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Paul Brook Subject: [Qemu-devel] [STABLE 1/3] Fix -usbdevice crash X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Paul Brook If -usbdevice is used on a machine with no USB busses, usb_create will fail and return NULL. Patch below handles this failure gracefully rather than crashing when we try to init the device. Signed-off-by: Paul Brook (cherry picked from commit d44168fffa07fc57e61a37da65e9348661dec887) --- hw/usb-bus.c | 3 +++ hw/usb-msd.c | 3 +++ hw/usb-net.c | 3 +++ hw/usb-serial.c | 3 +++ 4 files changed, 12 insertions(+), 0 deletions(-) diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 54027df..7c82314 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -102,6 +102,9 @@ USBDevice *usb_create(USBBus *bus, const char *name) USBDevice *usb_create_simple(USBBus *bus, const char *name) { USBDevice *dev = usb_create(bus, name); + if (!dev) { + hw_error("Failed to create USB device '%s'\n", name); + } qdev_init_nofail(&dev->qdev); return dev; } diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 1fb62ad..9d8d044 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -592,6 +592,9 @@ static USBDevice *usb_msd_init(const char *filename) /* create guest device */ dev = usb_create(NULL /* FIXME */, "usb-storage"); + if (!dev) { + return NULL; + } qdev_prop_set_drive(&dev->qdev, "drive", dinfo); if (qdev_init(&dev->qdev) < 0) return NULL; diff --git a/hw/usb-net.c b/hw/usb-net.c index cfd2f62..6875f11 100644 --- a/hw/usb-net.c +++ b/hw/usb-net.c @@ -1491,6 +1491,9 @@ static USBDevice *usb_net_init(const char *cmdline) } dev = usb_create(NULL /* FIXME */, "usb-net"); + if (!dev) { + return NULL; + } qdev_set_nic_properties(&dev->qdev, &nd_table[idx]); qdev_init_nofail(&dev->qdev); return dev; diff --git a/hw/usb-serial.c b/hw/usb-serial.c index c3f3401..1410b11 100644 --- a/hw/usb-serial.c +++ b/hw/usb-serial.c @@ -594,6 +594,9 @@ static USBDevice *usb_serial_init(const char *filename) return NULL; dev = usb_create(NULL /* FIXME */, "usb-serial"); + if (!dev) { + return NULL; + } qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); if (vendorid) qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid);