Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

authored by

Andy Shevchenko and committed by
Bartosz Golaszewski
ac505b6f 65dd36a3

+5 -34
+5 -34
drivers/gpio/gpio-aggregator.c
··· 37 37 static DEFINE_MUTEX(gpio_aggregator_lock); /* protects idr */ 38 38 static DEFINE_IDR(gpio_aggregator_idr); 39 39 40 - static char *get_arg(char **args) 41 - { 42 - char *start, *end; 43 - 44 - start = skip_spaces(*args); 45 - if (!*start) 46 - return NULL; 47 - 48 - if (*start == '"') { 49 - /* Quoted arg */ 50 - end = strchr(++start, '"'); 51 - if (!end) 52 - return ERR_PTR(-EINVAL); 53 - } else { 54 - /* Unquoted arg */ 55 - for (end = start; *end && !isspace(*end); end++) ; 56 - } 57 - 58 - if (*end) 59 - *end++ = '\0'; 60 - 61 - *args = end; 62 - return start; 63 - } 64 - 65 40 static int aggr_add_gpio(struct gpio_aggregator *aggr, const char *key, 66 41 int hwnum, unsigned int *n) 67 42 { ··· 58 83 59 84 static int aggr_parse(struct gpio_aggregator *aggr) 60 85 { 86 + char *args = skip_spaces(aggr->args); 61 87 char *name, *offsets, *p; 62 - char *args = aggr->args; 63 88 unsigned long *bitmap; 64 89 unsigned int i, n = 0; 65 90 int error = 0; ··· 68 93 if (!bitmap) 69 94 return -ENOMEM; 70 95 71 - for (name = get_arg(&args), offsets = get_arg(&args); name; 72 - offsets = get_arg(&args)) { 73 - if (IS_ERR(name)) { 74 - pr_err("Cannot get GPIO specifier: %pe\n", name); 75 - error = PTR_ERR(name); 76 - goto free_bitmap; 77 - } 96 + args = next_arg(args, &name, &p); 97 + while (*args) { 98 + args = next_arg(args, &offsets, &p); 78 99 79 100 p = get_options(offsets, 0, &error); 80 101 if (error == 0 || *p) { ··· 96 125 goto free_bitmap; 97 126 } 98 127 99 - name = get_arg(&args); 128 + args = next_arg(args, &name, &p); 100 129 } 101 130 102 131 if (!n) {