Commit 19314797 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski

gpiolib: fix bitmap operations related to line event watching

When operating on the bits of watched_lines bitmap, we're using
desc_to_gpio() which returns the GPIO number from the global numberspace.
This leads to all sorts of memory corruptions and invalid behavior. We
should switch to using gpio_chip_hwgpio() instead.

Fixes: 51c1064e ("gpiolib: add new ioctl() for monitoring changes in line info")
Reported-by: default avatarKent Gibson <warthog618@gmail.com>
Signed-off-by: default avatarBartosz Golaszewski <bgolaszewski@baylibre.com>
Tested-by: default avatarKent Gibson <warthog618@gmail.com>
parent 48543bd8
...@@ -1261,7 +1261,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1261,7 +1261,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return -EFAULT; return -EFAULT;
if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL) if (cmd == GPIO_GET_LINEINFO_WATCH_IOCTL)
set_bit(desc_to_gpio(desc), priv->watched_lines); set_bit(gpio_chip_hwgpio(desc), priv->watched_lines);
return 0; return 0;
} else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) { } else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) {
...@@ -1276,7 +1276,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -1276,7 +1276,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (IS_ERR(desc)) if (IS_ERR(desc))
return PTR_ERR(desc); return PTR_ERR(desc);
clear_bit(desc_to_gpio(desc), priv->watched_lines); clear_bit(gpio_chip_hwgpio(desc), priv->watched_lines);
return 0; return 0;
} }
return -EINVAL; return -EINVAL;
...@@ -1304,7 +1304,7 @@ static int lineinfo_changed_notify(struct notifier_block *nb, ...@@ -1304,7 +1304,7 @@ static int lineinfo_changed_notify(struct notifier_block *nb,
struct gpio_desc *desc = data; struct gpio_desc *desc = data;
int ret; int ret;
if (!test_bit(desc_to_gpio(desc), priv->watched_lines)) if (!test_bit(gpio_chip_hwgpio(desc), priv->watched_lines))
return NOTIFY_DONE; return NOTIFY_DONE;
memset(&chg, 0, sizeof(chg)); memset(&chg, 0, sizeof(chg));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment