From a570933999da5ff4e6a37aecb0ad9a0ac2bf4a09 Mon Sep 17 00:00:00 2001 From: Mathias Kresin Date: Thu, 28 Jun 2018 18:23:37 +0200 Subject: [PATCH] treewide: gpio-export: add error handling Check if the GPIO is valid (or set at all). If no GPIO is set in the devicetree, a gpiolib related kernel warning + stacktrace is shown during boot and gpio-export reports GPIOs as exported albeit none really is. Signed-off-by: Mathias Kresin --- .../ath79/patches-4.14/0024-GPIO-add-named-gpio-exports.patch | 4 +++- .../patches-4.14/0030-GPIO-add-named-gpio-exports.patch | 4 +++- .../patches-4.14/0024-GPIO-add-named-gpio-exports.patch | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/target/linux/ath79/patches-4.14/0024-GPIO-add-named-gpio-exports.patch b/target/linux/ath79/patches-4.14/0024-GPIO-add-named-gpio-exports.patch index 0c1bc739268..10ca24bc711 100644 --- a/target/linux/ath79/patches-4.14/0024-GPIO-add-named-gpio-exports.patch +++ b/target/linux/ath79/patches-4.14/0024-GPIO-add-named-gpio-exports.patch @@ -22,7 +22,7 @@ Signed-off-by: John Crispin #include "gpiolib.h" -@@ -506,3 +508,69 @@ void of_gpiochip_remove(struct gpio_chip +@@ -506,3 +508,71 @@ void of_gpiochip_remove(struct gpio_chip gpiochip_remove_pin_ranges(chip); of_node_put(chip->of_node); } @@ -56,6 +56,8 @@ Signed-off-by: John Crispin + enum of_gpio_flags of_flags; + + gpio = of_get_gpio_flags(cnp, i, &of_flags); ++ if (!gpio_is_valid(gpio)) ++ return gpio; + + if (of_flags == OF_GPIO_ACTIVE_LOW) + flags |= GPIOF_ACTIVE_LOW; diff --git a/target/linux/lantiq/patches-4.14/0030-GPIO-add-named-gpio-exports.patch b/target/linux/lantiq/patches-4.14/0030-GPIO-add-named-gpio-exports.patch index 30b6a11818b..013d8022650 100644 --- a/target/linux/lantiq/patches-4.14/0030-GPIO-add-named-gpio-exports.patch +++ b/target/linux/lantiq/patches-4.14/0030-GPIO-add-named-gpio-exports.patch @@ -22,7 +22,7 @@ Signed-off-by: John Crispin #include "gpiolib.h" -@@ -506,3 +508,73 @@ void of_gpiochip_remove(struct gpio_chip +@@ -506,3 +508,75 @@ void of_gpiochip_remove(struct gpio_chip gpiochip_remove_pin_ranges(chip); of_node_put(chip->of_node); } @@ -58,6 +58,8 @@ Signed-off-by: John Crispin + enum of_gpio_flags of_flags; + + gpio = of_get_gpio_flags(cnp, i, &of_flags); ++ if (!gpio_is_valid(gpio)) ++ return gpio; + + if (of_flags == OF_GPIO_ACTIVE_LOW) + flags |= GPIOF_ACTIVE_LOW; diff --git a/target/linux/ramips/patches-4.14/0024-GPIO-add-named-gpio-exports.patch b/target/linux/ramips/patches-4.14/0024-GPIO-add-named-gpio-exports.patch index 0c1bc739268..10ca24bc711 100644 --- a/target/linux/ramips/patches-4.14/0024-GPIO-add-named-gpio-exports.patch +++ b/target/linux/ramips/patches-4.14/0024-GPIO-add-named-gpio-exports.patch @@ -22,7 +22,7 @@ Signed-off-by: John Crispin #include "gpiolib.h" -@@ -506,3 +508,69 @@ void of_gpiochip_remove(struct gpio_chip +@@ -506,3 +508,71 @@ void of_gpiochip_remove(struct gpio_chip gpiochip_remove_pin_ranges(chip); of_node_put(chip->of_node); } @@ -56,6 +56,8 @@ Signed-off-by: John Crispin + enum of_gpio_flags of_flags; + + gpio = of_get_gpio_flags(cnp, i, &of_flags); ++ if (!gpio_is_valid(gpio)) ++ return gpio; + + if (of_flags == OF_GPIO_ACTIVE_LOW) + flags |= GPIOF_ACTIVE_LOW;