mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] devicetree: pull evaluation of of_address_to_resource() out of loop in of_dev_lookup()
@ 2012-04-03 12:48 Lothar Waßmann
       [not found] ` <20120403235434.A536C3E03F3@localhost>
  0 siblings, 1 reply; 2+ messages in thread
From: Lothar Waßmann @ 2012-04-03 12:48 UTC (permalink / raw)
  To: Grant Likely; +Cc: Rob Herring, linux-kernel, 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.

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

Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
---
 drivers/of/platform.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 343ad29..528405f 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -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);
-- 
1.7.2.5


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] devicetree: pull evaluation of of_address_to_resource() out of loop in of_dev_lookup()
       [not found] ` <20120403235434.A536C3E03F3@localhost>
@ 2012-04-04  5:57   ` Lothar Waßmann
  0 siblings, 0 replies; 2+ messages in thread
From: Lothar Waßmann @ 2012-04-04  5:57 UTC (permalink / raw)
  To: Grant Likely; +Cc: Rob Herring, linux-kernel

Hi,

Grant Likely writes:
> On Tue,  3 Apr 2012 14:48:28 +0200, Lothar Waßmann <LW@KARO-electronics.de> wrote:
> > 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.
> > 
> > Signed-off-by: Lothar Waßmann <LW@KARO-electronics.de>
> > ---
> 
> 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
-- 
___________________________________________________________

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 | info@karo-electronics.de
___________________________________________________________

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-04-04  5:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-03 12:48 [PATCH] devicetree: pull evaluation of of_address_to_resource() out of loop in of_dev_lookup() Lothar Waßmann
     [not found] ` <20120403235434.A536C3E03F3@localhost>
2012-04-04  5:57   ` Lothar Waßmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®