summaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib-cdev.c
diff options
context:
space:
mode:
authorKent Gibson <warthog618@gmail.com>2020-07-08 06:15:54 +0200
committerBartosz Golaszewski <bgolaszewski@baylibre.com>2020-07-12 10:22:01 +0200
commit1bf7ba400173c3a134aae3187b550d79c2a5f585 (patch)
tree6cf391acf47f72c23b6f99b280ae63a4a6166081 /drivers/gpio/gpiolib-cdev.c
parentgpiolib: cdev: fix minor race in GET_LINEINFO_WATCH (diff)
downloadlinux-1bf7ba400173c3a134aae3187b550d79c2a5f585.tar.xz
linux-1bf7ba400173c3a134aae3187b550d79c2a5f585.zip
gpiolib: cdev: remove recalculation of offset
Remove recalculation of offset from desc, where desc itself was calculated from offset. There is no benefit from the desc -> hwgpio conversion in this context. The only implicit benefit of the offset -> desc -> hwgpio is the range check in the offset -> desc, but where desc is required you still get that, and where desc isn't required it is simpler to perform the range check directly. Signed-off-by: Kent Gibson <warthog618@gmail.com> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Diffstat (limited to 'drivers/gpio/gpiolib-cdev.c')
-rw-r--r--drivers/gpio/gpiolib-cdev.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index b2b26dc25051..c86fb9305681 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -832,7 +832,6 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
void __user *ip = (void __user *)arg;
struct gpio_desc *desc;
__u32 offset;
- int hwgpio;
/* We fail any subsequent ioctl():s when the chip is gone */
if (!gc)
@@ -860,12 +859,11 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
return -EFAULT;
+ /* this doubles as a range check on line_offset */
desc = gpiochip_get_desc(gc, lineinfo.line_offset);
if (IS_ERR(desc))
return PTR_ERR(desc);
- hwgpio = gpio_chip_hwgpio(desc);
-
gpio_desc_to_lineinfo(desc, &lineinfo);
if (copy_to_user(ip, &lineinfo, sizeof(lineinfo)))
@@ -881,19 +879,18 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (copy_from_user(&lineinfo, ip, sizeof(lineinfo)))
return -EFAULT;
+ /* this doubles as a range check on line_offset */
desc = gpiochip_get_desc(gc, lineinfo.line_offset);
if (IS_ERR(desc))
return PTR_ERR(desc);
- hwgpio = gpio_chip_hwgpio(desc);
-
- if (test_and_set_bit(hwgpio, cdev->watched_lines))
+ if (test_and_set_bit(lineinfo.line_offset, cdev->watched_lines))
return -EBUSY;
gpio_desc_to_lineinfo(desc, &lineinfo);
if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) {
- clear_bit(hwgpio, cdev->watched_lines);
+ clear_bit(lineinfo.line_offset, cdev->watched_lines);
return -EFAULT;
}
@@ -902,13 +899,10 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (copy_from_user(&offset, ip, sizeof(offset)))
return -EFAULT;
- desc = gpiochip_get_desc(gc, offset);
- if (IS_ERR(desc))
- return PTR_ERR(desc);
-
- hwgpio = gpio_chip_hwgpio(desc);
+ if (offset >= cdev->gdev->ngpio)
+ return -EINVAL;
- if (!test_and_clear_bit(hwgpio, cdev->watched_lines))
+ if (!test_and_clear_bit(offset, cdev->watched_lines))
return -EBUSY;
return 0;