diff mbox series

gpio: fix line flag validation in lineevent_create

Message ID 20190909032406.1952-1-warthog618@gmail.com
State New
Headers show
Series gpio: fix line flag validation in lineevent_create | expand

Commit Message

Kent Gibson Sept. 9, 2019, 3:24 a.m. UTC
lineevent_create should not allow any of GPIOHANDLE_REQUEST_OUTPUT,
GPIOHANDLE_REQUEST_OPEN_DRAIN or GPIOHANDLE_REQUEST_OPEN_SOURCE to be set.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
---
 drivers/gpio/gpiolib.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Bartosz Golaszewski Sept. 9, 2019, 7:31 a.m. UTC | #1
pon., 9 wrz 2019 o 05:24 Kent Gibson <warthog618@gmail.com> napisał(a):
>

Hi Kent,

thanks for spotting this. Just single nit below:

> lineevent_create should not allow any of GPIOHANDLE_REQUEST_OUTPUT,
> GPIOHANDLE_REQUEST_OPEN_DRAIN or GPIOHANDLE_REQUEST_OPEN_SOURCE to be set.
>
> Signed-off-by: Kent Gibson <warthog618@gmail.com>
> ---
>  drivers/gpio/gpiolib.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index cca749010cd0..5499ec7bc783 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -918,7 +918,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
>                 goto out_free_label;
>         }
>
> -       /* Return an error if a unknown flag is set */
> +       /* Return an error if an unknown flag is set */

Please don't sneak in changes unrelated to the patch. If you want to
fix the typo - do it in a separate one.

>         if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
>             (eflags & ~GPIOEVENT_REQUEST_VALID_FLAGS)) {
>                 ret = -EINVAL;
> @@ -926,7 +926,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
>         }
>
>         /* This is just wrong: we don't look for events on output lines */
> -       if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
> +       if ((lflags & GPIOHANDLE_REQUEST_OUTPUT) ||
> +           (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) ||
> +           (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)) {
>                 ret = -EINVAL;
>                 goto out_free_label;
>         }
> @@ -940,10 +942,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
>
>         if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW)
>                 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
> -       if (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN)
> -               set_bit(FLAG_OPEN_DRAIN, &desc->flags);
> -       if (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)
> -               set_bit(FLAG_OPEN_SOURCE, &desc->flags);
>
>         ret = gpiod_direction_input(desc);
>         if (ret)
> --
> 2.23.0
>
Bartosz Golaszewski Sept. 9, 2019, 8:07 a.m. UTC | #2
pon., 9 wrz 2019 o 09:31 Bartosz Golaszewski <brgl@bgdev.pl> napisał(a):
>
> pon., 9 wrz 2019 o 05:24 Kent Gibson <warthog618@gmail.com> napisał(a):
> >
>
> Hi Kent,
>
> thanks for spotting this. Just single nit below:
>
> > lineevent_create should not allow any of GPIOHANDLE_REQUEST_OUTPUT,
> > GPIOHANDLE_REQUEST_OPEN_DRAIN or GPIOHANDLE_REQUEST_OPEN_SOURCE to be set.
> >
> > Signed-off-by: Kent Gibson <warthog618@gmail.com>
> > ---
> >  drivers/gpio/gpiolib.c | 10 ++++------
> >  1 file changed, 4 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> > index cca749010cd0..5499ec7bc783 100644
> > --- a/drivers/gpio/gpiolib.c
> > +++ b/drivers/gpio/gpiolib.c
> > @@ -918,7 +918,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
> >                 goto out_free_label;
> >         }
> >
> > -       /* Return an error if a unknown flag is set */
> > +       /* Return an error if an unknown flag is set */
>
> Please don't sneak in changes unrelated to the patch. If you want to
> fix the typo - do it in a separate one.
>
> >         if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
> >             (eflags & ~GPIOEVENT_REQUEST_VALID_FLAGS)) {
> >                 ret = -EINVAL;
> > @@ -926,7 +926,9 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
> >         }
> >
> >         /* This is just wrong: we don't look for events on output lines */
> > -       if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
> > +       if ((lflags & GPIOHANDLE_REQUEST_OUTPUT) ||
> > +           (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) ||
> > +           (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)) {
> >                 ret = -EINVAL;
> >                 goto out_free_label;
> >         }
> > @@ -940,10 +942,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip)
> >
> >         if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW)
> >                 set_bit(FLAG_ACTIVE_LOW, &desc->flags);
> > -       if (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN)
> > -               set_bit(FLAG_OPEN_DRAIN, &desc->flags);
> > -       if (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)
> > -               set_bit(FLAG_OPEN_SOURCE, &desc->flags);
> >
> >         ret = gpiod_direction_input(desc);
> >         if (ret)
> > --
> > 2.23.0
> >

Ok, so seeing that we'll still have another week for fixes, I thought
it would be nice to get those in before v5.3. I eventually applied
both patches and simply removed the typo fix.

Bart
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index cca749010cd0..5499ec7bc783 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -918,7 +918,7 @@  static int lineevent_create(struct gpio_device *gdev, void __user *ip)
 		goto out_free_label;
 	}
 
-	/* Return an error if a unknown flag is set */
+	/* Return an error if an unknown flag is set */
 	if ((lflags & ~GPIOHANDLE_REQUEST_VALID_FLAGS) ||
 	    (eflags & ~GPIOEVENT_REQUEST_VALID_FLAGS)) {
 		ret = -EINVAL;
@@ -926,7 +926,9 @@  static int lineevent_create(struct gpio_device *gdev, void __user *ip)
 	}
 
 	/* This is just wrong: we don't look for events on output lines */
-	if (lflags & GPIOHANDLE_REQUEST_OUTPUT) {
+	if ((lflags & GPIOHANDLE_REQUEST_OUTPUT) ||
+	    (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) ||
+	    (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)) {
 		ret = -EINVAL;
 		goto out_free_label;
 	}
@@ -940,10 +942,6 @@  static int lineevent_create(struct gpio_device *gdev, void __user *ip)
 
 	if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW)
 		set_bit(FLAG_ACTIVE_LOW, &desc->flags);
-	if (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN)
-		set_bit(FLAG_OPEN_DRAIN, &desc->flags);
-	if (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)
-		set_bit(FLAG_OPEN_SOURCE, &desc->flags);
 
 	ret = gpiod_direction_input(desc);
 	if (ret)