* [PATCH] gpiolib: check validity for gpio_info in *_active()
@ 2017-09-21 20:41 Uwe Kleine-König
2017-09-26 6:46 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2017-09-21 20:41 UTC (permalink / raw)
To: barebox
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>
---
drivers/gpio/gpiolib.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 67d771bae3a8..c17cfdbb3350 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;
+
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;
+
return gpio_direction_output(gpio, gpio_adjust_value(gi, value));
}
EXPORT_SYMBOL(gpio_direction_active);
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gpiolib: check validity for gpio_info in *_active()
2017-09-21 20:41 [PATCH] gpiolib: check validity for gpio_info in *_active() Uwe Kleine-König
@ 2017-09-26 6:46 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2017-09-26 6:46 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Thu, Sep 21, 2017 at 10:41:39PM +0200, Uwe Kleine-König wrote:
> 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>
> ---
> drivers/gpio/gpiolib.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
Applied, thanks
Sascha
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 67d771bae3a8..c17cfdbb3350 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;
> +
> 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;
> +
> return gpio_direction_output(gpio, gpio_adjust_value(gi, value));
> }
> EXPORT_SYMBOL(gpio_direction_active);
> --
> 2.11.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-09-26 6:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21 20:41 [PATCH] gpiolib: check validity for gpio_info in *_active() Uwe Kleine-König
2017-09-26 6:46 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox