diff mbox series

dm: core: Use device_foreach_child where possible

Message ID 20220330162640.428724-1-seanga2@gmail.com
State Accepted
Commit 501a9a7ed803ac948adb392e541f9da9bafad60e
Delegated to: Simon Glass
Headers show
Series dm: core: Use device_foreach_child where possible | expand

Commit Message

Sean Anderson March 30, 2022, 4:26 p.m. UTC
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>
---

 drivers/core/device-remove.c |  4 ++--
 drivers/core/device.c        | 21 ++++++++++-----------
 drivers/core/devres.c        |  2 +-
 drivers/core/dump.c          |  2 +-
 4 files changed, 14 insertions(+), 15 deletions(-)

Comments

Simon Glass June 28, 2022, 1:38 p.m. UTC | #1
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>
---

 drivers/core/device-remove.c |  4 ++--
 drivers/core/device.c        | 21 ++++++++++-----------
 drivers/core/devres.c        |  2 +-
 drivers/core/dump.c          |  2 +-
 4 files changed, 14 insertions(+), 15 deletions(-)

Applied to u-boot-dm, thanks!
diff mbox series

Patch

diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 73d2e9e420..a86b9325dd 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -29,7 +29,7 @@  int device_chld_unbind(struct udevice *dev, struct driver *drv)
 
 	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))
 			continue;
 
@@ -52,7 +52,7 @@  int device_chld_remove(struct udevice *dev, struct driver *drv,
 
 	assert(dev);
 
-	list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) {
+	device_foreach_child_safe(pos, n, dev) {
 		int ret;
 
 		if (drv && (pos->driver != drv))
diff --git a/drivers/core/device.c b/drivers/core/device.c
index 1b356f12dd..a7bfc47191 100644
--- a/drivers/core/device.c
+++ b/drivers/core/device.c
@@ -284,8 +284,7 @@  int device_reparent(struct udevice *dev, struct udevice *new_parent)
 	assert(dev);
 	assert(new_parent);
 
-	list_for_each_entry_safe(pos, n, &dev->parent->child_head,
-				 sibling_node) {
+	device_foreach_child_safe(pos, n, dev->parent) {
 		if (pos->driver != dev->driver)
 			continue;
 
@@ -729,7 +728,7 @@  int device_get_child(const struct udevice *parent, int index,
 {
 	struct udevice *dev;
 
-	list_for_each_entry(dev, &parent->child_head, sibling_node) {
+	device_foreach_child(dev, parent) {
 		if (!index--)
 			return device_get_device_tail(dev, 0, devp);
 	}
@@ -742,7 +741,7 @@  int device_get_child_count(const struct udevice *parent)
 	struct udevice *dev;
 	int count = 0;
 
-	list_for_each_entry(dev, &parent->child_head, sibling_node)
+	device_foreach_child(dev, parent)
 		count++;
 
 	return count;
@@ -753,7 +752,7 @@  int device_get_decendent_count(const struct udevice *parent)
 	const struct udevice *dev;
 	int count = 1;
 
-	list_for_each_entry(dev, &parent->child_head, sibling_node)
+	device_foreach_child(dev, parent)
 		count += device_get_decendent_count(dev);
 
 	return count;
@@ -766,7 +765,7 @@  int device_find_child_by_seq(const struct udevice *parent, int seq,
 
 	*devp = NULL;
 
-	list_for_each_entry(dev, &parent->child_head, sibling_node) {
+	device_foreach_child(dev, parent) {
 		if (dev->seq_ == seq) {
 			*devp = dev;
 			return 0;
@@ -795,7 +794,7 @@  int device_find_child_by_of_offset(const struct udevice *parent, int of_offset,
 
 	*devp = NULL;
 
-	list_for_each_entry(dev, &parent->child_head, sibling_node) {
+	device_foreach_child(dev, parent) {
 		if (dev_of_offset(dev) == of_offset) {
 			*devp = dev;
 			return 0;
@@ -824,7 +823,7 @@  static struct udevice *_device_find_global_by_ofnode(struct udevice *parent,
 	if (ofnode_equal(dev_ofnode(parent), ofnode))
 		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);
 		if (found)
 			return found;
@@ -902,7 +901,7 @@  int device_find_first_inactive_child(const struct udevice *parent,
 	struct udevice *dev;
 
 	*devp = NULL;
-	list_for_each_entry(dev, &parent->child_head, sibling_node) {
+	device_foreach_child(dev, parent) {
 		if (!device_active(dev) &&
 		    device_get_uclass_id(dev) == uclass_id) {
 			*devp = dev;
@@ -920,7 +919,7 @@  int device_find_first_child_by_uclass(const struct udevice *parent,
 	struct udevice *dev;
 
 	*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) {
 			*devp = dev;
 			return 0;
@@ -937,7 +936,7 @@  int device_find_child_by_namelen(const struct udevice *parent, const char *name,
 
 	*devp = NULL;
 
-	list_for_each_entry(dev, &parent->child_head, sibling_node) {
+	device_foreach_child(dev, parent) {
 		if (!strncmp(dev->name, name, len) &&
 		    strlen(dev->name) == len) {
 			*devp = dev;
diff --git a/drivers/core/devres.c b/drivers/core/devres.c
index 313ddc7089..78914bdf7f 100644
--- a/drivers/core/devres.c
+++ b/drivers/core/devres.c
@@ -232,7 +232,7 @@  static void dump_resources(struct udevice *dev, int depth)
 		       (unsigned long)dr->size, dr->name,
 		       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);
 }
 
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index f2f9cacc56..fe97dca954 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -39,7 +39,7 @@  static void show_devices(struct udevice *dev, int depth, int last_flag)
 
 	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);
 		show_devices(child, depth + 1, (last_flag << 1) | is_last);
 	}