Convert the *_orphan() device-creation calls in hw/pci 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/pci/pci.c:2121 | pci_new_orphan | ORPHAN-JUSTIFIED | - | 
pci_init_nic_in_slot() is a public helper called from board init in 
hw/{riscv,sh4,ppc,mips}; parenting requires threading Object* through 
include/hw/pci/pci.h and 5 callers; deferred to caller-side patches
hw/pci/pci.c:2132 | pci_create_simple_orphan | ORPHAN-JUSTIFIED | - | 
pci_vga_init() is a public helper called from board init in 
hw/{i386,ppc,mips,alpha}; parenting requires threading Object* through 
include/hw/pci/pci.h and 11 callers; deferred to caller-side patches
hw/pci/pci.c:2134 | pci_create_simple_orphan | ORPHAN-JUSTIFIED | - | 
pci_vga_init() public helper; deferred (see :2132)
hw/pci/pci.c:2136 | pci_create_simple_orphan | ORPHAN-JUSTIFIED | - | 
pci_vga_init() public helper; deferred (see :2132)
hw/pci/pci.c:2138 | pci_create_simple_orphan | ORPHAN-JUSTIFIED | - | 
pci_vga_init() public helper; deferred (see :2132)
hw/pci/pci.c:2140 | pci_create_simple_orphan | ORPHAN-JUSTIFIED | - | 
pci_vga_init() public helper; deferred (see :2132)
hw/pci/pci.c:2396 | qdev_new_orphan | ORPHAN-JUSTIFIED | - | pci_new_internal() 
is the implementation body of pci_new*_orphan() transitional API
hw/pci/pci.c:2443 | pci_new_multifunction_orphan | ORPHAN-JUSTIFIED | - | API 
definition (transitional _orphan wrapper)
hw/pci/pci.c:2448 | pci_new_orphan | ORPHAN-JUSTIFIED | - | API definition 
(transitional _orphan wrapper)
hw/pci/pci.c:2458 | pci_create_simple_multifunction_orphan | ORPHAN-JUSTIFIED | 
- | API definition (transitional _orphan wrapper)
hw/pci/pci.c:2461 | pci_new_multifunction_orphan | ORPHAN-JUSTIFIED | - | API 
definition body of pci_create_simple_multifunction_orphan()
hw/pci/pci.c:2466 | pci_create_simple_orphan | ORPHAN-JUSTIFIED | - | API 
definition (transitional _orphan wrapper)
hw/pci/pci.c:2468 | pci_new_orphan | ORPHAN-JUSTIFIED | - | API definition body 
of pci_create_simple_orphan()
hw/pci/pcie_sriov.c:174 | pci_new | OBJECT(dev) | "vf[*]" | 
pcie_sriov_pf_init(): VFs are children of the PF PCIDevice; already uses 
qdev_realize(); drop extra object_unref() on error path since parent child<> 
holds the only ref

Link: https://lore.kernel.org/qemu-devel/[email protected]/
Assisted-by: Kiro
Signed-off-by: Alexander Graf <[email protected]>
---
 hw/pci/pcie_sriov.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/pci/pcie_sriov.c b/hw/pci/pcie_sriov.c
index a69a41cdde..eb1707bb41 100644
--- a/hw/pci/pcie_sriov.c
+++ b/hw/pci/pcie_sriov.c
@@ -171,13 +171,12 @@ bool pcie_sriov_pf_init(PCIDevice *dev, uint16_t offset,
     dev->exp.sriov_pf.vf = g_new(PCIDevice *, total_vfs);
 
     for (uint16_t i = 0; i < total_vfs; i++) {
-        PCIDevice *vf = pci_new_orphan(devfn, vfname);
+        PCIDevice *vf = pci_new(OBJECT(dev), "vf[*]", devfn, vfname);
         vf->exp.sriov_vf.pf = dev;
         vf->exp.sriov_vf.vf_number = i;
 
         if (!qdev_realize(&vf->qdev, bus, errp)) {
             object_unparent(OBJECT(vf));
-            object_unref(vf);
             unparent_vfs(dev, i);
             return false;
         }
-- 
2.47.1


Reply via email to