Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: zImage: atags_to_fdt: Fix node names on added root nodes

Commit 7536c7e03e74 ("of/fdt: Remove redundant kbasename function
call") exposed a bug creating DT nodes in the ATAGS to DT fixup code.
Non-existent nodes would mistaken get created with a leading '/'. The
problem was fdt_path_offset() takes a full path while creating a node
with fdt_add_subnode() takes just the basename.

Since this we only add root child nodes, we can just skip over the '/'.

Fixes: 7536c7e03e74 ("of/fdt: Remove redundant kbasename function call")
Reported-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Cc: Qi Zheng <arch0.zheng@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Signed-off-by: Rob Herring <robh@kernel.org>
Tested-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Link: https://lore.kernel.org/r/20210126023905.1631161-1-robh@kernel.org

+2 -1
+2 -1
arch/arm/boot/compressed/atags_to_fdt.c
··· 15 15 { 16 16 int offset = fdt_path_offset(fdt, node_path); 17 17 if (offset == -FDT_ERR_NOTFOUND) 18 - offset = fdt_add_subnode(fdt, 0, node_path); 18 + /* Add the node to root if not found, dropping the leading '/' */ 19 + offset = fdt_add_subnode(fdt, 0, node_path + 1); 19 20 return offset; 20 21 } 21 22