pcspk was created in pc_machine_initfn() as an orphan and manually unref'd in pc_machine_finalize() when the machine was never realized (e.g. -M pc,help). Making it a child<> of the machine at creation time lets the QOM property teardown in object_property_del_all() handle that lifecycle for free, so pc_machine_finalize() and its open-coded refcount juggling can go.
The realize path switches from isa_realize_and_unref() to plain qdev_realize() because the reference is now held by the parent's child<> property, not the caller. Assisted-by: Kiro Signed-off-by: Alexander Graf <[email protected]> --- hw/i386/pc.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 0c89310ab7..a00d53b582 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1128,7 +1128,7 @@ void pc_basic_device_init(struct PCMachineState *pcms, } object_property_set_link(OBJECT(pcms->pcspk), "pit", OBJECT(pit), &error_fatal); - isa_realize_and_unref(pcms->pcspk, isa_bus, &error_fatal); + qdev_realize(DEVICE(pcms->pcspk), BUS(isa_bus), &error_fatal); } if (pcms->vmport == ON_OFF_AUTO_AUTO) { @@ -1640,7 +1640,7 @@ static void pc_machine_initfn(Object *obj) pcms->default_bus_bypass_iommu = false; pc_system_flash_create(pcms); - pcms->pcspk = isa_new_orphan(TYPE_PC_SPEAKER); + pcms->pcspk = isa_new(obj, "pcspk", TYPE_PC_SPEAKER); object_property_add_alias(OBJECT(pcms), "pcspk-audiodev", OBJECT(pcms->pcspk), "audiodev"); if (pcmc->pci_enabled) { @@ -1648,15 +1648,6 @@ static void pc_machine_initfn(Object *obj) } } -static void pc_machine_finalize(Object *obj) -{ - PCMachineState *pcms = PC_MACHINE(obj); - - if (pcms->pcspk && !qdev_is_realized(DEVICE(pcms->pcspk))) { - object_unref(OBJECT(pcms->pcspk)); - } -} - static void pc_machine_reset(MachineState *machine, ResetType type) { CPUState *cs; @@ -1795,7 +1786,6 @@ static const TypeInfo pc_machine_info = { .abstract = true, .instance_size = sizeof(PCMachineState), .instance_init = pc_machine_initfn, - .instance_finalize = pc_machine_finalize, .class_size = sizeof(PCMachineClass), .class_init = pc_machine_class_init, .interfaces = (const InterfaceInfo[]) { -- 2.47.1
