Convert the *_orphan() device-creation calls in hw/display 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/display/sii9022.c:167 | i2c_slave_create_simple | OBJECT(dev) | "ddc" | DeviceClass.realize(); DDC slave owned by sii9022 device hw/display/sm501.c:1913 | qdev_new | OBJECT(dev) | "ddc" | sm501_init() helper receives realizing DeviceState *dev; drop _and_unref hw/display/xlnx_dp.c:1349 | qdev_new | obj | "dpcd" | instance_init(Object *obj); collapse existing add_child+unref, keep name hw/display/xlnx_dp.c:1353 | qdev_new | obj | "edid" | instance_init(Object *obj); collapse existing add_child+unref, keep name Link: https://lore.kernel.org/qemu-devel/[email protected]/ Reviewed-by: Philippe Mathieu-Daudé <[email protected]> AI-used-for: code (refactoring) Signed-off-by: Alexander Graf <[email protected]> --- hw/display/sii9022.c | 2 +- hw/display/sm501.c | 4 ++-- hw/display/xlnx_dp.c | 14 +++----------- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/hw/display/sii9022.c b/hw/display/sii9022.c index 0bf49195d7..2accebf193 100644 --- a/hw/display/sii9022.c +++ b/hw/display/sii9022.c @@ -164,7 +164,7 @@ static void sii9022_realize(DeviceState *dev, Error **errp) I2CBus *bus; bus = I2C_BUS(qdev_get_parent_bus(dev)); - i2c_slave_create_simple_orphan(bus, TYPE_I2CDDC, 0x50); + i2c_slave_create_simple(OBJECT(dev), "ddc", bus, TYPE_I2CDDC, 0x50); } static void sii9022_class_init(ObjectClass *klass, const void *data) diff --git a/hw/display/sm501.c b/hw/display/sm501.c index 1e47e6a32b..56075a0303 100644 --- a/hw/display/sm501.c +++ b/hw/display/sm501.c @@ -1956,9 +1956,9 @@ static void sm501_init(SM501State *s, DeviceState *dev, /* i2c */ s->i2c_bus = i2c_init_bus(dev, "sm501.i2c"); /* ddc */ - I2CDDCState *ddc = I2CDDC(qdev_new_orphan(TYPE_I2CDDC)); + I2CDDCState *ddc = I2CDDC(qdev_new(OBJECT(dev), "ddc", TYPE_I2CDDC)); i2c_slave_set_address(I2C_SLAVE(ddc), 0x50); - qdev_realize_and_unref(DEVICE(ddc), BUS(s->i2c_bus), &error_abort); + qdev_realize(DEVICE(ddc), BUS(s->i2c_bus), &error_abort); /* mmio */ memory_region_init(&s->mmio_region, OBJECT(dev), "sm501.mmio", MMIO_SIZE); diff --git a/hw/display/xlnx_dp.c b/hw/display/xlnx_dp.c index e8490d644d..5968466e79 100644 --- a/hw/display/xlnx_dp.c +++ b/hw/display/xlnx_dp.c @@ -1341,19 +1341,11 @@ static void xlnx_dp_init(Object *obj) */ s->aux_bus = aux_bus_init(DEVICE(obj), "aux"); - /* - * Initialize DPCD and EDID. Once we have added the objects as - * child properties of this device, we can drop the reference we - * hold to them, leaving the child-property as the only reference. - */ - s->dpcd = DPCD(qdev_new_orphan("dpcd")); - object_property_add_child(OBJECT(s), "dpcd", OBJECT(s->dpcd)); - object_unref(s->dpcd); + /* Initialize DPCD and EDID. */ + s->dpcd = DPCD(qdev_new(obj, "dpcd", "dpcd")); - s->edid = I2CDDC(qdev_new_orphan("i2c-ddc")); + s->edid = I2CDDC(qdev_new(obj, "edid", "i2c-ddc")); i2c_slave_set_address(I2C_SLAVE(s->edid), 0x50); - object_property_add_child(OBJECT(s), "edid", OBJECT(s->edid)); - object_unref(s->edid); fifo8_create(&s->rx_fifo, 16); fifo8_create(&s->tx_fifo, 16); -- 2.47.1
