Commit 07d260e0 authored by Simon Glass's avatar Simon Glass
Browse files

dm: core: Handle recursive unbinding of uclass devices

Since a device can have children in the same uclass as itself, we need
to handle unbinding carefully: we must allow that unbinding a device in a
uclass may cause another device in the same uclass to be unbound.

Adjust the code to cope.
Signed-off-by: default avatarSimon Glass <>
Reviewed-by: default avatarJoe Hershberger <>
Tested-by: default avatarJoe Hershberger <>
parent a7b82502
......@@ -99,10 +99,18 @@ fail_mem:
int uclass_destroy(struct uclass *uc)
struct uclass_driver *uc_drv;
struct udevice *dev, *tmp;
struct udevice *dev;
int ret;
list_for_each_entry_safe(dev, tmp, &uc->dev_head, uclass_node) {
* We cannot use list_for_each_entry_safe() here. If a device in this
* uclass has a child device also in this uclass, it will be also be
* unbound (by the recursion in the call to device_unbind() below).
* We can loop until the list is empty.
while (!list_empty(&uc->dev_head)) {
dev = list_first_entry(&uc->dev_head, struct udevice,
ret = device_remove(dev);
if (ret)
return ret;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment