summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Xiwen <forbidden405@outlook.com>2026-01-20 03:07:18 +0800
committerTom Rini <trini@konsulko.com>2026-02-02 13:40:41 -0600
commitd7aea17d2e606249c2a3e8495f70bb4e47e11ed8 (patch)
tree3c0d75f38d759c312d91bfb7cdb27221eaf6c432
parent6b2d05748cf3cd6ba417a96c00602b0122e10af6 (diff)
drivers: core: device: set new parent when old parent is NULL
The current logic does not update the new parent in device_reparent() if old parent is NULL. The behavior is not desired. Fix it by setting the parent in this case. Fixes: cfecbaf4e768 ("dm: core: add support for device re-parenting") Signed-off-by: Yang Xiwen <forbidden405@outlook.com>
-rw-r--r--drivers/core/device.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 779f371b9d5..0ae09f5a4e3 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -285,6 +285,14 @@ int device_reparent(struct udevice *dev, struct udevice *new_parent)
assert(dev);
assert(new_parent);
+ if (!dev->parent) {
+ assert(list_empty(&dev->sibling_node));
+
+ list_add_tail(&dev->sibling_node, &new_parent->child_head);
+ dev->parent = new_parent;
+ return 0;
+ }
+
device_foreach_child_safe(pos, n, dev->parent) {
if (pos->driver != dev->driver)
continue;