summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2022-09-19 16:12:20 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2022-09-19 16:12:20 +0000
commit780ac5f6a7a40e704b72485c973860af939515df (patch)
tree77a3c1227a32c3e5ab7d0adc4c9db15a05039945 /sys/dev
parentae4dc495044bfdcc6545a9ea916e04c3ec7c3e7f (diff)
Change OF_getnodebyname() such that looking up a node using just the name
without a unit number (so without the @1234 bit) works as well. This is a re-commit of the backed out change with the endless loop fixed.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ofw/fdt.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/sys/dev/ofw/fdt.c b/sys/dev/ofw/fdt.c
index e6593d61b32..c3a84b93d65 100644
--- a/sys/dev/ofw/fdt.c
+++ b/sys/dev/ofw/fdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.c,v 1.32 2022/09/18 14:41:54 mpi Exp $ */
+/* $OpenBSD: fdt.c,v 1.33 2022/09/19 16:12:19 patrick Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -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(child)) {
+ 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