linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules
@ 2021-03-01 16:59 Andy Shevchenko
  2021-03-01 16:59 ` [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg() Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Andy Shevchenko @ 2021-03-01 16:59 UTC (permalink / raw)
  To: Geert Uytterhoeven, Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski

At least one module will benefit from using next_arg() helper.
Let's export it for that module and others if they consider it
helpful.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 lib/cmdline.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/cmdline.c b/lib/cmdline.c
index 5d474c626e24..5546bf588780 100644
--- a/lib/cmdline.c
+++ b/lib/cmdline.c
@@ -272,3 +272,4 @@ char *next_arg(char *args, char **param, char **val)
 	/* Chew up trailing spaces. */
 	return skip_spaces(args);
 }
+EXPORT_SYMBOL(next_arg);
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg()
  2021-03-01 16:59 [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules Andy Shevchenko
@ 2021-03-01 16:59 ` Andy Shevchenko
  2021-03-02 16:09   ` Linus Walleij
  2021-03-04  9:01   ` Geert Uytterhoeven
  2021-03-02 16:24 ` [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules Linus Walleij
  2021-03-04  8:53 ` Geert Uytterhoeven
  2 siblings, 2 replies; 10+ messages in thread
From: Andy Shevchenko @ 2021-03-01 16:59 UTC (permalink / raw)
  To: Geert Uytterhoeven, Andy Shevchenko, linux-gpio, linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski

cmdline library provides next_arg() helper to traverse over parameters
and their values given in command line. Replace custom approach in the driver
by it.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-aggregator.c | 39 +++++-----------------------------
 1 file changed, 5 insertions(+), 34 deletions(-)

diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 08171431bb8f..34e35b64dcdc 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -37,31 +37,6 @@ struct gpio_aggregator {
 static DEFINE_MUTEX(gpio_aggregator_lock);	/* protects idr */
 static DEFINE_IDR(gpio_aggregator_idr);
 
-static char *get_arg(char **args)
-{
-	char *start, *end;
-
-	start = skip_spaces(*args);
-	if (!*start)
-		return NULL;
-
-	if (*start == '"') {
-		/* Quoted arg */
-		end = strchr(++start, '"');
-		if (!end)
-			return ERR_PTR(-EINVAL);
-	} else {
-		/* Unquoted arg */
-		for (end = start; *end && !isspace(*end); end++) ;
-	}
-
-	if (*end)
-		*end++ = '\0';
-
-	*args = end;
-	return start;
-}
-
 static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key,
 			 int hwnum, unsigned int *n)
 {
@@ -83,8 +58,8 @@ static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key,
 
 static int aggr_parse(struct gpio_aggregator *aggr)
 {
+	char *args = skip_spaces(aggr->args);
 	char *name, *offsets, *p;
-	char *args = aggr->args;
 	unsigned long *bitmap;
 	unsigned int i, n = 0;
 	int error = 0;
@@ -93,13 +68,9 @@ static int aggr_parse(struct gpio_aggregator *aggr)
 	if (!bitmap)
 		return -ENOMEM;
 
-	for (name = get_arg(&args), offsets = get_arg(&args); name;
-	     offsets = get_arg(&args)) {
-		if (IS_ERR(name)) {
-			pr_err("Cannot get GPIO specifier: %pe\n", name);
-			error = PTR_ERR(name);
-			goto free_bitmap;
-		}
+	args = next_arg(args, &name, &p);
+	while (*args) {
+		args = next_arg(args, &offsets, &p);
 
 		p = get_options(offsets, 0, &error);
 		if (error == 0 || *p) {
@@ -125,7 +96,7 @@ static int aggr_parse(struct gpio_aggregator *aggr)
 				goto free_bitmap;
 		}
 
-		name = get_arg(&args);
+		args = next_arg(args, &name, &p);
 	}
 
 	if (!n) {
-- 
2.30.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg()
  2021-03-01 16:59 ` [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg() Andy Shevchenko
@ 2021-03-02 16:09   ` Linus Walleij
  2021-03-04  9:01   ` Geert Uytterhoeven
  1 sibling, 0 replies; 10+ messages in thread
From: Linus Walleij @ 2021-03-02 16:09 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Geert Uytterhoeven, open list:GPIO SUBSYSTEM, linux-kernel,
	Bartosz Golaszewski

On Mon, Mar 1, 2021 at 6:00 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> cmdline library provides next_arg() helper to traverse over parameters
> and their values given in command line. Replace custom approach in the driver
> by it.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Wow how nice!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules
  2021-03-01 16:59 [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules Andy Shevchenko
  2021-03-01 16:59 ` [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg() Andy Shevchenko
@ 2021-03-02 16:24 ` Linus Walleij
  2021-03-04  8:53 ` Geert Uytterhoeven
  2 siblings, 0 replies; 10+ messages in thread
From: Linus Walleij @ 2021-03-02 16:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Geert Uytterhoeven, open list:GPIO SUBSYSTEM, linux-kernel,
	Bartosz Golaszewski

On Mon, Mar 1, 2021 at 6:00 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:

> At least one module will benefit from using next_arg() helper.
> Let's export it for that module and others if they consider it
> helpful.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules
  2021-03-01 16:59 [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules Andy Shevchenko
  2021-03-01 16:59 ` [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg() Andy Shevchenko
  2021-03-02 16:24 ` [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules Linus Walleij
@ 2021-03-04  8:53 ` Geert Uytterhoeven
  2021-03-04 10:59   ` Andy Shevchenko
  2 siblings, 1 reply; 10+ messages in thread
From: Geert Uytterhoeven @ 2021-03-04  8:53 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Linux Kernel Mailing List,
	Linus Walleij, Bartosz Golaszewski

On Mon, Mar 1, 2021 at 6:00 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> At least one module will benefit from using next_arg() helper.
> Let's export it for that module and others if they consider it
> helpful.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg()
  2021-03-01 16:59 ` [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg() Andy Shevchenko
  2021-03-02 16:09   ` Linus Walleij
@ 2021-03-04  9:01   ` Geert Uytterhoeven
  2021-03-04 10:58     ` Andy Shevchenko
  1 sibling, 1 reply; 10+ messages in thread
From: Geert Uytterhoeven @ 2021-03-04  9:01 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Linux Kernel Mailing List,
	Linus Walleij, Bartosz Golaszewski

Hi Andy,

On Mon, Mar 1, 2021 at 5:59 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> cmdline library provides next_arg() helper to traverse over parameters
> and their values given in command line. Replace custom approach in the driver
> by it.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks for your patch!

> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -93,13 +68,9 @@ static int aggr_parse(struct gpio_aggregator *aggr)
>         if (!bitmap)
>                 return -ENOMEM;
>
> -       for (name = get_arg(&args), offsets = get_arg(&args); name;
> -            offsets = get_arg(&args)) {
> -               if (IS_ERR(name)) {
> -                       pr_err("Cannot get GPIO specifier: %pe\n", name);
> -                       error = PTR_ERR(name);
> -                       goto free_bitmap;
> -               }
> +       args = next_arg(args, &name, &p);
> +       while (*args) {
> +               args = next_arg(args, &offsets, &p);

As name and offsets should not contain equal signs (can they?),
I guess using next_arg() is fine.

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg()
  2021-03-04  9:01   ` Geert Uytterhoeven
@ 2021-03-04 10:58     ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2021-03-04 10:58 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: open list:GPIO SUBSYSTEM, Linux Kernel Mailing List,
	Linus Walleij, Bartosz Golaszewski

On Thu, Mar 04, 2021 at 10:01:46AM +0100, Geert Uytterhoeven wrote:
> Hi Andy,
> 
> On Mon, Mar 1, 2021 at 5:59 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > cmdline library provides next_arg() helper to traverse over parameters
> > and their values given in command line. Replace custom approach in the driver
> > by it.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Thanks for your patch!
> 
> > --- a/drivers/gpio/gpio-aggregator.c
> > +++ b/drivers/gpio/gpio-aggregator.c
> > @@ -93,13 +68,9 @@ static int aggr_parse(struct gpio_aggregator *aggr)
> >         if (!bitmap)
> >                 return -ENOMEM;
> >
> > -       for (name = get_arg(&args), offsets = get_arg(&args); name;
> > -            offsets = get_arg(&args)) {
> > -               if (IS_ERR(name)) {
> > -                       pr_err("Cannot get GPIO specifier: %pe\n", name);
> > -                       error = PTR_ERR(name);
> > -                       goto free_bitmap;
> > -               }
> > +       args = next_arg(args, &name, &p);
> > +       while (*args) {
> > +               args = next_arg(args, &offsets, &p);
> 
> As name and offsets should not contain equal signs (can they?),
> I guess using next_arg() is fine.

Even though we can use double quotes (AFAICU the next_arg() code).

> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Thanks!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules
  2021-03-04  8:53 ` Geert Uytterhoeven
@ 2021-03-04 10:59   ` Andy Shevchenko
  2021-03-08 15:38     ` Bartosz Golaszewski
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2021-03-04 10:59 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: open list:GPIO SUBSYSTEM, Linux Kernel Mailing List,
	Linus Walleij, Bartosz Golaszewski

On Thu, Mar 04, 2021 at 09:53:28AM +0100, Geert Uytterhoeven wrote:
> On Mon, Mar 1, 2021 at 6:00 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > At least one module will benefit from using next_arg() helper.
> > Let's export it for that module and others if they consider it
> > helpful.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> 
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Thanks Geert and Linus!

Bart, do you want me to add it to my usual PR or you want to take it yourself
(I have no dependencies in my tree on this anyway)?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules
  2021-03-04 10:59   ` Andy Shevchenko
@ 2021-03-08 15:38     ` Bartosz Golaszewski
  2021-03-08 16:36       ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Bartosz Golaszewski @ 2021-03-08 15:38 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Geert Uytterhoeven, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, Linus Walleij

On Thu, Mar 4, 2021 at 12:01 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Thu, Mar 04, 2021 at 09:53:28AM +0100, Geert Uytterhoeven wrote:
> > On Mon, Mar 1, 2021 at 6:00 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > > At least one module will benefit from using next_arg() helper.
> > > Let's export it for that module and others if they consider it
> > > helpful.
> > >
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> >
> > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> Thanks Geert and Linus!
>
> Bart, do you want me to add it to my usual PR or you want to take it yourself
> (I have no dependencies in my tree on this anyway)?
>
> --
> With Best Regards,
> Andy Shevchenko
>
>

Please send it with your PR.

Bart

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules
  2021-03-08 15:38     ` Bartosz Golaszewski
@ 2021-03-08 16:36       ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2021-03-08 16:36 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Geert Uytterhoeven, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List, Linus Walleij

On Mon, Mar 08, 2021 at 04:38:42PM +0100, Bartosz Golaszewski wrote:
> On Thu, Mar 4, 2021 at 12:01 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > On Thu, Mar 04, 2021 at 09:53:28AM +0100, Geert Uytterhoeven wrote:
> > > On Mon, Mar 1, 2021 at 6:00 PM Andy Shevchenko
> > > <andriy.shevchenko@linux.intel.com> wrote:
> > > > At least one module will benefit from using next_arg() helper.
> > > > Let's export it for that module and others if they consider it
> > > > helpful.
> > > >
> > > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > >
> > > Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
> >
> > Thanks Geert and Linus!
> >
> > Bart, do you want me to add it to my usual PR or you want to take it yourself
> > (I have no dependencies in my tree on this anyway)?
> 
> Please send it with your PR.

Will do, thanks!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-03-08 16:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01 16:59 [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules Andy Shevchenko
2021-03-01 16:59 ` [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg() Andy Shevchenko
2021-03-02 16:09   ` Linus Walleij
2021-03-04  9:01   ` Geert Uytterhoeven
2021-03-04 10:58     ` Andy Shevchenko
2021-03-02 16:24 ` [PATCH v1 1/2] lib/cmdline: Export next_arg() for being used in modules Linus Walleij
2021-03-04  8:53 ` Geert Uytterhoeven
2021-03-04 10:59   ` Andy Shevchenko
2021-03-08 15:38     ` Bartosz Golaszewski
2021-03-08 16:36       ` Andy Shevchenko

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).