Re: [PATCH] devicetree: pull evaluation of of_address_to_resource() out of loop in of_dev_lookup()

From: Lothar WaÃmann
Date: Wed Apr 04 2012 - 01:57:53 EST


Hi,

Grant Likely writes:
> On Tue, 3 Apr 2012 14:48:28 +0200, Lothar WaÃmann <LW@xxxxxxxxxxxxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxx>
> > ---
>
> 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@xxxxxxxxxxxxxxxxxxx
___________________________________________________________
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/