Skip to contentSkip to conversation

gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags simultaneously

PATCH In review Bartosz Golaszewski 2 participants 2 messages Nov 15, 2017 – Nov 29, 2017 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags simultaneously

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.

---
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(+)
drivers/gpio/gpiolib.c +9 -0
index 641a5eb552cb..ec80e0146fd5 100644
@@ -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) ||
Signature · 1 line
2.13.2
#1 lore raw
Quoted 11 lines · 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.

---
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