gpio: aggregator: simplify aggr_parse() with scoped bitmap

The bitmap allocated in aggr_parse() is always freed before the function
returns so use __free(bitmap) to simplify it and drop the goto label.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20240930163207.80276-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
Bartosz Golaszewski 2024-09-30 18:32:07 +02:00
parent 700cdf7ed0
commit 22dec5aa59

View File

@ -65,11 +65,11 @@ static int aggr_parse(struct gpio_aggregator *aggr)
{ {
char *args = skip_spaces(aggr->args); char *args = skip_spaces(aggr->args);
char *name, *offsets, *p; char *name, *offsets, *p;
unsigned long *bitmap;
unsigned int i, n = 0; unsigned int i, n = 0;
int error = 0; int error = 0;
bitmap = bitmap_alloc(AGGREGATOR_MAX_GPIOS, GFP_KERNEL); unsigned long *bitmap __free(bitmap) =
bitmap_alloc(AGGREGATOR_MAX_GPIOS, GFP_KERNEL);
if (!bitmap) if (!bitmap)
return -ENOMEM; return -ENOMEM;
@ -82,7 +82,7 @@ static int aggr_parse(struct gpio_aggregator *aggr)
/* Named GPIO line */ /* Named GPIO line */
error = aggr_add_gpio(aggr, name, U16_MAX, &n); error = aggr_add_gpio(aggr, name, U16_MAX, &n);
if (error) if (error)
goto free_bitmap; return error;
name = offsets; name = offsets;
continue; continue;
@ -92,13 +92,13 @@ static int aggr_parse(struct gpio_aggregator *aggr)
error = bitmap_parselist(offsets, bitmap, AGGREGATOR_MAX_GPIOS); error = bitmap_parselist(offsets, bitmap, AGGREGATOR_MAX_GPIOS);
if (error) { if (error) {
pr_err("Cannot parse %s: %d\n", offsets, error); pr_err("Cannot parse %s: %d\n", offsets, error);
goto free_bitmap; return error;
} }
for_each_set_bit(i, bitmap, AGGREGATOR_MAX_GPIOS) { for_each_set_bit(i, bitmap, AGGREGATOR_MAX_GPIOS) {
error = aggr_add_gpio(aggr, name, i, &n); error = aggr_add_gpio(aggr, name, i, &n);
if (error) if (error)
goto free_bitmap; return error;
} }
args = next_arg(args, &name, &p); args = next_arg(args, &name, &p);
@ -106,12 +106,10 @@ static int aggr_parse(struct gpio_aggregator *aggr)
if (!n) { if (!n) {
pr_err("No GPIOs specified\n"); pr_err("No GPIOs specified\n");
error = -EINVAL; return -EINVAL;
} }
free_bitmap: return 0;
bitmap_free(bitmap);
return error;
} }
static ssize_t new_device_store(struct device_driver *driver, const char *buf, static ssize_t new_device_store(struct device_driver *driver, const char *buf,