Patchwork [3/6] Check return value of qdev_init()

login
register
mail settings
Submitter Markus Armbruster
Date Sept. 11, 2009, 8:19 p.m.
Message ID <95d0eb3d81114087385f218102f142e68d769171.1252699478.git.armbru@redhat.com>
Download mbox | patch
Permalink /patch/33491/
State Superseded
Headers show

Comments

Markus Armbruster - Sept. 11, 2009, 8:19 p.m.
But do so only where it may actually fail.  Leave the rest for the
next commit.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/pci-hotplug.c |    4 ++--
 hw/pci.c         |    4 +++-
 hw/scsi-bus.c    |    4 +++-
 hw/usb-msd.c     |    3 ++-
 4 files changed, 10 insertions(+), 5 deletions(-)

Patch

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index 5348dd1..1f2dff9 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -149,8 +149,8 @@  static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,
     default:
         dev = NULL;
     }
-    if (dev)
-        qdev_init(&dev->qdev);
+    if (!dev || qdev_init(&dev->qdev) < 0)
+        return NULL;
     return dev;
 }
 
diff --git a/hw/pci.c b/hw/pci.c
index c12b0be..8dc8864 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -807,6 +807,7 @@  static const char * const pci_nic_names[] = {
 };
 
 /* Initialize a PCI NIC.  */
+/* FIXME callers should check for failure, but don't */
 PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
                         const char *default_devaddr)
 {
@@ -824,7 +825,8 @@  PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,
             if (nd->id)
                 dev->id = qemu_strdup(nd->id);
             dev->nd = nd;
-            qdev_init(dev);
+            if (qdev_init(dev) < 0)
+                return NULL;
             nd->private = dev;
             return pci_dev;
         }
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 16afa05..d751f6a 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -65,6 +65,7 @@  void scsi_qdev_register(SCSIDeviceInfo *info)
 }
 
 /* handle legacy '-drive if=scsi,...' cmd line args */
+/* FIXME callers should check for failure, but don't */
 SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit)
 {
     const char *driver;
@@ -74,7 +75,8 @@  SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit)
     dev = qdev_create(&bus->qbus, driver);
     qdev_prop_set_uint32(dev, "scsi-id", unit);
     qdev_prop_set_drive(dev, "drive", dinfo);
-    qdev_init(dev);
+    if (qdev_init(dev) < 0)
+        return NULL;
     return DO_UPCAST(SCSIDevice, qdev, dev);
 }
 
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index aa0ce6a..0c7ad5c 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -579,7 +579,8 @@  USBDevice *usb_msd_init(const char *filename)
     /* create guest device */
     dev = usb_create(NULL /* FIXME */, "QEMU USB MSD");
     qdev_prop_set_drive(&dev->qdev, "drive", dinfo);
-    qdev_init(&dev->qdev);
+    if (qdev_init(&dev->qdev) < 0)
+        return NULL;
 
     return dev;
 }