Skip to contentSkip to conversation

checks: Relax avoid_unnecessary_addr_size check to allow child ranges properties

PATCH Applied Philipp Zabel 2 participants 2 messages Nov 6, 2024 – Nov 27, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 checks: Relax avoid_unnecessary_addr_size check to allow child ranges properties

Do not fail the unnecessary #address-cells/#size-cells check if any children of the node have a "ranges" property.

---
Changes in v2:
- Add comment to child 'reg'/'ranges' check.
- Add child 'ranges' to failure message.
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 checks.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
checks.c +10 -7
index 6e06aeab5503..9e6a7b6a3e97 100644
@@ -1217,9 +1217,7 @@ WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
 static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti,
 					      struct node *node)
 {
-	struct property *prop;
 	struct node *child;
-	bool has_reg = false;
 
 	if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
 		return;
@@ -1228,13 +1226,18 @@ static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *d
 		return;
 
 	for_each_child(node, child) {
-		prop = get_property(child, "reg");
-		if (prop)
-			has_reg = true;
+		/*
+		 * Even if the child devices' address space is not mapped into
+		 * the parent bus (no 'ranges' property on node), children can
+		 * still have registers on a local bus, or map local addresses
+		 * to another subordinate address space. The properties on the
+		 * child nodes then make #address-cells/#size-cells necessary:
+		 */
+		if (get_property(child, "reg") || get_property(child, "ranges"))
+			return;
 	}
 
-	if (!has_reg)
-		FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" property");
+	FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" or \"ranges\" property");
 }
 WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size);
 
Signature · 1 line
2.39.5
Applied
#1 lore raw
Quoted 6 lines · Philipp Zabel

Do not fail the unnecessary #address-cells/#size-cells check if any children of the node have a "ranges" property.

Applied, thanks.

Sorry it's taken so long.

Quoted 47 lines

---
Changes in v2:
- Add comment to child 'reg'/'ranges' check.
- Add child 'ranges' to failure message.
- Link to v1: https://lore.kernel.org/all/[email protected]/

---
 checks.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
checks.c +10 -7
index 6e06aeab5503..9e6a7b6a3e97 100644
@@ -1217,9 +1217,7 @@ WARNING(avoid_default_addr_size, check_avoid_default_addr_size, NULL,
 static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *dti,
 					      struct node *node)
 {
-	struct property *prop;
 	struct node *child;
-	bool has_reg = false;
 
 	if (!node->parent || node->addr_cells < 0 || node->size_cells < 0)
 		return;
@@ -1228,13 +1226,18 @@ static void check_avoid_unnecessary_addr_size(struct check *c, struct dt_info *d
 		return;
 
 	for_each_child(node, child) {
-		prop = get_property(child, "reg");
-		if (prop)
-			has_reg = true;
+		/*
+		 * Even if the child devices' address space is not mapped into
+		 * the parent bus (no 'ranges' property on node), children can
+		 * still have registers on a local bus, or map local addresses
+		 * to another subordinate address space. The properties on the
+		 * child nodes then make #address-cells/#size-cells necessary:
+		 */
+		if (get_property(child, "reg") || get_property(child, "ranges"))
+			return;
 	}
 
-	if (!has_reg)
-		FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" property");
+	FAIL(c, dti, node, "unnecessary #address-cells/#size-cells without \"ranges\", \"dma-ranges\" or child \"reg\" or \"ranges\" property");
 }
 WARNING(avoid_unnecessary_addr_size, check_avoid_unnecessary_addr_size, NULL, &avoid_default_addr_size);
 
Signature · 4 lines
David Gibson (he or they)	| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you, not the other way
				| around.
http://www.ozlabs.org/~dgibson