All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] hw/core: Avoid attaching qdevs to /machine/unattached if they have a bus
@ 2026-02-17 16:40 Thomas Huth
  2026-02-19  8:49 ` Markus Armbruster
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Huth @ 2026-02-17 16:40 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini
  Cc: Daniel P. Berrangé, Eduardo Habkost, Markus Armbruster

From: Thomas Huth <thuth@redhat.com>

We still have a lot of devices that end up in /machine/unattached in
case the caller forgot to use object_property_add_child() to add it
to a proper location in the QOM tree. But at least for the devices
that get realized via qdev_realize() and that have a bus specified,
we can do better: Add the device automatically as a child to the bus
device instead! This way the QOM tree looks way more logical, with
way less devices hanging around in the /machine/unattached space.

While we're at it, use the type name as node name (instead of using
"device" like we did in the "unattached" space). But since these
entries might not be stable (they use a counting number in the square
brackets), the code also uses a "x-" prefix here to indicate that
this still might change in the course of time (once a board decides
to manually attach the device with a proper name instead).

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 hw/core/qdev.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 42641c5224e..5b773d0108a 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -266,9 +266,19 @@ bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp)
     assert(!dev->realized && !dev->parent_bus);
 
     if (bus) {
+        Object *obj = OBJECT(dev);
+
         if (!qdev_set_parent_bus(dev, bus, errp)) {
             return false;
         }
+
+        if (!obj->parent) {
+            static int count;
+            g_autofree char *name = g_strdup_printf("x-%s[%d]",
+                                                    object_get_typename(obj),
+                                                    count++);
+            object_property_add_child(OBJECT(bus), name, obj);
+        }
     } else {
         assert(!DEVICE_GET_CLASS(dev)->bus_type);
     }
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-03-08 17:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-17 16:40 [RFC PATCH] hw/core: Avoid attaching qdevs to /machine/unattached if they have a bus Thomas Huth
2026-02-19  8:49 ` Markus Armbruster
2026-02-24  9:47   ` Daniel P. Berrangé
2026-02-24 11:10     ` Peter Maydell
2026-02-24 12:22       ` Mark Cave-Ayland
2026-02-25  1:05         ` BALATON Zoltan
2026-02-26 11:58           ` Peter Maydell
2026-02-26 22:57             ` BALATON Zoltan
2026-03-08 17:56             ` Bernhard Beschow
2026-02-25  5:55         ` Philippe Mathieu-Daudé
2026-02-26 22:03           ` Bernhard Beschow
2026-02-24 11:43     ` Markus Armbruster

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.