Skip to content

Commit 045b14c

Browse files
committed
of: WARN on deprecated #address-cells/#size-cells handling
While OpenFirmware originally allowed walking parent nodes and default root values for #address-cells and #size-cells, FDT has long required explicit values. It's been a warning in dtc for the root node since the beginning (2005) and for any parent node since 2007. Of course, not all FDT uses dtc, but that should be the majority by far. The various extracted OF devicetrees I have dating back to the 1990s (various PowerMac, OLPC, PASemi Nemo) all have explicit root node properties. The warning is disabled for Sparc as there are known systems relying on default root node values. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Rob Herring (Arm) <[email protected]>
1 parent 67759cf commit 045b14c

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

drivers/of/base.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,25 @@ static bool __of_node_is_type(const struct device_node *np, const char *type)
8787
return np && match && type && !strcmp(match, type);
8888
}
8989

90+
#define EXCLUDED_DEFAULT_CELLS_PLATFORMS ( \
91+
IS_ENABLED(CONFIG_SPARC) \
92+
)
93+
9094
int of_bus_n_addr_cells(struct device_node *np)
9195
{
9296
u32 cells;
9397

94-
for (; np; np = np->parent)
98+
for (; np; np = np->parent) {
9599
if (!of_property_read_u32(np, "#address-cells", &cells))
96100
return cells;
97-
98-
/* No #address-cells property for the root node */
101+
/*
102+
* Default root value and walking parent nodes for "#address-cells"
103+
* is deprecated. Any platforms which hit this warning should
104+
* be added to the excluded list.
105+
*/
106+
WARN_ONCE(!EXCLUDED_DEFAULT_CELLS_PLATFORMS,
107+
"Missing '#address-cells' in %pOF\n", np);
108+
}
99109
return OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
100110
}
101111

@@ -112,11 +122,17 @@ int of_bus_n_size_cells(struct device_node *np)
112122
{
113123
u32 cells;
114124

115-
for (; np; np = np->parent)
125+
for (; np; np = np->parent) {
116126
if (!of_property_read_u32(np, "#size-cells", &cells))
117127
return cells;
118-
119-
/* No #size-cells property for the root node */
128+
/*
129+
* Default root value and walking parent nodes for "#size-cells"
130+
* is deprecated. Any platforms which hit this warning should
131+
* be added to the excluded list.
132+
*/
133+
WARN_ONCE(!EXCLUDED_DEFAULT_CELLS_PLATFORMS,
134+
"Missing '#size-cells' in %pOF\n", np);
135+
}
120136
return OF_ROOT_NODE_SIZE_CELLS_DEFAULT;
121137
}
122138

drivers/of/fdt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,12 +937,12 @@ int __init early_init_dt_scan_root(void)
937937
dt_root_addr_cells = OF_ROOT_NODE_ADDR_CELLS_DEFAULT;
938938

939939
prop = of_get_flat_dt_prop(node, "#size-cells", NULL);
940-
if (prop)
940+
if (!WARN(!prop, "No '#size-cells' in root node\n"))
941941
dt_root_size_cells = be32_to_cpup(prop);
942942
pr_debug("dt_root_size_cells = %x\n", dt_root_size_cells);
943943

944944
prop = of_get_flat_dt_prop(node, "#address-cells", NULL);
945-
if (prop)
945+
if (!WARN(!prop, "No '#address-cells' in root node\n"))
946946
dt_root_addr_cells = be32_to_cpup(prop);
947947
pr_debug("dt_root_addr_cells = %x\n", dt_root_addr_cells);
948948

0 commit comments

Comments
 (0)