All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpiolib: fix bitmap operations related to line event watching
@ 2020-02-26 13:53 Bartosz Golaszewski
  2020-02-26 14:57 ` Kent Gibson
  2020-02-28 23:20 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2020-02-26 13:53 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Kent Gibson

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

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: 51c1064e82e7 ("gpiolib: add new ioctl() for monitoring changes in line info")
Reported-by: Kent Gibson <warthog618@gmail.com>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpiolib.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a5cd1b4abe6f..5cc80f6f79e0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1261,7 +1261,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 			return -EFAULT;
 
 		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;
 	} else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) {
@@ -1276,7 +1276,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 		if (IS_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 -EINVAL;
@@ -1304,7 +1304,7 @@ static int lineinfo_changed_notify(struct notifier_block *nb,
 	struct gpio_desc *desc = data;
 	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;
 
 	memset(&chg, 0, sizeof(chg));
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: fix bitmap operations related to line event watching
  2020-02-26 13:53 [PATCH] gpiolib: fix bitmap operations related to line event watching Bartosz Golaszewski
@ 2020-02-26 14:57 ` Kent Gibson
  2020-02-28 23:20 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Kent Gibson @ 2020-02-26 14:57 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski

On Wed, Feb 26, 2020 at 02:53:23PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> 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: 51c1064e82e7 ("gpiolib: add new ioctl() for monitoring changes in line info")
> Reported-by: Kent Gibson <warthog618@gmail.com>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

That fixes all the failures I was seeing.

Tested-by: Kent Gibson <warthog618@gmail.com>

> ---
>  drivers/gpio/gpiolib.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index a5cd1b4abe6f..5cc80f6f79e0 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1261,7 +1261,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  			return -EFAULT;
>  
>  		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;
>  	} else if (cmd == GPIO_GET_LINEHANDLE_IOCTL) {
> @@ -1276,7 +1276,7 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  		if (IS_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 -EINVAL;
> @@ -1304,7 +1304,7 @@ static int lineinfo_changed_notify(struct notifier_block *nb,
>  	struct gpio_desc *desc = data;
>  	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;
>  
>  	memset(&chg, 0, sizeof(chg));
> -- 
> 2.25.0
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: fix bitmap operations related to line event watching
  2020-02-26 13:53 [PATCH] gpiolib: fix bitmap operations related to line event watching Bartosz Golaszewski
  2020-02-26 14:57 ` Kent Gibson
@ 2020-02-28 23:20 ` Linus Walleij
  2020-02-29 13:43   ` Bartosz Golaszewski
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2020-02-28 23:20 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski, Kent Gibson

On Wed, Feb 26, 2020 at 2:53 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> 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: 51c1064e82e7 ("gpiolib: add new ioctl() for monitoring changes in line info")
> Reported-by: Kent Gibson <warthog618@gmail.com>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

This looks good but where should it be applied?
It fails to apply to my devel branch where this lives.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] gpiolib: fix bitmap operations related to line event watching
  2020-02-28 23:20 ` Linus Walleij
@ 2020-02-29 13:43   ` Bartosz Golaszewski
  0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2020-02-29 13:43 UTC (permalink / raw)
  To: Linus Walleij
  Cc: open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski, Kent Gibson

sob., 29 lut 2020 o 00:20 Linus Walleij <linus.walleij@linaro.org> napisał(a):
>
> On Wed, Feb 26, 2020 at 2:53 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > 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: 51c1064e82e7 ("gpiolib: add new ioctl() for monitoring changes in line info")
> > Reported-by: Kent Gibson <warthog618@gmail.com>
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> This looks good but where should it be applied?
> It fails to apply to my devel branch where this lives.
>
> Yours,
> Linus Walleij

This depends on Kent's other patch. I'll send you a PR.

Bart

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-02-29 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 13:53 [PATCH] gpiolib: fix bitmap operations related to line event watching Bartosz Golaszewski
2020-02-26 14:57 ` Kent Gibson
2020-02-28 23:20 ` Linus Walleij
2020-02-29 13:43   ` Bartosz Golaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.