Skip to contentSkip to conversation

devicetree: pull evaluation of of_address_to_resource() out of loop in of_dev_lookup()

PATCH In review Lothar Waßmann 1 participant 2 messages Apr 3, 2012 – Apr 4, 2012 1 message not in the archive Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devicetree: pull evaluation of of_address_to_resource() out of loop in of_dev_lookup()

The result of_address_to_resource(np, 0, &res) is independent from the for (; lookup->compatible != NULL; lookup++) {
}
loop evaluation. Evaluate it once before entering the loop.

Also add a space between 'for' keyword and parens.

---
 drivers/of/platform.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
drivers/of/platform.c +4 -3
index 343ad29..528405f 100644
@@ -314,11 +314,12 @@ static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *l
 	if (!lookup)
 		return NULL;
 
-	for(; lookup->compatible != NULL; lookup++) {
+	if (of_address_to_resource(np, 0, &res))
+		return NULL;
+
+	for (; lookup->compatible != NULL; lookup++) {
 		if (!of_device_is_compatible(np, lookup->compatible))
 			continue;
-		if (of_address_to_resource(np, 0, &res))
-			continue;
 		if (res.start != lookup->phys_addr)
 			continue;
 		pr_debug("%s: devname=%s\n", np->full_name, lookup->name);
Signature · 1 line
1.7.2.5
#2 lore raw
In reply to a message not in the archive

Hi,

Quoted 6 lines · Grant Likely
Quoted 5 lines · Lothar Waßmann

The result of_address_to_resource(np, 0, &res) is independent from the for (; lookup->compatible != NULL; lookup++) {
}
loop evaluation. Evaluate it once before entering the loop.

Quoted 8 lines
Quoted 4 lines

Also add a space between 'for' keyword and parens.

---

What is the reason for this patch? The error path may be slightly less efficient in the failure case, but it isn't incorrect.

What's not correct? If of_address_to_resource() yields a non-zero result, the function will never reach the 'return lookup' inside the loop but only the 'return NULL' at the end of the function. Thus it is vain to re-evaluate of_address_to_resource() in every loop.

Lothar Waßmann

Signature · 9 lines
___________________________________________________________

Ka-Ro electronics GmbH | Pascalstraße 22 | D - 52076 Aachen
Phone: +49 2408 1402-0 | Fax: +49 2408 1402-10
Geschäftsführer: Matthias Kaussen
Handelsregistereintrag: Amtsgericht Aachen, HRB 4996

www.karo-electronics.de | [email protected]
___________________________________________________________