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

Message ID 20191204155912.17590-5-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 ngpio 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, 3 insertions(+), 4 deletions(-)

Comments

Andy Shevchenko Dec. 4, 2019, 10:20 p.m. UTC | #1
On Wed, Dec 4, 2019 at 7:18 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Unduplicate the ngpio check by simply calling gpiochip_get_desc() and
> checking its return value.
>

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

Fun fact, I have for longer than a month a similar series, though not
baked well, and never had time to send it up.
Thanks you did this!

> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/gpio/gpiolib.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index b3ffb079e323..6ef55cc1188b 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -678,14 +678,13 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
>         /* Request each GPIO */
>         for (i = 0; i < handlereq.lines; i++) {
>                 u32 offset = handlereq.lineoffsets[i];
> -               struct gpio_desc *desc;
> +               struct gpio_desc *desc = gpiochip_get_desc(gdev->chip, offset);
>
> -               if (offset >= gdev->ngpio) {
> -                       ret = -EINVAL;
> +               if (IS_ERR(desc)) {
> +                       ret = PTR_ERR(desc);
>                         goto out_free_descs;
>                 }
>
> -               desc = &gdev->descs[offset];
>                 ret = gpiod_request(desc, lh->label);
>                 if (ret)
>                         goto out_free_descs;
> --
> 2.23.0
>

Patch
diff mbox series

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index b3ffb079e323..6ef55cc1188b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -678,14 +678,13 @@  static int linehandle_create(struct gpio_device *gdev, void __user *ip)
 	/* Request each GPIO */
 	for (i = 0; i < handlereq.lines; i++) {
 		u32 offset = handlereq.lineoffsets[i];
-		struct gpio_desc *desc;
+		struct gpio_desc *desc = gpiochip_get_desc(gdev->chip, offset);
 
-		if (offset >= gdev->ngpio) {
-			ret = -EINVAL;
+		if (IS_ERR(desc)) {
+			ret = PTR_ERR(desc);
 			goto out_free_descs;
 		}
 
-		desc = &gdev->descs[offset];
 		ret = gpiod_request(desc, lh->label);
 		if (ret)
 			goto out_free_descs;