gpiolib: Switch to for_each_set_bit()
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 3 Jan 2017 17:01:17 +0000 (19:01 +0200)
committerLinus Walleij <linus.walleij@linaro.org>
Wed, 11 Jan 2017 11:07:17 +0000 (12:07 +0100)
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: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
drivers/gpio/gpiolib.c

index f4c26c7826cdfc0b5163632e596c0e664586549b..7f51c9bf55330c786db6e36adc0b2578e2e4418a 100644 (file)
@@ -1,3 +1,4 @@
+#include <linux/bitops.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
@@ -2570,18 +2571,11 @@ static void gpio_chip_set_multiple(struct gpio_chip *chip,
        if (chip->set_multiple) {
                chip->set_multiple(chip, mask, bits);
        } else {
-               int i;
-               for (i = 0; i < chip->ngpio; i++) {
-                       if (mask[BIT_WORD(i)] == 0) {
-                               /* no more set bits in this mask word;
-                                * skip ahead to the next word */
-                               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));
-               }
+               unsigned int i;
+
+               /* set outputs if the corresponding mask bit is set */
+               for_each_set_bit(i, mask, chip->ngpio)
+                       chip->set(chip, i, test_bit(i, bits));
        }
 }