Skip to contentSkip to conversation

of: fix phandle cache creation for DTs with no phandles

PATCH In review Rob Herring 2 participants 2 messages Sep 11, 2018

Subsystems (2)
lore
Share & tools
lore

Rob Herring

author maintainer
#0 lore raw

PATCH 1/1 of: fix phandle cache creation for DTs with no phandles

With commit 0b3ce78e90fc ("of: cache phandle nodes to reduce cost of of_find_node_by_phandle()"), a G3 PowerMac fails to boot. The root cause is the DT for this system has no phandle properties when booted with BootX. of_populate_phandle_cache() does not handle the case of no phandles correctly. The problem is roundup_pow_of_two() for 0 is undefined. The implementation subtracts 1 underflowing and then things are in the weeds.

Fixes 0b3ce78e90fc ("of: cache phandle nodes to reduce cost of of_find_node_by_phandle()")
Cc Frank Rowand <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>

---
Here's a formal patch of what Stan tested. Will send to Linus this week.

Rob

 drivers/of/base.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/of/base.c +3 -0
index a055cd1ef96d..17ae594b7014 100644
@@ -140,6 +140,9 @@ void of_populate_phandle_cache(void)
 		if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL)
 			phandles++;
 
+	if (!phandles)
+		goto out;
+
 	cache_entries = roundup_pow_of_two(phandles);
 	phandle_cache_mask = cache_entries - 1;
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines · Rob Herring

With commit 0b3ce78e90fc ("of: cache phandle nodes to reduce cost of of_find_node_by_phandle()"), a G3 PowerMac fails to boot. The root cause is the DT for this system has no phandle properties when booted with BootX. of_populate_phandle_cache() does not handle the case of no phandles correctly. The problem is roundup_pow_of_two() for 0 is undefined. The implementation subtracts 1 underflowing and then things are in the weeds.

Fixes 0b3ce78e90fc ("of: cache phandle nodes to reduce cost of of_find_node_by_phandle()")
Cc Frank Rowand <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>

---
Here's a formal patch of what Stan tested. Will send to Linus this week.

Rob

 drivers/of/base.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/of/base.c +0 -0
index a055cd1ef96d..17ae594b7014 100644

drivers/of/base.c void of_populate_phandle_cache(void) · line 148

Quoted 9 lines
drivers/of/base.c +3 -0
@@ -140,6 +140,9 @@ void of_populate_phandle_cache(void)
 		if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL)
 			phandles++;
 
+	if (!phandles)
+		goto out;
+
 	cache_entries = roundup_pow_of_two(phandles);
 	phandle_cache_mask = cache_entries - 1;