mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2] gpiolib: check validity for gpio_info in *_active()
Date: Thu, 21 Sep 2017 22:44:55 +0200	[thread overview]
Message-ID: <20170921204455.21403-1-u.kleine-koenig@pengutronix.de> (raw)

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>
---
Changes since (implicit) v1:

 - make it compile (sigh)

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

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 67d771bae3a8..b83a27de7d21 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);
-- 
2.11.0


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

             reply	other threads:[~2017-09-21 20:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-21 20:44 Uwe Kleine-König [this message]
2017-09-26  6:47 ` Sascha Hauer

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=20170921204455.21403-1-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.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