qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 08/14] qdev: Add qdev_device_new_from_qdict()


From: Akihiko Odaki
Subject: [PATCH 08/14] qdev: Add qdev_device_new_from_qdict()
Date: Sat, 02 Dec 2023 17:00:31 +0900

qdev_device_new_from_qdict() can be used to create a device from QDict
without realizing it.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 include/monitor/qdev.h |  2 ++
 system/qdev-monitor.c  | 23 ++++++++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index 1d57bf6577..013108a7dd 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -11,6 +11,8 @@ int qdev_device_help(QemuOpts *opts);
 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
 DeviceState *qdev_device_add_from_qdict(const QDict *opts,
                                         bool from_json, Error **errp);
+DeviceState *qdev_device_new_from_qdict(const QDict *opts, bool from_json,
+                                        BusState **busp, Error **errp);
 
 /**
  * qdev_set_id: parent the device and set its id if provided.
diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
index 42aac94b8c..028b97f2b5 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -618,6 +618,25 @@ const char *qdev_set_id(DeviceState *dev, char *id, Error 
**errp)
 
 DeviceState *qdev_device_add_from_qdict(const QDict *opts,
                                         bool from_json, Error **errp)
+{
+    DeviceState *dev;
+    BusState *bus;
+
+    dev = qdev_device_new_from_qdict(opts, from_json, &bus, errp);
+    if (!dev) {
+        return NULL;
+    }
+
+    if (!qdev_realize(dev, bus, errp)) {
+        object_unparent(OBJECT(dev));
+        object_unref(OBJECT(dev));
+    }
+
+    return dev;
+}
+
+DeviceState *qdev_device_new_from_qdict(const QDict *opts, bool from_json,
+                                        BusState **busp, Error **errp)
 {
     ERRP_GUARD();
     DeviceClass *dc;
@@ -720,9 +739,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
         goto err_del_dev;
     }
 
-    if (!qdev_realize(dev, bus, errp)) {
-        goto err_del_dev;
-    }
+    *busp = bus;
     return dev;
 
 err_del_dev:

-- 
2.43.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]