[RFC PATCH v2 081/137] hw/nitro: Give the vsock bridge a QOM parent

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-riscv,org.nongnu.qemu-arm,org.nongnu.qemu-devel
Message-ID <[email protected]>
nitro_vsock_bridge_create() was using qdev_set_id() to slot the
bridge under /machine/peripheral.  The bridge is a board-owned
singleton created from nitro_machine_init(), so make it a plain
child of the machine and drop the qdev_set_id() indirection.

The heartbeat device that hangs off the bridge is already a child<>
of it, so the composition tree becomes:

  /machine/nitro-vsock (nitro-vsock-bridge)
  /machine/nitro-vsock/heartbeat (nitro-heartbeat)

AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/nitro/machine.c                 | 2 +-
 hw/nitro/nitro-vsock-bus.c         | 9 ++++-----
 include/hw/nitro/nitro-vsock-bus.h | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/hw/nitro/machine.c b/hw/nitro/machine.c
index 6b61de911f..e522eae5ba 100644
--- a/hw/nitro/machine.c
+++ b/hw/nitro/machine.c
@@ -194,7 +194,7 @@ static void nitro_machine_init(MachineState *machine)
                         MEMTXATTRS_UNSPECIFIED, eif_data, eif_size);
 
     if (defaults_enabled()) {
-        NitroVsockBridge *bridge = nitro_vsock_bridge_create();
+        NitroVsockBridge *bridge = nitro_vsock_bridge_create(OBJECT(machine));
         DeviceState *dev;
 
         /* Nitro Enclaves require a heartbeat device. Provide one. */
diff --git a/hw/nitro/nitro-vsock-bus.c b/hw/nitro/nitro-vsock-bus.c
index f7540eaa54..2c4b66931f 100644
--- a/hw/nitro/nitro-vsock-bus.c
+++ b/hw/nitro/nitro-vsock-bus.c
@@ -20,7 +20,6 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "monitor/qdev.h"
 #include "hw/core/sysbus.h"
 #include "hw/nitro/nitro-vsock-bus.h"
 
@@ -46,12 +45,12 @@ void nitro_vsock_bridge_start_enclave(NitroVsockBridge *bridge,
     }
 }
 
-NitroVsockBridge *nitro_vsock_bridge_create(void)
+NitroVsockBridge *nitro_vsock_bridge_create(Object *parent)
 {
-    DeviceState *dev = qdev_new_orphan(TYPE_NITRO_VSOCK_BRIDGE);
+    DeviceState *dev = qdev_new(parent, "nitro-vsock",
+                                TYPE_NITRO_VSOCK_BRIDGE);
 
-    qdev_set_id(dev, g_strdup("nitro-vsock"), &error_fatal);
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     return NITRO_VSOCK_BRIDGE(dev);
 }
diff --git a/include/hw/nitro/nitro-vsock-bus.h b/include/hw/nitro/nitro-vsock-bus.h
index 064260aa41..36f4dde78f 100644
--- a/include/hw/nitro/nitro-vsock-bus.h
+++ b/include/hw/nitro/nitro-vsock-bus.h
@@ -50,7 +50,7 @@ struct NitroVsockDeviceClass {
 /*
  * Machine helper to create the Nitro vsock bridge sysbus device.
  */
-NitroVsockBridge *nitro_vsock_bridge_create(void);
+NitroVsockBridge *nitro_vsock_bridge_create(Object *parent);
 
 /*
  * Find the Nitro vsock bridge on the sysbus.
-- 
2.47.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.