From 76ad3f76c2ae5d0c78f3f568255e5bb6cf562ca7 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Thu, 17 Mar 2016 14:10:30 +0000 Subject: 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. --- sys/dev/ofw/fdt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'sys') 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 @@ -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; } -- cgit v1.2.3