gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags for input
authorBartosz Golaszewski <brgl@bgdev.pl>
Mon, 16 Oct 2017 09:32:30 +0000 (11:32 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Thu, 19 Oct 2017 20:32:39 +0000 (22:32 +0200)
OPEN_DRAIN and OPEN_SOURCE flags only affect the way we drive a GPIO
line, so they only make sense for output mode. Just as we only allow
input mode for event handle requests, don't allow passing open-drain
and open-source flags for any other mode than explicit output.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c

index 58196be52b1ef0b58a1ea028285fcb4d47d32c69..5acff8db513615175f2111b836a30584e06bf166 100644 (file)
@@ -457,6 +457,12 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
        if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS)
                return -EINVAL;
 
+       /* OPEN_DRAIN and OPEN_SOURCE flags only make sense for output mode. */
+       if (!(lflags & GPIOHANDLE_REQUEST_OUTPUT) &&
+           ((lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) ||
+            (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)))
+               return -EINVAL;
+
        lh = kzalloc(sizeof(*lh), GFP_KERNEL);
        if (!lh)
                return -ENOMEM;