dm: core: Use device_foreach_child where possible

We have some nice macros for iterating over devices in device.h, but they
are not used by the driver core. Convert all the users I could find.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
This commit is contained in:
Sean Anderson 2022-03-30 12:26:40 -04:00 committed by Simon Glass
parent 8b52f237f0
commit 501a9a7ed8
4 changed files with 14 additions and 15 deletions

View file

@ -29,7 +29,7 @@ int device_chld_unbind(struct udevice *dev, struct driver *drv)
assert(dev); assert(dev);
list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { device_foreach_child_safe(pos, n, dev) {
if (drv && (pos->driver != drv)) if (drv && (pos->driver != drv))
continue; continue;
@ -52,7 +52,7 @@ int device_chld_remove(struct udevice *dev, struct driver *drv,
assert(dev); assert(dev);
list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { device_foreach_child_safe(pos, n, dev) {
int ret; int ret;
if (drv && (pos->driver != drv)) if (drv && (pos->driver != drv))

View file

@ -284,8 +284,7 @@ int device_reparent(struct udevice *dev, struct udevice *new_parent)
assert(dev); assert(dev);
assert(new_parent); assert(new_parent);
list_for_each_entry_safe(pos, n, &dev->parent->child_head, device_foreach_child_safe(pos, n, dev->parent) {
sibling_node) {
if (pos->driver != dev->driver) if (pos->driver != dev->driver)
continue; continue;
@ -724,7 +723,7 @@ int device_get_child(const struct udevice *parent, int index,
{ {
struct udevice *dev; struct udevice *dev;
list_for_each_entry(dev, &parent->child_head, sibling_node) { device_foreach_child(dev, parent) {
if (!index--) if (!index--)
return device_get_device_tail(dev, 0, devp); return device_get_device_tail(dev, 0, devp);
} }
@ -737,7 +736,7 @@ int device_get_child_count(const struct udevice *parent)
struct udevice *dev; struct udevice *dev;
int count = 0; int count = 0;
list_for_each_entry(dev, &parent->child_head, sibling_node) device_foreach_child(dev, parent)
count++; count++;
return count; return count;
@ -748,7 +747,7 @@ int device_get_decendent_count(const struct udevice *parent)
const struct udevice *dev; const struct udevice *dev;
int count = 1; int count = 1;
list_for_each_entry(dev, &parent->child_head, sibling_node) device_foreach_child(dev, parent)
count += device_get_decendent_count(dev); count += device_get_decendent_count(dev);
return count; return count;
@ -761,7 +760,7 @@ int device_find_child_by_seq(const struct udevice *parent, int seq,
*devp = NULL; *devp = NULL;
list_for_each_entry(dev, &parent->child_head, sibling_node) { device_foreach_child(dev, parent) {
if (dev->seq_ == seq) { if (dev->seq_ == seq) {
*devp = dev; *devp = dev;
return 0; return 0;
@ -790,7 +789,7 @@ int device_find_child_by_of_offset(const struct udevice *parent, int of_offset,
*devp = NULL; *devp = NULL;
list_for_each_entry(dev, &parent->child_head, sibling_node) { device_foreach_child(dev, parent) {
if (dev_of_offset(dev) == of_offset) { if (dev_of_offset(dev) == of_offset) {
*devp = dev; *devp = dev;
return 0; return 0;
@ -819,7 +818,7 @@ static struct udevice *_device_find_global_by_ofnode(struct udevice *parent,
if (ofnode_equal(dev_ofnode(parent), ofnode)) if (ofnode_equal(dev_ofnode(parent), ofnode))
return parent; return parent;
list_for_each_entry(dev, &parent->child_head, sibling_node) { device_foreach_child(dev, parent) {
found = _device_find_global_by_ofnode(dev, ofnode); found = _device_find_global_by_ofnode(dev, ofnode);
if (found) if (found)
return found; return found;
@ -897,7 +896,7 @@ int device_find_first_inactive_child(const struct udevice *parent,
struct udevice *dev; struct udevice *dev;
*devp = NULL; *devp = NULL;
list_for_each_entry(dev, &parent->child_head, sibling_node) { device_foreach_child(dev, parent) {
if (!device_active(dev) && if (!device_active(dev) &&
device_get_uclass_id(dev) == uclass_id) { device_get_uclass_id(dev) == uclass_id) {
*devp = dev; *devp = dev;
@ -915,7 +914,7 @@ int device_find_first_child_by_uclass(const struct udevice *parent,
struct udevice *dev; struct udevice *dev;
*devp = NULL; *devp = NULL;
list_for_each_entry(dev, &parent->child_head, sibling_node) { device_foreach_child(dev, parent) {
if (device_get_uclass_id(dev) == uclass_id) { if (device_get_uclass_id(dev) == uclass_id) {
*devp = dev; *devp = dev;
return 0; return 0;
@ -932,7 +931,7 @@ int device_find_child_by_namelen(const struct udevice *parent, const char *name,
*devp = NULL; *devp = NULL;
list_for_each_entry(dev, &parent->child_head, sibling_node) { device_foreach_child(dev, parent) {
if (!strncmp(dev->name, name, len) && if (!strncmp(dev->name, name, len) &&
strlen(dev->name) == len) { strlen(dev->name) == len) {
*devp = dev; *devp = dev;

View file

@ -232,7 +232,7 @@ static void dump_resources(struct udevice *dev, int depth)
(unsigned long)dr->size, dr->name, (unsigned long)dr->size, dr->name,
devres_phase_name[dr->phase]); devres_phase_name[dr->phase]);
list_for_each_entry(child, &dev->child_head, sibling_node) device_foreach_child(child, dev)
dump_resources(child, depth + 1); dump_resources(child, depth + 1);
} }

View file

@ -39,7 +39,7 @@ static void show_devices(struct udevice *dev, int depth, int last_flag)
printf("%s\n", dev->name); printf("%s\n", dev->name);
list_for_each_entry(child, &dev->child_head, sibling_node) { device_foreach_child(child, dev) {
is_last = list_is_last(&child->sibling_node, &dev->child_head); is_last = list_is_last(&child->sibling_node, &dev->child_head);
show_devices(child, depth + 1, (last_flag << 1) | is_last); show_devices(child, depth + 1, (last_flag << 1) | is_last);
} }