]> git.ipfire.org Git - thirdparty/kernel/stable.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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 19 Mar 2018 08:09:52 +0000 (09:09 +0100)
[ Upstream commit 588fc3bceaf81bbd62e18af6f7bd475e01c2b7e8 ]

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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/gpio/gpiolib.c

index f6efcf94f6ad079915a8bf4060bc2b93117495ec..7a5cf5b08c54f16218f58aeffb7360db14c0345e 100644 (file)
@@ -460,6 +460,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) ||