dm: core: Add device_foreach_child()
authorSimon Glass <sjg@chromium.org>
Wed, 25 Sep 2019 14:55:56 +0000 (08:55 -0600)
committerBin Meng <bmeng.cn@gmail.com>
Tue, 8 Oct 2019 05:57:39 +0000 (13:57 +0800)
We have a 'safe' version of this function but sometimes it is not needed.
Add a normal version too and update a few places that can use it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
arch/arm/mach-uniphier/pinctrl-glue.c
drivers/block/blk-uclass.c
include/dm/device.h

index c4d3b17c39d8457817ea514acc6552bbca1f41c3..b45f72f59a77862b8256f4bd19d6d2db77694d5a 100644 (file)
 
 int uniphier_pin_init(const char *pinconfig_name)
 {
-       struct udevice *pctldev, *config, *next;
+       struct udevice *pctldev, *config;
        int ret;
 
        ret = uclass_first_device(UCLASS_PINCTRL, &pctldev);
        if (ret)
                return ret;
 
-       device_foreach_child_safe(config, next, pctldev) {
+       device_foreach_child(config, pctldev) {
                if (strcmp(config->name, pinconfig_name))
                        continue;
 
index baaf431e5e0c3ce64af9b934fa140af496e0b2b5..e8f58b3f5e471b815c619a0a091fab87d5e7d762 100644 (file)
@@ -142,9 +142,9 @@ struct blk_desc *blk_get_devnum_by_typename(const char *if_typename, int devnum)
  */
 struct blk_desc *blk_get_by_device(struct udevice *dev)
 {
-       struct udevice *child_dev, *next;
+       struct udevice *child_dev;
 
-       device_foreach_child_safe(child_dev, next, dev) {
+       device_foreach_child(child_dev, dev) {
                if (device_get_uclass_id(child_dev) != UCLASS_BLK)
                        continue;
 
index 27a6d7b9fdb0da75049a285bb14fb562fca710c3..d1210429e9230788afe4c59af7d418b2f6d21352 100644 (file)
@@ -679,6 +679,15 @@ static inline bool device_is_on_pci_bus(struct udevice *dev)
 #define device_foreach_child_safe(pos, next, parent)   \
        list_for_each_entry_safe(pos, next, &parent->child_head, sibling_node)
 
+/**
+ * device_foreach_child() - iterate through child devices
+ *
+ * @pos: struct udevice * for the current device
+ * @parent: parent device to scan
+ */
+#define device_foreach_child(pos, parent)      \
+       list_for_each_entry(pos, &parent->child_head, sibling_node)
+
 /**
  * dm_scan_fdt_dev() - Bind child device in a the device tree
  *