[RFC PATCH v2 041/137] hw/core/sysbus: Skip nested devices in foreach_dynamic_sysbus_device()
Alexander Graf <[email protected]>
| Newsgroups | org.nongnu.qemu-arm,org.nongnu.qemu-devel,org.nongnu.qemu-riscv |
|---|---|
| Message-ID | <[email protected]> |
find_sysbus_device() recurses into any non-sysbus child of
/machine/peripheral{,-anon} on the assumption that only pure
containers appear there. Once user-created devices start
QOM-parenting their internal helper sysbus devices under themselves
(next patch, and the general direction of this series), those
helpers become visible to foreach_dynamic_sysbus_device() and are
mis-treated as user-requested dynamic sysbus devices -- sysbus-fdt
aborts on the first one it has no binding for.
Skip recursion into any non-sysbus TYPE_DEVICE: internal helper
devices are board-managed and never candidates for platform-bus
placement or FDT node generation. No in-tree caller currently
relies on recursion through TYPE_DEVICE: user -device sysbus
devices are direct children of the peripheral container.
AI-used-for: code (refactoring)
Signed-off-by: Alexander Graf <[email protected]>
---
hw/core/sysbus.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c
index bbacb07e1a..85f56b68fb 100644
--- a/hw/core/sysbus.c
+++ b/hw/core/sysbus.c
@@ -42,7 +42,15 @@ static int find_sysbus_device(Object *obj, void *opaque)
sbdev = (SysBusDevice *)dev;
if (!sbdev) {
- /* Container, traverse it for children */
+ /*
+ * Only recurse into pure containers. A user-created -device
+ * may internally instantiate helper sysbus children under
+ * itself; those are board-managed and must not be treated
+ * as dynamic sysbus devices.
+ */
+ if (object_dynamic_cast(obj, TYPE_DEVICE)) {
+ return 0;
+ }
return object_child_foreach(obj, find_sysbus_device, opaque);
}
--
2.47.1