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); }
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
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
linux-stable-mirror@lists.linaro.org