Skip to content

Commit 761b5c3

Browse files
andy-shevlinusw
authored andcommitted
gpio: mmio: replace open-coded for_each_set_bit()
Use for_each_set_bit() instead of open-coding it to simplify the code. Signed-off-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 4dc5794 commit 761b5c3

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

drivers/gpio/gpio-mmio.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,7 @@ static int bgpio_get_multiple_be(struct gpio_chip *gc, unsigned long *mask,
195195
*bits &= ~*mask;
196196

197197
/* Create a mirrored mask */
198-
bit = -1;
199-
while ((bit = find_next_bit(mask, gc->ngpio, bit + 1)) < gc->ngpio)
198+
for_each_set_bit(bit, mask, gc->ngpio)
200199
readmask |= bgpio_line2mask(gc, bit);
201200

202201
/* Read the register */
@@ -206,8 +205,7 @@ static int bgpio_get_multiple_be(struct gpio_chip *gc, unsigned long *mask,
206205
* Mirror the result into the "bits" result, this will give line 0
207206
* in bit 0 ... line 31 in bit 31 for a 32bit register.
208207
*/
209-
bit = -1;
210-
while ((bit = find_next_bit(&val, gc->ngpio, bit + 1)) < gc->ngpio)
208+
for_each_set_bit(bit, &val, gc->ngpio)
211209
*bits |= bgpio_line2mask(gc, bit);
212210

213211
return 0;
@@ -272,15 +270,11 @@ static void bgpio_multiple_get_masks(struct gpio_chip *gc,
272270
*set_mask = 0;
273271
*clear_mask = 0;
274272

275-
for (i = 0; i < gc->bgpio_bits; i++) {
276-
if (*mask == 0)
277-
break;
278-
if (__test_and_clear_bit(i, mask)) {
279-
if (test_bit(i, bits))
280-
*set_mask |= bgpio_line2mask(gc, i);
281-
else
282-
*clear_mask |= bgpio_line2mask(gc, i);
283-
}
273+
for_each_set_bit(i, mask, gc->bgpio_bits) {
274+
if (test_bit(i, bits))
275+
*set_mask |= bgpio_line2mask(gc, i);
276+
else
277+
*clear_mask |= bgpio_line2mask(gc, i);
284278
}
285279
}
286280

0 commit comments

Comments
 (0)