diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-03-17 14:10:30 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2016-03-17 14:10:30 +0000 |
commit | 76ad3f76c2ae5d0c78f3f568255e5bb6cf562ca7 (patch) | |
tree | d8ed0dfed8920db1b709ad723541f3ec0ebac18a /sys | |
parent | 3d945c7ae401b425bbcb8b2ac6c947b6c044bff6 (diff) |
Do not iterate all over the tree if OF_parent() is called on the root
node. The root is the root, it has no parent.
From Patrick Wildt.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/ofw/fdt.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/sys/dev/ofw/fdt.c b/sys/dev/ofw/fdt.c index c86df3e41d1..6810fdddfbc 100644 --- a/sys/dev/ofw/fdt.c +++ b/sys/dev/ofw/fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdt.c,v 1.2 2016/03/07 10:49:03 mpi Exp $ */ +/* $OpenBSD: fdt.c,v 1.3 2016/03/17 14:10:29 mpi Exp $ */ /* * Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net> @@ -291,7 +291,7 @@ fdt_parent_node_recurse(void *pnode, void *child) { void *node = fdt_child_node(pnode); void *tmp; - + while (node && (node != child)) { if ((tmp = fdt_parent_node_recurse(node, child))) return tmp; @@ -308,6 +308,9 @@ fdt_parent_node(void *node) if (!tree_inited) return NULL; + if (node == pnode) + return NULL; + return fdt_parent_node_recurse(pnode, node); } @@ -428,7 +431,7 @@ int OF_parent(int handle) { void *node = (char *)tree.header + handle; - + node = fdt_parent_node(node); return node ? ((char *)node - (char *)tree.header) : 0; } |