From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
linux-gpio@vger.kernel.org,
Mika Westerberg <mika.westerberg@linux.intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 1/3] gpiolib: Switch to for_each_set_bit()
Date: Mon, 9 Jan 2017 16:02:26 +0200 [thread overview]
Message-ID: <20170109140228.47613-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20170109140228.47613-1-andriy.shevchenko@linux.intel.com>
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.
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
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
next prev parent reply other threads:[~2017-01-09 14:03 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-09 14:02 [PATCH v2 0/3] Unify gpiod_get*() API Andy Shevchenko
2017-01-09 14:02 ` Andy Shevchenko [this message]
2017-01-11 11:11 ` [PATCH v2 1/3] gpiolib: Switch to for_each_set_bit() Linus Walleij
2017-01-09 14:02 ` [PATCH v2 2/3] gpiolib: Update documentation of struct acpi_gpio_info Andy Shevchenko
2017-01-11 11:11 ` Linus Walleij
2017-01-11 11:42 ` Andy Shevchenko
2017-01-09 14:02 ` [PATCH v2 3/3] gpiolib: Convert fwnode_get_named_gpiod() to configure GPIO Andy Shevchenko
2017-01-11 12:21 ` Linus Walleij
2017-01-11 13:35 ` Andy Shevchenko
2017-01-11 14:14 ` Andy Shevchenko
2017-01-12 7:27 ` Alexander Stein
2017-01-12 12:15 ` Andy Shevchenko
2017-01-12 12:51 ` Alexander Stein
2017-01-12 14:27 ` Andy Shevchenko
2017-01-17 15:05 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170109140228.47613-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=gnurou@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).