From: Alexander Kurz <akurz@blala.de>
To: Lucas Stach <l.stach@pengutronix.de>
Cc: barebox@lists.infradead.org, "Sam Ravnborg" <sam@ravnborg.org>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH 2/3] gpio: fix null pointer exception when there is no oftree
Date: Thu, 6 Jul 2017 22:53:38 +0200 (CEST) [thread overview]
Message-ID: <alpine.DEB.2.00.1707062233390.12561@blala.de> (raw)
In-Reply-To: <1499345180.22075.58.camel@pengutronix.de>
On Thu, 6 Jul 2017, Lucas Stach wrote:
> Am Mittwoch, den 05.07.2017, 20:33 +0200 schrieb Sam Ravnborg:
> > From d10f426e1b8cec7de257dabf59e7fe53a591b3c1 Mon Sep 17 00:00:00 2001
> > From: Sam Ravnborg <srn@skov.dk>
> > Date: Mon, 3 Jul 2017 22:07:41 +0200
> > Subject: [PATCH 2/3] gpio: fix null pointer exception when there is no oftree
> >
> > In a system with oftree support enabled but with no oftree the
> > of_gpiochip_scan_hogs() would fail due to device_node equals NULL.
> >
> > Check device_node and return with 0 in this situation, as this
> > mirrors what would have happened before we added support for gpio-hogs.
> >
> > Use IS_ENABLED(CONFIG_OFDEVICE) to teach compiler to leave
> > out the of_* specific functions if not needed.
> >
> > Fixes: 37e6bee7 ("gpiolib: Add support for GPIO "hog" nodes")
> > Signed-off-by: Alexander Kurz <akurz@blala.de>
> > Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
> > ---
> > drivers/gpio/gpiolib.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index a3e17ada0..2bd8ef2a8 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -379,6 +379,9 @@ static int of_gpiochip_scan_hogs(struct gpio_chip *chip)
> > struct device_node *np;
> > int ret, i;
> >
> > + if (!chip->dev->device_node)
> > + return 0;
> > +
> > for_each_available_child_of_node(chip->dev->device_node, np) {
> > if (!of_property_read_bool(np, "gpio-hog"))
> > continue;
> > @@ -416,7 +419,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)
>
> I think this can be simplified to:
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index a3e17ada0d39..1a373ef149a5 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -379,6 +379,9 @@ static int of_gpiochip_scan_hogs(struct gpio_chip
> *chip)
> struct device_node *np;
> int ret, i;
>
> + if (!IS_ENABLED(CONFIG_OFDEVICE) || !chip->dev->device_node)
> + return 0;
> +
> for_each_available_child_of_node(chip->dev->device_node, np) {
> if (!of_property_read_bool(np, "gpio-hog"))
> continue;
>
> The optimizer should be able to work this out. Can you check that this
> works for you? No need to resend, if it works I'll just commit this.
This works perfecty fine with gcc-5.2 and gcc-4.6
(although gcc-4.6 compatibilty broke with commit 4ef026c3048)
Thanks, Alexander
>
> Regards,
> Lucas
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-07-06 20:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-05 18:27 [PATCH v2 0/3] diverse at91 related fixes Sam Ravnborg
2017-07-05 18:32 ` [PATCH 1/3] clk: fix clk_get error handling Sam Ravnborg
2017-07-05 18:33 ` [PATCH 2/3] gpio: fix null pointer exception when there is no oftree Sam Ravnborg
2017-07-06 12:46 ` Lucas Stach
2017-07-06 20:53 ` Alexander Kurz [this message]
2017-07-07 12:42 ` Lucas Stach
2017-07-05 18:34 ` [PATCH 3/3] arm: at91 bootstrap: declare local function static Sam Ravnborg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.00.1707062233390.12561@blala.de \
--to=akurz@blala.de \
--cc=barebox@lists.infradead.org \
--cc=l.stach@pengutronix.de \
--cc=sam@ravnborg.org \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox