Convert the *_orphan() device-creation calls in hw/cxl 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):

hw/cxl/cxl-host.c:29 | qdev_new | parent (new arg) | "cxl-fmw[*]" | Property 
setter machine_set_cfmw() has Object *obj = machine; thread it through as 
parent for each fixed memory window

Link: https://lore.kernel.org/qemu-devel/[email protected]/
Assisted-by: Kiro
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/cxl/cxl-host.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/hw/cxl/cxl-host.c b/hw/cxl/cxl-host.c
index c7a40a81f0..91ccd0d57c 100644
--- a/hw/cxl/cxl-host.c
+++ b/hw/cxl/cxl-host.c
@@ -22,11 +22,12 @@
 #include "hw/pci/pcie_port.h"
 #include "hw/pci-bridge/pci_expander_bridge.h"
 
-static void cxl_fixed_memory_window_config(CXLFixedMemoryWindowOptions *object,
+static void cxl_fixed_memory_window_config(Object *parent,
+                                           CXLFixedMemoryWindowOptions *object,
                                            int index, Error **errp)
 {
     ERRP_GUARD();
-    DeviceState *dev = qdev_new_orphan(TYPE_CXL_FMW);
+    DeviceState *dev = qdev_new(parent, "cxl-fmw[*]", TYPE_CXL_FMW);
     CXLFixedWindow *fw = CXL_FMW(dev);
     strList *target;
     int i;
@@ -67,7 +68,7 @@ static void 
cxl_fixed_memory_window_config(CXLFixedMemoryWindowOptions *object,
         fw->targets[i] = g_strdup(target->value);
     }
 
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), errp);
+    sysbus_realize(SYS_BUS_DEVICE(dev), errp);
 }
 
 static int cxl_fmws_link(Object *obj, void *opaque)
@@ -557,7 +558,7 @@ static void machine_set_cfmw(Object *obj, Visitor *v, const 
char *name,
     }
 
     for (it = cfmw_list, index = 0; it; it = it->next, index++) {
-        cxl_fixed_memory_window_config(it->value, index, errp);
+        cxl_fixed_memory_window_config(obj, it->value, index, errp);
     }
     state->cfmw_list = cfmw_list;
 }
-- 
2.47.1


Reply via email to