linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: sim: fix setting and getting multiple lines
@ 2022-04-13 14:01 Bartosz Golaszewski
  2022-04-13 16:53 ` Andy Shevchenko
  0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2022-04-13 14:01 UTC (permalink / raw)
  To: Kent Gibson, Linus Walleij, Andy Shevchenko
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, stable

We need to take mask into account in the set/get_multiple() callbacks.
Use bitmap_replace() instead of bitmap_copy().

Fixes: cb8c474e79be ("gpio: sim: new testing module")
Cc: stable@vger.kernel.org
Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 drivers/gpio/gpio-sim.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 8e5d87984a48..41c31b10ae84 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -134,7 +134,7 @@ static int gpio_sim_get_multiple(struct gpio_chip *gc,
 	struct gpio_sim_chip *chip = gpiochip_get_data(gc);
 
 	mutex_lock(&chip->lock);
-	bitmap_copy(bits, chip->value_map, gc->ngpio);
+	bitmap_replace(bits, bits, chip->value_map, mask, gc->ngpio);
 	mutex_unlock(&chip->lock);
 
 	return 0;
@@ -146,7 +146,7 @@ static void gpio_sim_set_multiple(struct gpio_chip *gc,
 	struct gpio_sim_chip *chip = gpiochip_get_data(gc);
 
 	mutex_lock(&chip->lock);
-	bitmap_copy(chip->value_map, bits, gc->ngpio);
+	bitmap_replace(chip->value_map, chip->value_map, bits, mask, gc->ngpio);
 	mutex_unlock(&chip->lock);
 }
 
-- 
2.32.0


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

* Re: [PATCH] gpio: sim: fix setting and getting multiple lines
  2022-04-13 14:01 [PATCH] gpio: sim: fix setting and getting multiple lines Bartosz Golaszewski
@ 2022-04-13 16:53 ` Andy Shevchenko
  2022-04-13 19:22   ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Andy Shevchenko @ 2022-04-13 16:53 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Kent Gibson, Linus Walleij, linux-gpio, linux-kernel, stable

On Wed, Apr 13, 2022 at 04:01:32PM +0200, Bartosz Golaszewski wrote:
> We need to take mask into account in the set/get_multiple() callbacks.
> Use bitmap_replace() instead of bitmap_copy().

Good catch!
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

> Fixes: cb8c474e79be ("gpio: sim: new testing module")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
> ---
>  drivers/gpio/gpio-sim.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
> index 8e5d87984a48..41c31b10ae84 100644
> --- a/drivers/gpio/gpio-sim.c
> +++ b/drivers/gpio/gpio-sim.c
> @@ -134,7 +134,7 @@ static int gpio_sim_get_multiple(struct gpio_chip *gc,
>  	struct gpio_sim_chip *chip = gpiochip_get_data(gc);
>  
>  	mutex_lock(&chip->lock);
> -	bitmap_copy(bits, chip->value_map, gc->ngpio);
> +	bitmap_replace(bits, bits, chip->value_map, mask, gc->ngpio);
>  	mutex_unlock(&chip->lock);
>  
>  	return 0;
> @@ -146,7 +146,7 @@ static void gpio_sim_set_multiple(struct gpio_chip *gc,
>  	struct gpio_sim_chip *chip = gpiochip_get_data(gc);
>  
>  	mutex_lock(&chip->lock);
> -	bitmap_copy(chip->value_map, bits, gc->ngpio);
> +	bitmap_replace(chip->value_map, chip->value_map, bits, mask, gc->ngpio);
>  	mutex_unlock(&chip->lock);
>  }
>  
> -- 
> 2.32.0
> 

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] gpio: sim: fix setting and getting multiple lines
  2022-04-13 16:53 ` Andy Shevchenko
@ 2022-04-13 19:22   ` Bartosz Golaszewski
  0 siblings, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2022-04-13 19:22 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Kent Gibson, Linus Walleij, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, stable

On Wed, Apr 13, 2022 at 6:57 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Wed, Apr 13, 2022 at 04:01:32PM +0200, Bartosz Golaszewski wrote:
> > We need to take mask into account in the set/get_multiple() callbacks.
> > Use bitmap_replace() instead of bitmap_copy().
>
> Good catch!
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>

I've actually spent two days tracking this. I noticed that a single
test-case in libgpiod v2 fails sometimes (about 1 in 10 runs) and
suspected some race condition but couldn't find any. Turned out it was
triggered by not masking the bits but would only be triggered if the
memory which got passed to the callbacks got written over with some
other values than zeroes.

Bart

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

end of thread, other threads:[~2022-04-13 19:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-13 14:01 [PATCH] gpio: sim: fix setting and getting multiple lines Bartosz Golaszewski
2022-04-13 16:53 ` Andy Shevchenko
2022-04-13 19:22   ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).