Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: max3191x: utilize the for_each_set_clump8 macro

Replace verbose implementation in get_multiple callback with
for_each_set_clump8 macro to simplify code and improve clarity.

Link: http://lkml.kernel.org/r/c2b1ed62caf6fce6e5681809a50c05ce6acdf2a6.1570641097.git.vilhelm.gray@gmail.com
Signed-off-by: William Breathitt Gray <vilhelm.gray@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Mathias Duckeck <m.duckeck@kunbus.de>
Cc: Lukas Wunner <lukas@wunner.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: Morten Hein Tiljeset <morten.tiljeset@prevas.dk>
Cc: Phil Reid <preid@electromag.com.au>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Sean Nyekjaer <sean.nyekjaer@prevas.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

William Breathitt Gray and committed by
Linus Torvalds
d077c78b 608bd5fd

+10 -9
+10 -9
drivers/gpio/gpio-max3191x.c
··· 31 31 */ 32 32 33 33 #include <linux/bitmap.h> 34 + #include <linux/bitops.h> 34 35 #include <linux/crc8.h> 35 36 #include <linux/gpio/consumer.h> 36 37 #include <linux/gpio/driver.h> ··· 233 232 unsigned long *bits) 234 233 { 235 234 struct max3191x_chip *max3191x = gpiochip_get_data(gpio); 236 - int ret, bit = 0, wordlen = max3191x_wordlen(max3191x); 235 + const unsigned int wordlen = max3191x_wordlen(max3191x); 236 + int ret; 237 + unsigned long bit; 238 + unsigned long gpio_mask; 239 + unsigned long in; 237 240 238 241 mutex_lock(&max3191x->lock); 239 242 ret = max3191x_readout_locked(max3191x); 240 243 if (ret) 241 244 goto out_unlock; 242 245 243 - while ((bit = find_next_bit(mask, gpio->ngpio, bit)) != gpio->ngpio) { 246 + bitmap_zero(bits, gpio->ngpio); 247 + for_each_set_clump8(bit, gpio_mask, mask, gpio->ngpio) { 244 248 unsigned int chipnum = bit / MAX3191X_NGPIO; 245 - unsigned long in, shift, index; 246 249 247 250 if (max3191x_chip_is_faulting(max3191x, chipnum)) { 248 251 ret = -EIO; ··· 254 249 } 255 250 256 251 in = ((u8 *)max3191x->xfer.rx_buf)[chipnum * wordlen]; 257 - shift = round_down(bit % BITS_PER_LONG, MAX3191X_NGPIO); 258 - index = bit / BITS_PER_LONG; 259 - bits[index] &= ~(mask[index] & (0xff << shift)); 260 - bits[index] |= mask[index] & (in << shift); /* copy bits */ 261 - 262 - bit = (chipnum + 1) * MAX3191X_NGPIO; /* go to next chip */ 252 + in &= gpio_mask; 253 + bitmap_set_value8(bits, in, bit); 263 254 } 264 255 265 256 out_unlock: