@@ -174,6 +174,15 @@ DeviceState *qdev_try_new(const char *name)
return DEVICE(object_new(name));
}
+DeviceState *qdev_create_simple(const char *name, Error **errp)
+{
+ DeviceState *dev = qdev_new(name);
+
+ qdev_realize_and_unref(dev, NULL, errp);
+
+ return dev;
+}
+
static QTAILQ_HEAD(, DeviceListener) device_listeners
= QTAILQ_HEAD_INITIALIZER(device_listeners);
@@ -397,6 +397,17 @@ bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp);
* the life of the simulation and should not be unrealized and freed.
*/
void qdev_unrealize(DeviceState *dev);
+
+/**
+ * Create and realize a device on the heap.
+ * @name: device type to create (we assert() that this type exists)
+ * @errp: pointer to error object
+ *
+ * Create the device state structure, initialize it, and drop the
+ * reference to it (the device is realized).
+ */
+DeviceState *qdev_create_simple(const char *name, Error **errp);
+
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
int required_for_version);
HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev);
Add a helper to easily create a qdev with no (or default) property. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/core/qdev.c | 9 +++++++++ include/hw/qdev-core.h | 11 +++++++++++ 2 files changed, 20 insertions(+)