[PATCH 13/18] Add ft_find_prop().

Scott Wood scottwood at freescale.com
Thu Jan 25 08:07:24 EST 2007


ft_find_prop() finds nodes with the specified property/value pair.

Signed-off-by: Scott Wood <scottwood at freescale.com>
---
 arch/powerpc/boot/flatdevtree.c |   68 +++++++++++++++++++++++++++++++++++++++
 arch/powerpc/boot/flatdevtree.h |    4 ++
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/boot/flatdevtree.c b/arch/powerpc/boot/flatdevtree.c
index 87e6636..0cd3f64 100644
--- a/arch/powerpc/boot/flatdevtree.c
+++ b/arch/powerpc/boot/flatdevtree.c
@@ -819,6 +819,74 @@ int ft_get_prop(struct ft_cxt *cxt, cons
 	return -1;
 }
 
+void *__ft_find_prop(struct ft_cxt *cxt, void *prev, const char *propname,
+                     const char *propval, unsigned int proplen)
+{
+	struct ft_atom atom;
+	char *p = ft_first_node(cxt);
+	char *next;
+	int past_prev = prev ? 0 : 1;
+	int depth = -1;
+
+	while ((next = ft_next(cxt, p, &atom)) != NULL) {
+		const void *data;
+		unsigned int size;
+
+		switch (atom.tag) {
+		case OF_DT_BEGIN_NODE:
+			depth++;
+
+			if (prev == p) {
+				past_prev = 1;
+				break;
+			}
+
+			if (!past_prev || depth < 1)
+				break;
+
+			data = __ft_get_prop(cxt, p, propname, &size);
+			if (!data || size != proplen)
+				break;
+			if (memcmp(data, propval, size))
+				break;
+
+			return p;
+
+		case OF_DT_END_NODE:
+			if (depth-- == 0)
+				return NULL;
+
+			break;
+		}
+
+		p = next;
+	}
+
+	return NULL;
+}
+
+void *ft_find_prop(struct ft_cxt *cxt, void *prev, const char *propname,
+                   const char *propval, int proplen)
+{
+	void *node = NULL;
+
+	if (prev) {
+		node = ft_node_ph2node(cxt, prev);
+
+		if (!node)
+			return NULL;
+	}
+
+	node = __ft_find_prop(cxt, node, propname, propval, proplen);
+	return ft_node_add(cxt, node);
+}
+
+void *ft_find_prop_str(struct ft_cxt *cxt, void *prev,
+                       const char *propname, const char *propval)
+{
+	return ft_find_prop(cxt, prev, propname, propval, strlen(propval) + 1);
+}
+
 int ft_set_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
 		const void *buf, const unsigned int buflen)
 {
diff --git a/arch/powerpc/boot/flatdevtree.h b/arch/powerpc/boot/flatdevtree.h
index 64c5513..8a9923d 100644
--- a/arch/powerpc/boot/flatdevtree.h
+++ b/arch/powerpc/boot/flatdevtree.h
@@ -104,5 +104,9 @@ int ft_get_prop(struct ft_cxt *cxt, cons
 int ft_set_prop(struct ft_cxt *cxt, const void *phandle, const char *propname,
 		const void *buf, const unsigned int buflen);
 void *ft_get_parent(struct ft_cxt *cxt, const void *phandle);
+void *ft_find_prop(struct ft_cxt *cxt, void *prev, const char *propname,
+                   const char *propval, int proplen);
+void *ft_find_prop_str(struct ft_cxt *cxt, void *prev,
+                       const char *propname, const char *propval);
 
 #endif /* FLATDEVTREE_H */
-- 
1.4.4




More information about the Linuxppc-dev mailing list