qdev: add creation function that may fail
authorBlue Swirl <blauwirbel@gmail.com>
Sat, 5 Feb 2011 14:34:25 +0000 (14:34 +0000)
committerBlue Swirl <blauwirbel@gmail.com>
Sat, 12 Feb 2011 08:27:55 +0000 (08:27 +0000)
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
hw/qdev.c
hw/qdev.h

index c7fec44a83e5e8f1fa9f6c1327690a2a97bc9368..1aa1ea0e264f96ecf7c6b95b147dab036581162a 100644 (file)
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -105,6 +105,18 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info)
    and allows properties to be set.  qdev_init should be called to
    initialize the actual device emulation.  */
 DeviceState *qdev_create(BusState *bus, const char *name)
+{
+    DeviceState *dev;
+
+    dev = qdev_try_create(bus, name);
+    if (!dev) {
+        hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
+    }
+
+    return dev;
+}
+
+DeviceState *qdev_try_create(BusState *bus, const char *name)
 {
     DeviceInfo *info;
 
@@ -114,7 +126,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
 
     info = qdev_find_info(bus->info, name);
     if (!info) {
-        hw_error("Unknown device '%s' for bus '%s'\n", name, bus->info->name);
+        return NULL;
     }
 
     return qdev_create_from_info(bus, info);
index 9808f85119700449c9eca96d36f0aaba4e3c5270..8a13ec95cc6a96521ec4e54ffa3d48c914b1ddf4 100644 (file)
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -122,6 +122,7 @@ typedef struct GlobalProperty {
 /*** Board API.  This should go away once we have a machine config file.  ***/
 
 DeviceState *qdev_create(BusState *bus, const char *name);
+DeviceState *qdev_try_create(BusState *bus, const char *name);
 int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts);
 int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;