]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[fdt] Allow for trailing slashes in path lookups
authorMichael Brown <mcb30@ipxe.org>
Mon, 14 Apr 2025 10:26:49 +0000 (11:26 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 14 Apr 2025 10:26:49 +0000 (11:26 +0100)
Using fdt_path() to find the root node "/" currently fails, since it
will attempt to find a child node with the empty name "" within the
root node.

Fix by changing fdt_path() to ignore any trailing slashes in a device
tree path.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/core/fdt.c

index 298cc439a0375029a6c608a67d15a6daff9edad2..199a53497e7118d1b9954d9d6227e0270255390b 100644 (file)
@@ -298,12 +298,16 @@ int fdt_path ( struct fdt *fdt, const char *path, unsigned int *offset ) {
        *offset = 0;
 
        /* Traverse tree one path segment at a time */
-       while ( *tmp ) {
+       while ( 1 ) {
 
                /* Skip any leading '/' */
                while ( *tmp == '/' )
                        tmp++;
 
+               /* Terminate if there are no more path components */
+               if ( ! *tmp )
+                       break;
+
                /* Find next '/' delimiter and convert to NUL */
                del = strchr ( tmp, '/' );
                if ( del )
@@ -316,9 +320,12 @@ int fdt_path ( struct fdt *fdt, const char *path, unsigned int *offset ) {
                if ( rc != 0 )
                        return rc;
 
-               /* Move to next path component, if any */
-               while ( *tmp && ( *tmp != '/' ) )
-                       tmp++;
+               /* Terminate if there are no more delimiters */
+               if ( ! del )
+                       break;
+
+               /* Move to next path component */
+               tmp = del;
        }
 
        DBGC2 ( fdt, "FDT found path \"%s\" at +%#04x\n", path, *offset );