aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2016-10-18 10:54:06 -0400
committerLinus Walleij <linus.walleij@linaro.org>2016-10-21 08:48:56 -0400
commitac7dbb991ee5afc0beacce3a252dcaaa249a7786 (patch)
tree4c3fba72decc19bae273e070874cfe534e704f83 /drivers/gpio
parente3e847c7f15a27c80f526b2a7a8d4dd7ce0960a0 (diff)
gpio: GPIO_GET_LINEEVENT_IOCTL: Reject invalid line and event flags
The GPIO_GET_LINEEVENT_IOCTL currently ignores unknown or undefined linehandle and lineevent flags. From a backwards and forwards compatibility viewpoint it is highly desirable to reject unknown flags though. On one hand an application that is using newer flags and is running on an older kernel has no way to detect if the new flags were handled correctly if they are silently discarded. On the other hand an application that (accidentally) passes undefined flags will run fine on an older kernel, but may break on a newer kernel when these flags get defined. Ensure that requests that have undefined flags set are rejected with an error, rather than silently discarding the undefined flags. Cc: stable@vger.kernel.org Fixes: 61f922db7221 ("gpio: userspace ABI for reading GPIO line events") Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b5b1a8425907..20e09b7c2de3 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -556,6 +556,10 @@ struct lineevent_state {
556 struct mutex read_lock; 556 struct mutex read_lock;
557}; 557};
558 558
559#define GPIOEVENT_REQUEST_VALID_FLAGS \
560 (GPIOEVENT_REQUEST_RISING_EDGE | \
561 GPIOEVENT_REQUEST_FALLING_EDGE)
562
559static unsigned int lineevent_poll(struct file *filep, 563static unsigned int lineevent_poll(struct file *filep,
560 struct poll_table_struct *wait) 564 struct poll_table_struct *wait)
561{ 565{
@@ -753,6 +757,13 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
753 goto out_free_label; 757 goto out_free_label;
754 } 758 }
755 759
760 /* Return an error if a unknown flag is set */
761 if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
762 (eflags & ~GPIOEVENT_REQUEST_VALID_FLAGS)) {
763 ret = -EINVAL;
764 goto out_free_label;
765 }
766
756 /* This is just wrong: we don't look for events on output lines */ 767 /* This is just wrong: we don't look for events on output lines */
757 if (lflags & GPIOHANDLE_REQUEST_OUTPUT) { 768 if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
758 ret = -EINVAL; 769 ret = -EINVAL;