From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
linux-gpio@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 2/3] gpio: aggregator: Simplify isrange() by using get_option()
Date: Sun, 19 Jul 2020 00:26:07 +0300 [thread overview]
Message-ID: <20200718212608.65328-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20200718212608.65328-1-andriy.shevchenko@linux.intel.com>
We already have a nice helper called get_option() which can be used
to validate the input format. Simplify isrange() by using it.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/gpio/gpio-aggregator.c | 29 ++++++++---------------------
1 file changed, 8 insertions(+), 21 deletions(-)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 5be166e73381..de9ae622ca23 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -64,30 +64,17 @@ static char *get_arg(char **args)
static bool isrange(const char *s)
{
- size_t n;
+ char **args = (char **)&s;
+ int dummy;
+ int res;
- if (IS_ERR_OR_NULL(s))
+ if (IS_ERR_OR_NULL(s) || *s == '\0')
return false;
- while (1) {
- n = strspn(s, "0123456789");
- if (!n)
- return false;
-
- s += n;
-
- switch (*s++) {
- case '\0':
- return true;
-
- case '-':
- case ',':
- break;
-
- default:
- return false;
- }
- }
+ do {
+ res = get_option(args, &dummy);
+ } while (res);
+ return **args == '\0';
}
static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key,
--
2.27.0
next prev parent reply other threads:[~2020-07-18 21:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-18 21:26 [PATCH v1 0/3] gpio: aggregator: Further improvements Andy Shevchenko
2020-07-18 21:26 ` [PATCH v1 1/3] gpio: aggregator: Refactor ->{get,set}_multiple() to make Sparse happy Andy Shevchenko
2020-08-05 14:56 ` Geert Uytterhoeven
2020-08-10 11:09 ` Andy Shevchenko
2020-07-18 21:26 ` Andy Shevchenko [this message]
2020-08-05 14:37 ` [PATCH v1 2/3] gpio: aggregator: Simplify isrange() by using get_option() Geert Uytterhoeven
2020-07-18 21:26 ` [PATCH v1 3/3] gpio: aggregator: Assign name and offsets only once in a loop Andy Shevchenko
2020-07-19 10:12 ` Andy Shevchenko
2020-07-21 9:46 ` [PATCH v1 0/3] gpio: aggregator: Further improvements 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=20200718212608.65328-3-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=bgolaszewski@baylibre.com \
--cc=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@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).