[RFC PATCH v2 014/137] hw/nitro: Give onboard devices a QOM parent

Alexander Graf <[email protected]>
Newsgroups org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv
Message-ID <[email protected]>
Convert the *_orphan() device-creation calls in hw/nitro to the new
parented API introduced earlier in this series, so every onboard
device gets a stable path in the composition tree instead of landing
in /machine/unattached with an unstable device[N] name.

The parent for each device is the object that owns its lifetime: the
machine for board-created devices, the containing device for
composite children.  Names follow existing QOM conventions.

Per-site rationale (reviewers: dispute the modeling here):

  file:line              | parent          | name        | rationale
  machine.c:200          | OBJECT(bridge)  | "heartbeat" | onboard heartbeat is a fixed child of the vsock bridge it plugs into; bridge owns its lifetime
  machine.c:212          | OBJECT(bridge)  | "serial"    | debug-mode serial-over-vsock is a fixed child of the same bridge
  nitro-vsock-bus.c:51   | ORPHAN-JUSTIFIED| -           | bridge is parented immediately after via qdev_set_id() to /machine/peripheral/nitro-vsock; keep the orphan creator here

Link: https://lore.kernel.org/qemu-devel/[email protected]/
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/nitro/machine.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/nitro/machine.c b/hw/nitro/machine.c
index efcc2c8a3f..6b61de911f 100644
--- a/hw/nitro/machine.c
+++ b/hw/nitro/machine.c
@@ -195,10 +195,11 @@ static void nitro_machine_init(MachineState *machine)
 
     if (defaults_enabled()) {
         NitroVsockBridge *bridge = nitro_vsock_bridge_create();
+        DeviceState *dev;
 
         /* Nitro Enclaves require a heartbeat device. Provide one. */
-        qdev_realize(qdev_new_orphan(TYPE_NITRO_HEARTBEAT),
-                     BUS(&bridge->bus), &error_fatal);
+        dev = qdev_new(OBJECT(bridge), "heartbeat", TYPE_NITRO_HEARTBEAT);
+        qdev_realize(dev, BUS(&bridge->bus), &error_fatal);
 
         /*
          * In debug mode, Nitro Enclaves expose the guest's serial output via
@@ -209,8 +210,8 @@ static void nitro_machine_init(MachineState *machine)
             Chardev *chr = serial_hd(0);
 
             if (chr) {
-                DeviceState *dev = qdev_new_orphan(TYPE_NITRO_SERIAL_VSOCK);
-
+                dev = qdev_new(OBJECT(bridge), "serial",
+                               TYPE_NITRO_SERIAL_VSOCK);
                 qdev_prop_set_chr(dev, "chardev", chr);
                 qdev_realize(dev, BUS(&bridge->bus), &error_fatal);
             }
-- 
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.