From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [PATCH 2/2] gpio: aggregator: Use bitmap_parselist() for parsing GPIO offsets
Date: Tue, 23 Jun 2020 16:57:48 +0200 [thread overview]
Message-ID: <20200623145748.28877-3-geert+renesas@glider.be> (raw)
In-Reply-To: <20200623145748.28877-1-geert+renesas@glider.be>
Replace the custom code to parse GPIO offsets and/or GPIO offset ranges
by a call to bitmap_parselist(), and an iteration over the returned bit
mask.
This should have no impact on the format of the configuration parameters
written to the "new_device" virtual file in sysfs.
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
I'm not super happy with the mask[] array, which is on the stack.
But there is no real limit on the number of GPIO lines provided by a
single gpiochip, except for the global ARCH_NR_GPIOS.
---
drivers/gpio/gpio-aggregator.c | 42 ++++++++++++----------------------
1 file changed, 14 insertions(+), 28 deletions(-)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 62a3fcbd4b4bb106..7b2e7abaece9cdb1 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -10,6 +10,7 @@
#include <linux/bitmap.h>
#include <linux/bitops.h>
#include <linux/ctype.h>
+#include <linux/gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/gpio/driver.h>
#include <linux/gpio/machine.h>
@@ -111,9 +112,10 @@ static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key,
static int aggr_parse(struct gpio_aggregator *aggr)
{
- unsigned int first_index, last_index, i, n = 0;
- char *name, *offsets, *first, *last, *next;
+ DECLARE_BITMAP(mask, ARCH_NR_GPIOS);
char *args = aggr->args;
+ unsigned int i, n = 0;
+ char *name, *offsets;
int error;
for (name = get_arg(&args), offsets = get_arg(&args); name;
@@ -134,32 +136,16 @@ static int aggr_parse(struct gpio_aggregator *aggr)
}
/* GPIO chip + offset(s) */
- for (first = offsets; *first; first = next) {
- next = strchrnul(first, ',');
- if (*next)
- *next++ = '\0';
-
- last = strchr(first, '-');
- if (last)
- *last++ = '\0';
-
- if (kstrtouint(first, 10, &first_index)) {
- pr_err("Cannot parse GPIO index %s\n", first);
- return -EINVAL;
- }
-
- if (!last) {
- last_index = first_index;
- } else if (kstrtouint(last, 10, &last_index)) {
- pr_err("Cannot parse GPIO index %s\n", last);
- return -EINVAL;
- }
-
- for (i = first_index; i <= last_index; i++) {
- error = aggr_add_gpio(aggr, name, i, &n);
- if (error)
- return error;
- }
+ error = bitmap_parselist(offsets, mask, ARCH_NR_GPIOS);
+ if (error) {
+ pr_err("Cannot parse %s: %d\n", offsets, error);
+ return error;
+ }
+
+ for_each_set_bit(i, mask, ARCH_NR_GPIOS) {
+ error = aggr_add_gpio(aggr, name, i, &n);
+ if (error)
+ return error;
}
name = get_arg(&args);
--
2.17.1
next prev parent reply other threads:[~2020-06-23 14:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-23 14:57 [PATCH 0/2] gpio: aggregator: Misc parsing improvements Geert Uytterhoeven
2020-06-23 14:57 ` [PATCH 1/2] gpio: aggregator: Drop pre-initialization in get_arg() Geert Uytterhoeven
2020-06-23 14:57 ` Geert Uytterhoeven [this message]
2020-06-24 12:16 ` [PATCH 2/2] gpio: aggregator: Use bitmap_parselist() for parsing GPIO offsets Bartosz Golaszewski
2020-06-24 13:41 ` Andy Shevchenko
2020-06-27 7:57 ` Geert Uytterhoeven
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=20200623145748.28877-3-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=andy.shevchenko@gmail.com \
--cc=bgolaszewski@baylibre.com \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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).