[v2,06/11] gpiolib: use gpiochip_get_desc() in gpio_ioctl()
diff mbox series

Message ID 20191204155912.17590-7-brgl@bgdev.pl
State New
Headers show
Series
  • gpiolib: add an ioctl() for monitoring line status changes
Related show

Commit Message

Bartosz Golaszewski Dec. 4, 2019, 3:59 p.m. UTC
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Unduplicate the offset check by simply calling gpiochip_get_desc() and
checking its return value.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpiolib.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Rainer Sickinger Dec. 4, 2019, 4:25 p.m. UTC | #1
GREAT WORK

Am Mi., 4. Dez. 2019 um 17:04 Uhr schrieb Bartosz Golaszewski <brgl@bgdev.pl>:
>
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Unduplicate the offset check by simply calling gpiochip_get_desc() and
> checking its return value.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/gpio/gpiolib.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 17796437d7be..b7043946c029 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1175,10 +1175,11 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>
>                 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
>                         return -EFAULT;
> -               if (lineinfo.line_offset >= gdev->ngpio)
> -                       return -EINVAL;
>
> -               desc = &gdev->descs[lineinfo.line_offset];
> +               desc = gpiochip_get_desc(chip, lineinfo.line_offset);
> +               if (IS_ERR(desc))
> +                       return PTR_ERR(desc);
> +
>                 if (desc->name) {
>                         strncpy(lineinfo.name, desc->name,
>                                 sizeof(lineinfo.name));
> --
> 2.23.0
>
Andy Shevchenko Dec. 4, 2019, 10:21 p.m. UTC | #2
On Wed, Dec 4, 2019 at 6:04 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Unduplicate the offset check by simply calling gpiochip_get_desc() and
> checking its return value.
>

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>


> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/gpio/gpiolib.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 17796437d7be..b7043946c029 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1175,10 +1175,11 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>
>                 if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
>                         return -EFAULT;
> -               if (lineinfo.line_offset >= gdev->ngpio)
> -                       return -EINVAL;
>
> -               desc = &gdev->descs[lineinfo.line_offset];
> +               desc = gpiochip_get_desc(chip, lineinfo.line_offset);
> +               if (IS_ERR(desc))
> +                       return PTR_ERR(desc);
> +
>                 if (desc->name) {
>                         strncpy(lineinfo.name, desc->name,
>                                 sizeof(lineinfo.name));
> --
> 2.23.0
>

Patch
diff mbox series

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 17796437d7be..b7043946c029 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1175,10 +1175,11 @@  static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 
 		if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
 			return -EFAULT;
-		if (lineinfo.line_offset >= gdev->ngpio)
-			return -EINVAL;
 
-		desc = &gdev->descs[lineinfo.line_offset];
+		desc = gpiochip_get_desc(chip, lineinfo.line_offset);
+		if (IS_ERR(desc))
+			return PTR_ERR(desc);
+
 		if (desc->name) {
 			strncpy(lineinfo.name, desc->name,
 				sizeof(lineinfo.name));