of: Add of_get_next_status_child() and makes more generic of_get_next
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Wed, 10 Jan 2024 01:14:43 +0000 (01:14 +0000)
committerGeert Uytterhoeven <geert+renesas@glider.be>
Tue, 23 Jan 2024 08:38:23 +0000 (09:38 +0100)
Linux Kernel has of_get_next_available_child().
Add more generic of_get_next_status_child() to enable to use same
logic for other status.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Tested-by: Yusuke Goda <yusuke.goda.sx@renesas.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/87bk9ugfb0.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
drivers/of/base.c

index afb54bf5c887acdcd9f9786f0defa62b7f1c46fa..ae26a15390f74f5ccf2212c6a54142cc065ca8e4 100644 (file)
@@ -612,16 +612,9 @@ struct device_node *of_get_next_child(const struct device_node *node,
 }
 EXPORT_SYMBOL(of_get_next_child);
 
-/**
- * of_get_next_available_child - Find the next available child node
- * @node:      parent node
- * @prev:      previous child of the parent node, or NULL to get first
- *
- * This function is like of_get_next_child(), except that it
- * automatically skips any disabled nodes (i.e. status = "disabled").
- */
-struct device_node *of_get_next_available_child(const struct device_node *node,
-       struct device_node *prev)
+static struct device_node *of_get_next_status_child(const struct device_node *node,
+                                                   struct device_node *prev,
+                                                   bool (*checker)(const struct device_node *))
 {
        struct device_node *next;
        unsigned long flags;
@@ -632,7 +625,7 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
        raw_spin_lock_irqsave(&devtree_lock, flags);
        next = prev ? prev->sibling : node->child;
        for (; next; next = next->sibling) {
-               if (!__of_device_is_available(next))
+               if (!checker(next))
                        continue;
                if (of_node_get(next))
                        break;
@@ -641,6 +634,20 @@ struct device_node *of_get_next_available_child(const struct device_node *node,
        raw_spin_unlock_irqrestore(&devtree_lock, flags);
        return next;
 }
+
+/**
+ * of_get_next_available_child - Find the next available child node
+ * @node:      parent node
+ * @prev:      previous child of the parent node, or NULL to get first
+ *
+ * This function is like of_get_next_child(), except that it
+ * automatically skips any disabled nodes (i.e. status = "disabled").
+ */
+struct device_node *of_get_next_available_child(const struct device_node *node,
+       struct device_node *prev)
+{
+       return of_get_next_status_child(node, prev, __of_device_is_available);
+}
 EXPORT_SYMBOL(of_get_next_available_child);
 
 /**