summaryrefslogtreecommitdiff
path: root/sys/dev/ofw
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2024-03-27 23:05:28 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2024-03-27 23:05:28 +0000
commit78d14e11e6eff6b1907b83cd11e54ec0c55a60e2 (patch)
tree5dc7dbae68727773b94edb0ea11f4237125e39d9 /sys/dev/ofw
parent002b8236854e432b2a9931fa3ec9673a09640ef7 (diff)
Fix fdt_find_node(). We should make sure we match the full name when
matching path components (but we do allow matches with the @unit bit). This fixes a problem on the Milk-V Pioneer where /soc/serial@123456 accidentally match a /socket0-clocks node and we would fail to find the serial console. ok miod@
Diffstat (limited to 'sys/dev/ofw')
-rw-r--r--sys/dev/ofw/fdt.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/sys/dev/ofw/fdt.c b/sys/dev/ofw/fdt.c
index 42edb466093..dfc00a39766 100644
--- a/sys/dev/ofw/fdt.c
+++ b/sys/dev/ofw/fdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdt.c,v 1.34 2023/04/26 14:39:42 kettenis Exp $ */
+/* $OpenBSD: fdt.c,v 1.35 2024/03/27 23:05:27 kettenis Exp $ */
/*
* Copyright (c) 2009 Dariusz Swiderski <sfires@sfires.net>
@@ -501,6 +501,7 @@ fdt_find_node(char *name)
while (*p) {
void *child;
const char *q;
+ const char *s;
while (*p == '/')
p++;
@@ -510,18 +511,33 @@ fdt_find_node(char *name)
if (q == NULL)
q = p + strlen(p);
+ /* Check for a complete match. */
for (child = fdt_child_node(node); child;
child = fdt_next_node(child)) {
- if (strncmp(p, fdt_node_name(child), q - p) == 0) {
- node = child;
+ s = fdt_node_name(child);
+ if (strncmp(p, s, q - p) == 0 && s[q - p] == '\0')
break;
- }
+ }
+ if (child) {
+ node = child;
+ p = q;
+ continue;
}
- if (child == NULL)
- return NULL; /* No match found. */
+ /* Check for a match without the unit name. */
+ for (child = fdt_child_node(node); child;
+ child = fdt_next_node(child)) {
+ s = fdt_node_name(child);
+ if (strncmp(p, s, q - p) == 0 && s[q - p] == '@')
+ break;
+ }
+ if (child) {
+ node = child;
+ p = q;
+ continue;
+ }
- p = q;
+ return NULL; /* No match found. */
}
return node;