summaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorBartosz Golaszewski <brgl@bgdev.pl>2017-10-16 11:32:30 +0200
committerLinus Walleij <linus.walleij@linaro.org>2017-10-19 22:32:39 +0200
commit609aaf6a60299256d2a6f2be499327a409dada17 (patch)
treeb38145be5ed4aded0a31de14de36e1bc0e8802e1 /drivers/gpio
parent418ee8e91fe7fc90ffb6bce391304e084f77bce4 (diff)
downloadlinux-609aaf6a60299256d2a6f2be499327a409dada17.tar.gz
linux-609aaf6a60299256d2a6f2be499327a409dada17.tar.bz2
linux-609aaf6a60299256d2a6f2be499327a409dada17.zip
gpiolib: don't allow OPEN_DRAIN & OPEN_SOURCE flags for input
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>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 58196be52b1e..5acff8db5136 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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;