Convert the *_orphan() device-creation calls in hw/s390x 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
  ap-bridge.c:52         | qdev_get_machine()  | TYPE_AP_BRIDGE | already 
parented via object_property_add_child(); collapse into qdev_new() and keep the 
same name for QOM-path stability
  css-bridge.c:95        | qdev_get_machine()  | TYPE_VIRTUAL_CSS_BRIDGE | 
already parented via object_property_add_child(); collapse into qdev_new()
  s390-pci-bus.c:970     | OBJECT(s)           | "zpci[*]"   | auto-created 
zPCI companion for a hot-plugged PCI device; the S390pciState host bridge owns 
it; auto-index name
  s390-virtio-ccw.c:256  | OBJECT(ef)          | type        | already parented 
to the SCLP event facility; collapse into qdev_new() and keep the type-derived 
name
  s390-virtio-ccw.c:268  | OBJECT(ef)          | "sclpcpi"   | already 
parented; collapse into qdev_new()
  s390-virtio-ccw.c:312  | OBJECT(machine)     | TYPE_S390_PCI_HOST_BRIDGE | 
already parented to machine; collapse into qdev_new() with the same name

Link: https://lore.kernel.org/qemu-devel/[email protected]/
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/s390x/ap-bridge.c       |  6 ++----
 hw/s390x/css-bridge.c      |  7 +++----
 hw/s390x/s390-pci-bus.c    |  4 ++--
 hw/s390x/s390-virtio-ccw.c | 17 +++++++----------
 4 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/hw/s390x/ap-bridge.c b/hw/s390x/ap-bridge.c
index ce9b09240a..d7b2c4bddc 100644
--- a/hw/s390x/ap-bridge.c
+++ b/hw/s390x/ap-bridge.c
@@ -49,10 +49,8 @@ void s390_init_ap(void)
     }
 
     /* Create bridge device */
-    dev = qdev_new_orphan(TYPE_AP_BRIDGE);
-    object_property_add_child(qdev_get_machine(), TYPE_AP_BRIDGE,
-                              OBJECT(dev));
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    dev = qdev_new(qdev_get_machine(), TYPE_AP_BRIDGE, TYPE_AP_BRIDGE);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     /* Create bus on bridge device */
     bus = qbus_new(TYPE_AP_BUS, dev, TYPE_AP_BUS);
diff --git a/hw/s390x/css-bridge.c b/hw/s390x/css-bridge.c
index c6be24e5cb..8929d47b1b 100644
--- a/hw/s390x/css-bridge.c
+++ b/hw/s390x/css-bridge.c
@@ -92,9 +92,8 @@ VirtualCssBus *virtual_css_bus_init(void)
     DeviceState *dev;
 
     /* Create bridge device */
-    dev = qdev_new_orphan(TYPE_VIRTUAL_CSS_BRIDGE);
-    object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE,
-                              OBJECT(dev));
+    dev = qdev_new(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE,
+                   TYPE_VIRTUAL_CSS_BRIDGE);
 
     /* Create bus on bridge device */
     bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
@@ -102,7 +101,7 @@ VirtualCssBus *virtual_css_bus_init(void)
     /* Enable hotplugging */
     qbus_set_hotplug_handler(bus, OBJECT(dev));
 
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
                              0, &error_abort);
diff --git a/hw/s390x/s390-pci-bus.c b/hw/s390x/s390-pci-bus.c
index bc335ca883..4f0a8a787b 100644
--- a/hw/s390x/s390-pci-bus.c
+++ b/hw/s390x/s390-pci-bus.c
@@ -967,7 +967,7 @@ static S390PCIBusDevice *s390_pci_device_new(S390pciState 
*s,
     Error *local_err = NULL;
     DeviceState *dev;
 
-    dev = qdev_try_new_orphan(TYPE_S390_PCI_DEVICE);
+    dev = qdev_try_new(OBJECT(s), "zpci[*]", TYPE_S390_PCI_DEVICE);
     if (!dev) {
         error_setg(errp, "zPCI device could not be created");
         return NULL;
@@ -979,7 +979,7 @@ static S390PCIBusDevice *s390_pci_device_new(S390pciState 
*s,
                                 "zPCI device could not be created: ");
         return NULL;
     }
-    if (!qdev_realize_and_unref(dev, BUS(s->bus), &local_err)) {
+    if (!qdev_realize(dev, BUS(s->bus), &local_err)) {
         object_unparent(OBJECT(dev));
         error_propagate_prepend(errp, local_err,
                                 "zPCI device could not be created: ");
diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index f9eb6cb411..1848cde0c4 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -253,10 +253,9 @@ static void s390_create_sclpconsole(SCLPDevice *sclp,
     BusState *ev_fac_bus = sclp_get_event_facility_bus(ef);
     DeviceState *dev;
 
-    dev = qdev_new_orphan(type);
-    object_property_add_child(OBJECT(ef), type, OBJECT(dev));
+    dev = qdev_new(OBJECT(ef), type, type);
     qdev_prop_set_chr(dev, "chardev", chardev);
-    qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal);
+    qdev_realize(dev, ev_fac_bus, &error_fatal);
 }
 
 static void s390_create_sclpcpi(SCLPDevice *sclp)
@@ -265,9 +264,8 @@ static void s390_create_sclpcpi(SCLPDevice *sclp)
     BusState *ev_fac_bus = sclp_get_event_facility_bus(ef);
     DeviceState *dev;
 
-    dev = qdev_new_orphan(TYPE_SCLP_EVENT_CPI);
-    object_property_add_child(OBJECT(ef), "sclpcpi", OBJECT(dev));
-    qdev_realize_and_unref(dev, ev_fac_bus, &error_fatal);
+    dev = qdev_new(OBJECT(ef), "sclpcpi", TYPE_SCLP_EVENT_CPI);
+    qdev_realize(dev, ev_fac_bus, &error_fatal);
 }
 
 static void ccw_init(MachineState *machine)
@@ -309,10 +307,9 @@ static void ccw_init(MachineState *machine)
                       machine->firmware ?: "s390-ccw.img",
                       true);
 
-    dev = qdev_new_orphan(TYPE_S390_PCI_HOST_BRIDGE);
-    object_property_add_child(qdev_get_machine(), TYPE_S390_PCI_HOST_BRIDGE,
-                              OBJECT(dev));
-    sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
+    dev = qdev_new(OBJECT(machine), TYPE_S390_PCI_HOST_BRIDGE,
+                   TYPE_S390_PCI_HOST_BRIDGE);
+    sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
 
     s390_enable_css_support(s390_cpu_addr2state(0));
 
-- 
2.47.1


Reply via email to