summaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2017-09-21 22:44:55 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-09-26 08:46:54 +0200
commitb2ac13f498fb217194d6afe836981411bf14158c (patch)
tree057d6ce5f30f830ed113a75766302b9776330311 /drivers/gpio
parent340af0aaf7a9d2d8838c7f1d917a1cbec2b6bcfa (diff)
downloadbarebox-b2ac13f498fb217194d6afe836981411bf14158c.tar.gz
barebox-b2ac13f498fb217194d6afe836981411bf14158c.tar.xz
gpiolib: check validity for gpio_info in *_active()
gpio_set_active, gpio_is_active and gpio_direction_active are public functions, accordingly there should be error checking. If an invalid gpio number is given to these functions without checking gpio_adjust_value is called with gi == NULL which then dereferences this pointer. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 67d771bae3..b83a27de7d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -204,6 +204,10 @@ EXPORT_SYMBOL(gpio_set_value);
void gpio_set_active(unsigned gpio, bool value)
{
struct gpio_info *gi = gpio_to_desc(gpio);
+
+ if (!gi)
+ return;
+
gpio_set_value(gpio, gpio_adjust_value(gi, value));
}
EXPORT_SYMBOL(gpio_set_active);
@@ -229,6 +233,10 @@ EXPORT_SYMBOL(gpio_get_value);
int gpio_is_active(unsigned gpio)
{
struct gpio_info *gi = gpio_to_desc(gpio);
+
+ if (!gi)
+ return -ENODEV;
+
return gpio_adjust_value(gi, gpio_get_value(gpio));
}
EXPORT_SYMBOL(gpio_is_active);
@@ -255,6 +263,10 @@ EXPORT_SYMBOL(gpio_direction_output);
int gpio_direction_active(unsigned gpio, bool value)
{
struct gpio_info *gi = gpio_to_desc(gpio);
+
+ if (!gi)
+ return -ENODEV;
+
return gpio_direction_output(gpio, gpio_adjust_value(gi, value));
}
EXPORT_SYMBOL(gpio_direction_active);