qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 1/7] usb: make usb_create_simple catch and pass up errors.
Date: Wed, 23 Nov 2011 18:25:11 +0100	[thread overview]
Message-ID: <1322069117-27150-2-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1322069117-27150-1-git-send-email-kraxel@redhat.com>

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 <kraxel@redhat.com>
---
 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

  reply	other threads:[~2011-11-23 17:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-23 17:25 [Qemu-devel] [PULL 1.0] usb fixes Gerd Hoffmann
2011-11-23 17:25 ` Gerd Hoffmann [this message]
2011-11-23 17:25 ` [Qemu-devel] [PATCH 2/7] usb: fix usb_qdev_init error handling Gerd Hoffmann
2011-11-23 17:25 ` [Qemu-devel] [PATCH 3/7] usb-hub: wakeup on detach too Gerd Hoffmann
2011-11-23 17:25 ` [Qemu-devel] [PATCH 4/7] usb-hub: implement reset Gerd Hoffmann
2011-11-23 17:25 ` [Qemu-devel] [PATCH 5/7] usb-ehci: codestyle fixups Gerd Hoffmann
2011-11-23 17:25 ` [Qemu-devel] [PATCH 6/7] usb-ehci: add register names Gerd Hoffmann
2011-11-23 17:25 ` [Qemu-devel] [PATCH 7/7] usb-host: add usb_host_do_reset function Gerd Hoffmann
2011-11-28 22:33 ` [Qemu-devel] [PULL 1.0] usb fixes Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1322069117-27150-2-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).