[Skiboot] [PATCH v2 1/2] core/device: Function to return child node using name
Neelesh Gupta
neelegup at linux.vnet.ibm.com
Tue Jan 13 16:46:11 AEDT 2015
Add a function dt_find_by_name() that returns the child node if
matches the given name, otherwise NULL.
Signed-off-by: Neelesh Gupta <neelegup at linux.vnet.ibm.com>
---
core/device.c | 16 ++++++++++++++++
include/device.h | 3 +++
2 files changed, 19 insertions(+)
diff --git a/core/device.c b/core/device.c
index 51ddbdb..09f76d7 100644
--- a/core/device.c
+++ b/core/device.c
@@ -250,6 +250,22 @@ struct dt_node *dt_find_by_path(struct dt_node *root, const char *path)
return root;
}
+struct dt_node *dt_find_by_name(struct dt_node *root, const char *name)
+{
+ struct dt_node *child, *match;
+
+ list_for_each(&root->children, child, list) {
+ if (!strcmp(child->name, name))
+ return child;
+
+ match = dt_find_by_name(child, name);
+ if (match)
+ return match;
+ }
+
+ return NULL;
+}
+
struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle)
{
struct dt_node *node;
diff --git a/include/device.h b/include/device.h
index 16c26bb..b301958 100644
--- a/include/device.h
+++ b/include/device.h
@@ -167,6 +167,9 @@ char *dt_get_path(const struct dt_node *node);
/* Find a node by path */
struct dt_node *dt_find_by_path(struct dt_node *root, const char *path);
+/* Find a child node by name */
+struct dt_node *dt_find_by_name(struct dt_node *root, const char *name);
+
/* Find a node by phandle */
struct dt_node *dt_find_by_phandle(struct dt_node *root, u32 phandle);
More information about the Skiboot
mailing list