From a4fa68764dee46c3d376031e17913b52c65045a0 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sun, 11 Sep 2022 08:33:03 +0000 Subject: [PATCH] Change OF_getnodebyname() such that lokking up a node using just the name without a unit number (so without the @1234 bit) works as well. ok patrick@, gkoehler@ --- sys/dev/ofw/fdt.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sys/dev/ofw/fdt.c b/sys/dev/ofw/fdt.c index 9de907d6693..834c83ad55d 100644 --- a/sys/dev/ofw/fdt.c +++ b/sys/dev/ofw/fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdt.c,v 1.30 2022/08/21 12:52:10 jasper Exp $ */ +/* $OpenBSD: fdt.c,v 1.31 2022/09/11 08:33:03 kettenis Exp $ */ /* * Copyright (c) 2009 Dariusz Swiderski @@ -882,16 +882,33 @@ int OF_getnodebyname(int handle, const char *name) { void *node = (char *)tree.header + handle; + void *child; + char *data; + int len; if (handle == 0) node = fdt_find_node("/"); - for (node = fdt_child_node(node); node; node = fdt_next_node(node)) { - if (strcmp(name, fdt_node_name(node)) == 0) + for (child = fdt_child_node(node); child; + child = fdt_next_node(child)) { + if (strcmp(name, fdt_node_name(child)) == 0) break; } + if (child) + return (char *)child - (char *)tree.header; + + len = strlen(name); + for (child = fdt_child_node(node); child; + child = fdt_next_node(node)) { + data = fdt_node_name(child); + if (strncmp(name, data, len) == 0 && + strlen(data) > len && data[len] == '@') + break; + } + if (child) + return (char *)child - (char *)tree.header; - return node ? ((char *)node - (char *)tree.header) : 0; + return 0; } int -- 2.20.1