summaryrefslogtreecommitdiff
path: root/drivers/of
diff options
context:
space:
mode:
authorBiju Das <biju.das.jz@bp.renesas.com>2025-02-05 12:42:21 +0000
committerDavid S. Miller <davem@davemloft.net>2025-02-07 13:43:55 +0000
commit8d3bbe4355aded32961b9009b31de6d41b7352e9 (patch)
tree5e04b5696513355c73430f293c9fa0a2edbcda26 /drivers/of
parent26db4dbb747813b5946aff31485873f071a10332 (diff)
downloadlinux-8d3bbe4355aded32961b9009b31de6d41b7352e9.tar.gz
linux-8d3bbe4355aded32961b9009b31de6d41b7352e9.tar.bz2
linux-8d3bbe4355aded32961b9009b31de6d41b7352e9.zip
of: base: Add of_get_available_child_by_name()
There are lot of drivers using of_get_child_by_name() followed by of_device_is_available() to find the available child node by name for a given parent. Provide a helper for these users to simplify the code. Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/of')
-rw-r--r--drivers/of/base.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c
index af6c68bbb427..e37b088f1fad 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -824,6 +824,33 @@ struct device_node *of_get_child_by_name(const struct device_node *node,
}
EXPORT_SYMBOL(of_get_child_by_name);
+/**
+ * of_get_available_child_by_name - Find the available child node by name for a given parent
+ * @node: parent node
+ * @name: child name to look for.
+ *
+ * This function looks for child node for given matching name and checks the
+ * device's availability for use.
+ *
+ * Return: A node pointer if found, with refcount incremented, use
+ * of_node_put() on it when done.
+ * Returns NULL if node is not found.
+ */
+struct device_node *of_get_available_child_by_name(const struct device_node *node,
+ const char *name)
+{
+ struct device_node *child;
+
+ child = of_get_child_by_name(node, name);
+ if (child && !of_device_is_available(child)) {
+ of_node_put(child);
+ return NULL;
+ }
+
+ return child;
+}
+EXPORT_SYMBOL(of_get_available_child_by_name);
+
struct device_node *__of_find_node_by_path(const struct device_node *parent,
const char *path)
{