summaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorBartosz Golaszewski <bgolaszewski@baylibre.com>2019-12-24 13:07:02 +0100
committerBartosz Golaszewski <bgolaszewski@baylibre.com>2020-01-07 12:03:28 +0100
commit2a2cabd8bc1715ceceb9d9566055f4a0a8ff749a (patch)
tree6bcb9982a99ba349929e484ef5fb83b4d135a119 /drivers/gpio
parentgpiolib: use gpiochip_get_desc() in lineevent_create() (diff)
downloadlinux-2a2cabd8bc1715ceceb9d9566055f4a0a8ff749a.tar.xz
linux-2a2cabd8bc1715ceceb9d9566055f4a0a8ff749a.zip
gpiolib: use gpiochip_get_desc() in gpio_ioctl()
Unduplicate the offset check by simply calling gpiochip_get_desc() and checking its return value. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a11c4ee3e47f..5eef7ddddd0e 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));