summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Ravnborg <srn@skov.dk>2017-07-03 22:07:41 +0200
committerLucas Stach <l.stach@pengutronix.de>2017-07-14 16:46:08 +0200
commitea1bb5616b362adceec5df87dfb39d5973062afc (patch)
tree880acf7d2aae8f0d941472293e8e9dc2a0868ecf
parentcd7d4469687871e483b9adda3febb11621e23ef5 (diff)
downloadbarebox-ea1bb5616b362adceec5df87dfb39d5973062afc.tar.gz
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> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
-rw-r--r--drivers/gpio/gpiolib.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a3e17ad..1a373ef 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;