mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] gpiolib: fix: do not access oftree on non-OFDEVICE boards
@ 2017-07-02 20:24 Alexander Kurz
  2017-07-03  9:56 ` Lucas Stach
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Kurz @ 2017-07-02 20:24 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov, Alexander Kurz

Non-OFDEVICE boards may have OFTREE=y set, e.g. by BOOTM_OFTREE.
Attempts to browse the oftree will crash barebox on those boards.

Signed-off-by: Alexander Kurz <akurz@blala.de>
---
 drivers/gpio/gpiolib.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a3e17ad..a1ff965 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -416,7 +416,10 @@ int gpiochip_add(struct gpio_chip *chip)
 	for (i = chip->base; i < chip->base + chip->ngpio; i++)
 		gpio_desc[i].chip = chip;
 
-	return of_gpiochip_scan_hogs(chip);
+	if (IS_ENABLED(CONFIG_OFDEVICE))
+		return of_gpiochip_scan_hogs(chip);
+	else
+		return 0;
 }
 
 void gpiochip_remove(struct gpio_chip *chip)
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] gpiolib: fix: do not access oftree on non-OFDEVICE boards
  2017-07-02 20:24 [PATCH] gpiolib: fix: do not access oftree on non-OFDEVICE boards Alexander Kurz
@ 2017-07-03  9:56 ` Lucas Stach
  2017-07-04 20:17   ` Alexander Kurz
  0 siblings, 1 reply; 4+ messages in thread
From: Lucas Stach @ 2017-07-03  9:56 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: Andrey Smirnov, barebox

Am Sonntag, den 02.07.2017, 22:24 +0200 schrieb Alexander Kurz:
> Non-OFDEVICE boards may have OFTREE=y set, e.g. by BOOTM_OFTREE.
> Attempts to browse the oftree will crash barebox on those boards.
> 
> Signed-off-by: Alexander Kurz <akurz@blala.de>
> ---
>  drivers/gpio/gpiolib.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index a3e17ad..a1ff965 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -416,7 +416,10 @@ int gpiochip_add(struct gpio_chip *chip)
>  	for (i = chip->base; i < chip->base + chip->ngpio; i++)
>  		gpio_desc[i].chip = chip;
>  
> -	return of_gpiochip_scan_hogs(chip);
> +	if (IS_ENABLED(CONFIG_OFDEVICE))
> +		return of_gpiochip_scan_hogs(chip);
> +	else
> +		return 0;

This may also crash in mixed oftree/board file based systems (however
unlikely that is). I think an early return from of_gpiochip_scan_hogs ()
if chip->dev->device_node is NULL would be more robust.

Regards,
Lucas


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] gpiolib: fix: do not access oftree on non-OFDEVICE boards
  2017-07-03  9:56 ` Lucas Stach
@ 2017-07-04 20:17   ` Alexander Kurz
  2017-07-05 18:22     ` Sam Ravnborg
  0 siblings, 1 reply; 4+ messages in thread
From: Alexander Kurz @ 2017-07-04 20:17 UTC (permalink / raw)
  To: Lucas Stach; +Cc: Andrey Smirnov, barebox, Sam Ravnborg

Hi Lucas,

On Mon, 3 Jul 2017, Lucas Stach wrote:

> Am Sonntag, den 02.07.2017, 22:24 +0200 schrieb Alexander Kurz:
> > Non-OFDEVICE boards may have OFTREE=y set, e.g. by BOOTM_OFTREE.
> > Attempts to browse the oftree will crash barebox on those boards.
> > 
> > Signed-off-by: Alexander Kurz <akurz@blala.de>
> > ---
> >  drivers/gpio/gpiolib.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index a3e17ad..a1ff965 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -416,7 +416,10 @@ int gpiochip_add(struct gpio_chip *chip)
> >  	for (i = chip->base; i < chip->base + chip->ngpio; i++)
> >  		gpio_desc[i].chip = chip;
> >  
> > -	return of_gpiochip_scan_hogs(chip);
> > +	if (IS_ENABLED(CONFIG_OFDEVICE))
> > +		return of_gpiochip_scan_hogs(chip);
> > +	else
> > +		return 0;
> 
> This may also crash in mixed oftree/board file based systems (however
> unlikely that is). I think an early return from of_gpiochip_scan_hogs ()
> if chip->dev->device_node is NULL would be more robust.
IS_ENABLED(...) is evaluated at compile time.
Checking CONFIG_OFDEVICE even before calling the OF-function gives the 
compiler the chance to omit the integration of the unneeded function.
A quick test on with kindle3_defconfig resulted in half a kilobyte
image size difference.

Sure, a further check on the device node presence might be usefull, e.g.
git grep 'IS_ENABLED(CONFIG_OFDEVICE)' drivers/
but I have not reviewed the code in this direction.
At least, the code does not crash due to this reason.

Regards, Alexander


> Regards,
> Lucas
> 

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] gpiolib: fix: do not access oftree on non-OFDEVICE boards
  2017-07-04 20:17   ` Alexander Kurz
@ 2017-07-05 18:22     ` Sam Ravnborg
  0 siblings, 0 replies; 4+ messages in thread
From: Sam Ravnborg @ 2017-07-05 18:22 UTC (permalink / raw)
  To: Alexander Kurz; +Cc: Andrey Smirnov, barebox

On Tue, Jul 04, 2017 at 10:17:39PM +0200, Alexander Kurz wrote:
> Hi Lucas,
> 
> On Mon, 3 Jul 2017, Lucas Stach wrote:
> 
> > Am Sonntag, den 02.07.2017, 22:24 +0200 schrieb Alexander Kurz:
> > > Non-OFDEVICE boards may have OFTREE=y set, e.g. by BOOTM_OFTREE.
> > > Attempts to browse the oftree will crash barebox on those boards.
> > > 
> > > Signed-off-by: Alexander Kurz <akurz@blala.de>
> > > ---
> > >  drivers/gpio/gpiolib.c | 5 ++++-
> > >  1 file changed, 4 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > > index a3e17ad..a1ff965 100644
> > > --- a/drivers/gpio/gpiolib.c
> > > +++ b/drivers/gpio/gpiolib.c
> > > @@ -416,7 +416,10 @@ int gpiochip_add(struct gpio_chip *chip)
> > >  	for (i = chip->base; i < chip->base + chip->ngpio; i++)
> > >  		gpio_desc[i].chip = chip;
> > >  
> > > -	return of_gpiochip_scan_hogs(chip);
> > > +	if (IS_ENABLED(CONFIG_OFDEVICE))
> > > +		return of_gpiochip_scan_hogs(chip);
> > > +	else
> > > +		return 0;
> > 
> > This may also crash in mixed oftree/board file based systems (however
> > unlikely that is). I think an early return from of_gpiochip_scan_hogs ()
> > if chip->dev->device_node is NULL would be more robust.
> IS_ENABLED(...) is evaluated at compile time.
> Checking CONFIG_OFDEVICE even before calling the OF-function gives the 
> compiler the chance to omit the integration of the unneeded function.
> A quick test on with kindle3_defconfig resulted in half a kilobyte
> image size difference.

I have incorporat this change in the fix I posted, and added your
Signed-off-by: as you posted this first and my change came on
top of yours.
Will post in a new thread.

	Sam

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2017-07-05 18:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-02 20:24 [PATCH] gpiolib: fix: do not access oftree on non-OFDEVICE boards Alexander Kurz
2017-07-03  9:56 ` Lucas Stach
2017-07-04 20:17   ` Alexander Kurz
2017-07-05 18:22     ` Sam Ravnborg

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