linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags simultaneously
@ 2017-11-15 15:47 Bartosz Golaszewski
  2017-11-29 13:16 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Bartosz Golaszewski @ 2017-11-15 15:47 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

Do not allow OPEN_SOURCE & OPEN_DRAIN flags in a single request. If
the hardware actually supports enabling both at the same time the
electrical result would be disastrous.

Suggested-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
There was a misunderstanding as to what the goal of my previous commit
609aaf6a6029 ("gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags for
input") was, which resulted in discovering another thing that needs
fixing. This change was suggested to me by Linus earlier today.

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

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 641a5eb552cb..ec80e0146fd5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -459,6 +459,15 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
 	if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS)
 		return -EINVAL;
 
+	/*
+	 * Do not allow OPEN_SOURCE & OPEN_DRAIN flags in a single request. If
+	 * the hardware actually supports enabling both at the same time the
+	 * electrical result would be disastrous.
+	 */
+	if ((lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) &&
+	    (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE))
+		return -EINVAL;
+
 	/* OPEN_DRAIN and OPEN_SOURCE flags only make sense for output mode. */
 	if (!(lflags & GPIOHANDLE_REQUEST_OUTPUT) &&
 	    ((lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) ||
-- 
2.13.2

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags simultaneously
  2017-11-15 15:47 [PATCH] gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags simultaneously Bartosz Golaszewski
@ 2017-11-29 13:16 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2017-11-29 13:16 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio, linux-kernel

On Wed, Nov 15, 2017 at 4:47 PM, Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> Do not allow OPEN_SOURCE & OPEN_DRAIN flags in a single request. If
> the hardware actually supports enabling both at the same time the
> electrical result would be disastrous.
>
> Suggested-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
> There was a misunderstanding as to what the goal of my previous commit
> 609aaf6a6029 ("gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags for
> input") was, which resulted in discovering another thing that needs
> fixing. This change was suggested to me by Linus earlier today.

Awesome, thanks.

Patch applied.

I wonder if we should even put some swear words into dmesg
for this.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-29 13:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-15 15:47 [PATCH] gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags simultaneously Bartosz Golaszewski
2017-11-29 13:16 ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).