Commit 5e4e6fb3 authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Linus Walleij

gpiolib: Switch to for_each_set_bit()

The macro for_each_set_bit() effectively looks up to the next
set bit in array of bits.

Instead of open coding that switch to for_each_set_bit() in
gpio_chip_set_multiple().

While here, make gpio_chip_set_multiple() non-destructive
against its parameters. We are safe since all callers, i.e.
gpiod_set_array_value_complex(), handle that already.
Signed-off-by: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent bb5b0675
#include <linux/bitops.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -2570,18 +2571,11 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip, ...@@ -2570,18 +2571,11 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip,
if (chip->set_multiple) { if (chip->set_multiple) {
chip->set_multiple(chip, mask, bits); chip->set_multiple(chip, mask, bits);
} else { } else {
int i; unsigned int i;
for (i = 0; i < chip->ngpio; i++) {
if (mask[BIT_WORD(i)] == 0) { /* set outputs if the corresponding mask bit is set */
/* no more set bits in this mask word; for_each_set_bit(i, mask, chip->ngpio)
* skip ahead to the next word */ chip->set(chip, i, test_bit(i, bits));
i = (BIT_WORD(i) + 1) * BITS_PER_LONG - 1;
continue;
}
/* set outputs if the corresponding mask bit is set */
if (__test_and_clear_bit(i, mask))
chip->set(chip, i, test_bit(i, bits));
}
} }
} }
......
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