]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commitdiff
gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags simultaneously
authorBartosz Golaszewski <brgl@bgdev.pl>
Wed, 15 Nov 2017 15:47:43 +0000 (16:47 +0100)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 30 Nov 2017 09:54:16 +0000 (10:54 +0100)
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>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c

index aad84a6306c4e5ddbc3364d58add85fa1b1e2583..bdcdcdefdb71bec95c4dd797ff1c35fb788f6b9f 100644 (file)
@@ -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) ||