Skip to contentSkip to conversation

lib/cmdline: Export next_arg() for being used in modules

PATCH In review Andy Shevchenko 4 participants 10 messages Mar 1, 2021 – Mar 8, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib/cmdline: Export next_arg() for being used in modules

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.

---
 lib/cmdline.c | 1 +
 1 file changed, 1 insertion(+)
lib/cmdline.c +1 -0
index 5d474c626e24..5546bf588780 100644
@@ -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);
Signature · 1 line
2.30.1
#1 lore raw

PATCH 2/2 gpio: aggregator: Replace custom get_arg() with a generic next_arg()

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.

---
 drivers/gpio/gpio-aggregator.c | 39 +++++-----------------------------
 1 file changed, 5 insertions(+), 34 deletions(-)
drivers/gpio/gpio-aggregator.c +5 -34
index 08171431bb8f..34e35b64dcdc 100644
@@ -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) {
Signature · 1 line
2.30.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg()

Quoted 5 lines · Andy Shevchenko

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.

Wow how nice!

Yours,
Linus Walleij

Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg()

In reply to Andy Shevchenko

Hi Andy,

Quoted 5 lines · Andy Shevchenko

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.

Thanks for your patch!

Quoted 6 lines
drivers/gpio/gpio-aggregator.c +0 -0
@@ -93,13 +68,9 @@ static int aggr_parse(struct gpio_aggregator *aggr)
        if (!bitmap)
                return -ENOMEM;
 

drivers/gpio/gpio-aggregator.c static int aggr_parse(struct gpio_aggregator *aggr) · line 73

Quoted 10 lines
drivers/gpio/gpio-aggregator.c +3 -7
-       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.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#4 lore raw

Re: [PATCH v1 2/2] gpio: aggregator: Replace custom get_arg() with a generic next_arg()

Quoted 18 lines · Geert Uytterhoeven

Hi Andy,

Quoted 5 lines · Andy Shevchenko

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.

Thanks for your patch!

Quoted 6 lines
drivers/gpio/gpio-aggregator.c +0 -0
@@ -93,13 +68,9 @@ static int aggr_parse(struct gpio_aggregator *aggr)
        if (!bitmap)
                return -ENOMEM;
 
Quoted 13 lines

drivers/gpio/gpio-aggregator.c static int aggr_parse(struct gpio_aggregator *aggr) · line 73

Quoted 10 lines
drivers/gpio/gpio-aggregator.c +3 -7
-       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).

Quoted 1 line

Thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
Reviewed-by on v1 1/2
#6 lore raw
In reply to Andy Shevchenko
Quoted 5 lines · Andy Shevchenko

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.

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

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
#7 lore raw
Quoted 9 lines · Geert Uytterhoeven
Quoted 5 lines · Andy Shevchenko

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.

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

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
Quoted 12 lines · Andy Shevchenko
Quoted 9 lines · Geert Uytterhoeven
Quoted 5 lines · Andy Shevchenko

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.

Quoted 10 lines

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

#9 lore raw
Quoted 11 lines · Bartosz Golaszewski
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Geert Uytterhoeven
Quoted 5 lines · Andy Shevchenko

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.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

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!

Signature · 2 lines
With Best Regards,
Andy Shevchenko