[PATCH 2/3] of: Add missing locking to of_(bus_)?n_(size|addr)_cells()
From: Rob Herring (Arm)
Date: Thu May 30 2024 - 21:04:06 EST
When accessing parent/child/sibling pointers the DT spinlock needs to
be held. The of_(bus_)?n_(size|addr)_cells() functions are missing that
when walking up the parent nodes. In reality, it rarely matters as most
nodes are static.
Signed-off-by: Rob Herring (Arm) <robh@xxxxxxxxxx>
---
drivers/of/base.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 20603d3c9931..61fff13bbee5 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -91,8 +91,8 @@ int of_bus_n_addr_cells(struct device_node *np)
{
u32 cells;
- for (; np; np = np->parent)
- if (!of_property_read_u32(np, "#address-cells", &cells))
+ for_each_parent_of_node_scoped(parent, np)
+ if (!of_property_read_u32(parent, "#address-cells", &cells))
return cells;
/* No #address-cells property for the root node */
@@ -101,10 +101,9 @@ int of_bus_n_addr_cells(struct device_node *np)
int of_n_addr_cells(struct device_node *np)
{
- if (np->parent)
- np = np->parent;
+ struct device_node *parent __free(device_node) = of_get_parent(np);
- return of_bus_n_addr_cells(np);
+ return of_bus_n_addr_cells(parent);
}
EXPORT_SYMBOL(of_n_addr_cells);
@@ -112,8 +111,8 @@ int of_bus_n_size_cells(struct device_node *np)
{
u32 cells;
- for (; np; np = np->parent)
- if (!of_property_read_u32(np, "#size-cells", &cells))
+ for_each_parent_of_node_scoped(parent, np)
+ if (!of_property_read_u32(parent, "#size-cells", &cells))
return cells;
/* No #size-cells property for the root node */
@@ -122,10 +121,9 @@ int of_bus_n_size_cells(struct device_node *np)
int of_n_size_cells(struct device_node *np)
{
- if (np->parent)
- np = np->parent;
+ struct device_node *parent __free(device_node) = of_get_parent(np);
- return of_bus_n_size_cells(np);
+ return of_bus_n_size_cells(parent);
}
EXPORT_SYMBOL(of_n_size_cells);
--
2.43.0