of_get_next_child() is supposed to return the next sibling of 'prev' and the function does exactly that. It expects that 'node' is always the same parent node. of_graph_get_next_endpoint() breaks this expectation, it walks further down the tree and then calls of_get_next_child() with 'node' being some subnode of the original node. Fix this by retrieving 'node' always from 'prev' and use 'node' only on initial entry when 'prev' is NULL. Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx> --- drivers/of/base.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index 62d84786ae..6fd69e7d7d 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -2054,6 +2054,9 @@ EXPORT_SYMBOL(of_get_next_available_child); struct device_node *of_get_next_child(const struct device_node *node, struct device_node *prev) { + if (prev) + node = prev->parent; + prev = list_prepare_entry(prev, &node->children, parent_list); list_for_each_entry_continue(prev, &node->children, parent_list) return prev; -- 2.39.5