mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sam Ravnborg <sam@ravnborg.org>
To: barebox@lists.infradead.org
Cc: Alexander Kurz <akurz@blala.de>
Subject: [PATCH 2/2] gpio: fix null pointer exception when there is no oftree
Date: Mon, 3 Jul 2017 22:22:34 +0200	[thread overview]
Message-ID: <20170703202234.GB15480@ravnborg.org> (raw)
In-Reply-To: <20170703161922.GA24614@ravnborg.org>

From 500c564285890fd0c9c47dc68f7fe6bc916e4589 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/2] 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.

Fixes: 37e6bee7 ("gpiolib: Add support for GPIO "hog" nodes")
Cc: Alexander Kurz <akurz@blala.de>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---


Alexander posted a patch to fix this problem earlier this week.
I only looked at it after I had cooked up this patch.

Not too happy about the approach here, but seems to me to be
the best way.

Also the two static functions in this file may be wrapped in
#ifdef CONFIG_OFTREE
#else
static int of_gpiochip_scan_hogs(struct gpio_chip *chip) { return 0; }
#endif
Or maybe moved to of/of_gpio.c?

So they do not waste binary size with no OFTREE support.
I could not from existing code base see what was the preferred
approach here, likely because I looked in the wrong places.

	Sam



 drivers/gpio/gpiolib.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a3e17ada0..2d0b778c8 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;
-- 
2.12.0


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

      parent reply	other threads:[~2017-07-03 20:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-03 16:19 Observations with AT91SAM9263-EK Sam Ravnborg
2017-07-03 16:34 ` Jean-Christophe PLAGNIOL-VILLARD
2017-07-03 21:07   ` Sam Ravnborg
2017-07-03 20:17 ` [PATCH 1/2] clk: fix clk_get error handling Sam Ravnborg
2017-07-04  6:11   ` Uwe Kleine-König
2017-07-04  6:53     ` Sam Ravnborg
2017-07-03 20:22 ` Sam Ravnborg [this message]

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=20170703202234.GB15480@ravnborg.org \
    --to=sam@ravnborg.org \
    --cc=akurz@blala.de \
    --cc=barebox@lists.infradead.org \
    /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