From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTGZc-00036D-BI for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTGZa-0008M9-SD for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51939) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTGZa-0008KP-Ks for qemu-devel@nongnu.org; Wed, 23 Nov 2011 12:25:26 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pANHPKvl029098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 23 Nov 2011 12:25:20 -0500 From: Gerd Hoffmann Date: Wed, 23 Nov 2011 18:25:11 +0100 Message-Id: <1322069117-27150-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1322069117-27150-1-git-send-email-kraxel@redhat.com> References: <1322069117-27150-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 1/7] usb: make usb_create_simple catch and pass up errors. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Use qdev_init() instead of qdev_init_nofail(), usb device initialization can fail, most common case being port and device speed mismatch. Handle failures correctly and pass up NULL pointers then. Also fixup usb_create_simple() callers (only one was buggy) to properly check for NULL pointers before referncing the usb_create_simple() return value. Signed-off-by: Gerd Hoffmann --- hw/usb-bt.c | 3 +++ hw/usb-bus.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/usb-bt.c b/hw/usb-bt.c index 529fa33..f30eec1 100644 --- a/hw/usb-bt.c +++ b/hw/usb-bt.c @@ -528,6 +528,9 @@ USBDevice *usb_bt_init(HCIInfo *hci) if (!hci) return NULL; dev = usb_create_simple(NULL /* FIXME */, "usb-bt-dongle"); + if (!dev) { + return NULL; + } s = DO_UPCAST(struct USBBtState, dev, dev); s->dev.opaque = s; diff --git a/hw/usb-bus.c b/hw/usb-bus.c index 93f640d..f8b9807 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -139,10 +139,17 @@ USBDevice *usb_create(USBBus *bus, const char *name) USBDevice *usb_create_simple(USBBus *bus, const char *name) { USBDevice *dev = usb_create(bus, name); + int rc; + if (!dev) { - hw_error("Failed to create USB device '%s'\n", name); + error_report("Failed to create USB device '%s'\n", name); + return NULL; + } + rc = qdev_init(&dev->qdev); + if (rc < 0) { + error_report("Failed to initialize USB device '%s'\n", name); + return NULL; } - qdev_init_nofail(&dev->qdev); return dev; } -- 1.7.1