linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/3] gpiolib: Switch to for_each_set_bit()
@ 2017-01-03 17:01 Andy Shevchenko
  2017-01-03 17:01 ` [PATCH v1 2/3] gpiolib: Update documentation of struct acpi_gpio_info Andy Shevchenko
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Andy Shevchenko @ 2017-01-03 17:01 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, linux-gpio, Mika Westerberg
  Cc: Andy Shevchenko

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>
---
 drivers/gpio/gpiolib.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index f4c26c7826cd..7f51c9bf5533 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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));
 	}
 }
 
-- 
2.11.0


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

end of thread, other threads:[~2017-01-11 11:10 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-03 17:01 [PATCH v1 1/3] gpiolib: Switch to for_each_set_bit() Andy Shevchenko
2017-01-03 17:01 ` [PATCH v1 2/3] gpiolib: Update documentation of struct acpi_gpio_info Andy Shevchenko
2017-01-04 12:37   ` Mika Westerberg
2017-01-11 11:10   ` Linus Walleij
2017-01-03 17:01 ` [PATCH v1 3/3] gpiolib: Convert fwnode_get_named_gpiod() to configure GPIO Andy Shevchenko
2017-01-04 12:52   ` Mika Westerberg
2017-01-09 13:49     ` Andy Shevchenko
2017-01-09 13:59       ` Mika Westerberg
2017-01-04 12:58 ` [PATCH v1 1/3] gpiolib: Switch to for_each_set_bit() Mika Westerberg
2017-01-11 11:08 ` Linus Walleij

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).