]> git.proxmox.com Git - mirror_qemu.git/commitdiff
usb: make usb_create_simple catch and pass up errors.
authorGerd Hoffmann <kraxel@redhat.com>
Tue, 22 Nov 2011 11:39:58 +0000 (12:39 +0100)
committerGerd Hoffmann <kraxel@redhat.com>
Tue, 22 Nov 2011 12:38:12 +0000 (13:38 +0100)
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
hw/usb-bus.c

index 529fa3355d7698259ae8bacdb051a3557b0dabc2..f30eec1ea2db1a164c91b11aa955a873429ac1b7 100644 (file)
@@ -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;
 
index 93f640d3707f97fc6e295ad380a239a3d9ea1656..f8b98072328e414997e293a1e40995d0ac041367 100644 (file)
@@ -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;
 }