summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2009-08-26 17:30:15 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2009-08-26 17:30:15 +0000
commit202aa5db1c78622a17a6b0be9a45fb2748247111 (patch)
tree7b580f13e8583abef1d26f930d020eabc211b331 /sys/arch
parentb2d20daf1444454c31977d17ed27a3e84bb933f2 (diff)
Change fdt_find_node() such that it takes a full path as argument.
ok dms@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/socppc/socppc/fdt.c58
1 files changed, 27 insertions, 31 deletions
diff --git a/sys/arch/socppc/socppc/fdt.c b/sys/arch/socppc/socppc/fdt.c
index 61b4bcbda63..0ddb5b8d7be 100644
--- a/sys/arch/socppc/socppc/fdt.c
+++ b/sys/arch/socppc/socppc/fdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.c,v 1.2 2009/08/25 21:27:24 kettenis Exp $ */
+/* $OpenBSD: fdt.c,v 1.3 2009/08/26 17:30:14 kettenis Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -27,7 +27,6 @@ char *fdt_get_str(u_int32_t);
void *skip_property(u_int32_t *);
void *skip_props(u_int32_t *);
void *skip_node_name(u_int32_t *);
-void *fdt_find_node_recurse(void *node, char *name);
#ifdef DEBUG
void fdt_print_node_recurse(void *, int);
#endif
@@ -262,44 +261,41 @@ fdt_node_name(void *node)
}
void *
-fdt_find_node_recurse(void *node, char *name)
+fdt_find_node(char *name)
{
- void *child;
- void *tmp;
- char *nname;
- int len;
+ void *node = fdt_next_node(0);
+ const char *p = name;
- tmp = 0;
+ if (!tree_inited)
+ return NULL;
- if (!(nname = fdt_node_name(node)))
+ if (*p != '/')
return NULL;
- /* root directory for version >= 16 can be null */
- if ((strlen(nname) == 0) && (tree.version >= 16)) {
- if (!strcmp(name, "/"))
- return node;
- } else {
- len = (strlen(name) > strlen(nname)) ? strlen(nname) :
- strlen(name);
- if (!strncmp(name, nname, len)) {
+ while (*p) {
+ void *child;
+ const char *q;
+
+ while (*p == '/')
+ p++;
+ if (*p == 0)
return node;
+ q = strchr(p, '/');
+ if (q == NULL)
+ q = p + strlen(p);
+
+ for (child = fdt_child_node(node); child;
+ child = fdt_next_node(child)) {
+ if (strncmp(p, fdt_node_name(child), q - p) == 0) {
+ node = child;
+ break;
+ }
}
- }
-
- for (child = fdt_child_node(node); child && (!tmp);
- child = fdt_next_node(child))
- tmp = fdt_find_node_recurse(child, name);
- return (tmp) ? tmp : NULL;
-}
-
-void *
-fdt_find_node(char *name)
-{
- if (!tree_inited)
- return NULL;
+ p = q;
+ }
- return fdt_find_node_recurse(fdt_next_node(0), name);
+ return node;
}
#ifdef DEBUG