bootfdt: Fix infinite loop in device_tree_for_each_node()

When a node's depth exceeds DEVICE_TREE_MAX_DEPTH inside the
device_tree_for_each_node() loop, the code prints a warning and
executes 'continue;' statement, which jumps to condition check,
bypassing the iterator update step:

    node = fdt_next_node(fdt, node, &depth).

The node and depth are not updated, the loop repeatedly evaluates
the same too-deep node, causing a hang.

Fix this by wrapping the node processing logic in an 'else' block.
This ensures the loop update step is executed on every iteration,
safely skipping deeply nested nodes and doing the traversal.

Fixes: 40f2ea3df2 ("xen/arm: pass node to device_tree_for_each_node")
Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
Reviewed-by: Michal Orzel <michal.orzel@amd.com>
Release-Acked-by: Oleskii Kurochko <oleksii.kurochko@gmail.com>
This commit is contained in:
Dmytro Prokopchuk1 authored and Michal Orzel committed 2026-06-26 10:08:15 +02:00
1 parent 9b3a73a028
commit 3b717f57dc
1 file changed
+20 -15
+20 -15
View File
@@ -90,23 +90,28 @@ int __init device_tree_for_each_node(const void *fdt, int node,
{
printk("Warning: device tree node `%s' is nested too deep\n",
name);
continue;
}
as = depth > 0 ? address_cells[depth-1] : DT_ROOT_NODE_ADDR_CELLS_DEFAULT;
ss = depth > 0 ? size_cells[depth-1] : DT_ROOT_NODE_SIZE_CELLS_DEFAULT;
address_cells[depth] = device_tree_get_u32(fdt, node,
"#address-cells", as);
size_cells[depth] = device_tree_get_u32(fdt, node,
"#size-cells", ss);
/* skip the first node */
if ( node != first_node )
else
{
ret = func(fdt, node, name, depth, as, ss, data);
if ( ret != 0 )
return ret;
as = depth > 0 ?
address_cells[depth - 1] :
DT_ROOT_NODE_ADDR_CELLS_DEFAULT;
ss = depth > 0 ?
size_cells[depth - 1] :
DT_ROOT_NODE_SIZE_CELLS_DEFAULT;
address_cells[depth] = device_tree_get_u32(fdt, node,
"#address-cells", as);
size_cells[depth] = device_tree_get_u32(fdt, node,
"#size-cells", ss);
/* skip the first node */
if ( node != first_node )
{
ret = func(fdt, node, name, depth, as, ss, data);
if ( ret != 0 )
return ret;
}
}
node = fdt_next_node(fdt, node, &depth);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.