Skip to contentSkip to conversation

gpio: fix line flag validation in linehandle_create

PATCH In review Kent Gibson 2 participants 2 messages Sep 9, 2019 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: fix line flag validation in linehandle_create

linehandle_create should not allow both GPIOHANDLE_REQUEST_INPUT and GPIOHANDLE_REQUEST_OUTPUT to be set.

---
 drivers/gpio/gpiolib.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpio/gpiolib.c +8 -0
index cca749010cd0..7502230a4ec8 100644
@@ -535,6 +535,14 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
 	if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS)
 		return -EINVAL;
 
+	/*
+	 * Do not allow both INPUT & OUTPUT flags to be set as they are
+	 * contradictory.
+	 */
+	if ((lflags & GPIOHANDLE_REQUEST_INPUT) &&
+	    (lflags & GPIOHANDLE_REQUEST_OUTPUT))
+		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
Signature · 1 line
2.23.0
#1 lore raw

pon., 9 wrz 2019 o 05:23 Kent Gibson <[email protected]> napisał(a):

Quoted 29 lines

linehandle_create should not allow both GPIOHANDLE_REQUEST_INPUT and GPIOHANDLE_REQUEST_OUTPUT to be set.

---
 drivers/gpio/gpiolib.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpio/gpiolib.c +8 -1
index cca749010cd0..7502230a4ec8 100644
@@ -535,6 +535,14 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
        if (lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS)
                return -EINVAL;
 
+       /*
+        * Do not allow both INPUT & OUTPUT flags to be set as they are
+        * contradictory.
+        */
+       if ((lflags & GPIOHANDLE_REQUEST_INPUT) &&
+           (lflags & GPIOHANDLE_REQUEST_OUTPUT))
+               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
--
Quoted 2 lines

2.23.0

This looks good, thanks. When sending v2 (after fixing the other patch) please do the following:

- send it to Linus and myself (addresses are listed in MAINTAINERS)
- send all patches as a single series

Thanks,
Bart