Convert the *_orphan() device-creation calls in hw/ide 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/ide/ide-bus.c:78 | qdev_new | OBJECT(bus->qbus.parent) | "drive[*]" | drive 
is child of the IDE controller device that owns the bus; helper called from 
many controllers so use bus->qbus.parent
hw/ide/isa.c:87 | isa_new | parent | "ide[*]" | helper called from isapc board 
init loop; thread Object *parent through isa_ide_init()

Link: https://lore.kernel.org/qemu-devel/[email protected]/
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/i386/isapc.c      | 3 ++-
 hw/ide/ide-bus.c     | 5 +++--
 hw/ide/isa.c         | 7 ++++---
 include/hw/ide/isa.h | 3 ++-
 4 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/hw/i386/isapc.c b/hw/i386/isapc.c
index 655ec599b5..c2a3f23f2c 100644
--- a/hw/i386/isapc.c
+++ b/hw/i386/isapc.c
@@ -142,7 +142,8 @@ static void pc_init_isa(MachineState *machine)
     for (i = 0; i < MAX_IDE_BUS; i++) {
         ISADevice *dev;
         char busname[] = "ide.0";
-        dev = isa_ide_init(isa_bus, ide_iobase[i], ide_iobase2[i],
+        dev = isa_ide_init(OBJECT(machine), isa_bus,
+                            ide_iobase[i], ide_iobase2[i],
                             ide_irq[i],
                             hd[MAX_IDE_DEVS * i], hd[MAX_IDE_DEVS * i + 1]);
         /*
diff --git a/hw/ide/ide-bus.c b/hw/ide/ide-bus.c
index 40ba94235f..4473709a04 100644
--- a/hw/ide/ide-bus.c
+++ b/hw/ide/ide-bus.c
@@ -75,11 +75,12 @@ IDEDevice *ide_bus_create_drive(IDEBus *bus, int unit, 
DriveInfo *drive)
 {
     DeviceState *dev;
 
-    dev = qdev_new_orphan(drive->media_cd ? "ide-cd" : "ide-hd");
+    dev = qdev_new(OBJECT(bus->qbus.parent), "drive[*]",
+                   drive->media_cd ? "ide-cd" : "ide-hd");
     qdev_prop_set_uint32(dev, "unit", unit);
     qdev_prop_set_drive_err(dev, "drive", blk_by_legacy_dinfo(drive),
                             &error_fatal);
-    qdev_realize_and_unref(dev, &bus->qbus, &error_fatal);
+    qdev_realize(dev, &bus->qbus, &error_fatal);
     return DO_UPCAST(IDEDevice, qdev, dev);
 }
 
diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index c9c997344b..37457be035 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -77,19 +77,20 @@ static void isa_ide_realizefn(DeviceState *dev, Error 
**errp)
     ide_bus_register_restart_cb(&s->bus);
 }
 
-ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int irqnum,
+ISADevice *isa_ide_init(Object *parent, ISABus *bus,
+                        int iobase, int iobase2, int irqnum,
                         DriveInfo *hd0, DriveInfo *hd1)
 {
     DeviceState *dev;
     ISADevice *isadev;
     ISAIDEState *s;
 
-    isadev = isa_new_orphan(TYPE_ISA_IDE);
+    isadev = isa_new(parent, "ide[*]", TYPE_ISA_IDE);
     dev = DEVICE(isadev);
     qdev_prop_set_uint32(dev, "iobase",  iobase);
     qdev_prop_set_uint32(dev, "iobase2", iobase2);
     qdev_prop_set_uint32(dev, "irq",     irqnum);
-    isa_realize_and_unref(isadev, bus, &error_fatal);
+    qdev_realize(dev, BUS(bus), &error_fatal);
 
     s = ISA_IDE(dev);
     if (hd0) {
diff --git a/include/hw/ide/isa.h b/include/hw/ide/isa.h
index 1cd0ff1fa6..18fe363a1a 100644
--- a/include/hw/ide/isa.h
+++ b/include/hw/ide/isa.h
@@ -14,7 +14,8 @@
 #define TYPE_ISA_IDE "isa-ide"
 OBJECT_DECLARE_SIMPLE_TYPE(ISAIDEState, ISA_IDE)
 
-ISADevice *isa_ide_init(ISABus *bus, int iobase, int iobase2, int irqnum,
+ISADevice *isa_ide_init(Object *parent, ISABus *bus,
+                        int iobase, int iobase2, int irqnum,
                         DriveInfo *hd0, DriveInfo *hd1);
 
 #endif
-- 
2.47.1


Reply via email to