* [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap
@ 2024-09-30 16:32 Bartosz Golaszewski
2024-10-02 13:17 ` Linus Walleij
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2024-09-30 16:32 UTC (permalink / raw)
To: Geert Uytterhoeven, Linus Walleij
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
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.
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpio-aggregator.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
index 38e0fff9afe7..65f41cc3eafc 100644
--- a/drivers/gpio/gpio-aggregator.c
+++ b/drivers/gpio/gpio-aggregator.c
@@ -65,11 +65,11 @@ static int aggr_parse(struct gpio_aggregator *aggr)
{
char *args = skip_spaces(aggr->args);
char *name, *offsets, *p;
- unsigned long *bitmap;
unsigned int i, n = 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)
return -ENOMEM;
@@ -82,7 +82,7 @@ static int aggr_parse(struct gpio_aggregator *aggr)
/* Named GPIO line */
error = aggr_add_gpio(aggr, name, U16_MAX, &n);
if (error)
- goto free_bitmap;
+ return error;
name = offsets;
continue;
@@ -92,13 +92,13 @@ static int aggr_parse(struct gpio_aggregator *aggr)
error = bitmap_parselist(offsets, bitmap, AGGREGATOR_MAX_GPIOS);
if (error) {
pr_err("Cannot parse %s: %d\n", offsets, error);
- goto free_bitmap;
+ return error;
}
for_each_set_bit(i, bitmap, AGGREGATOR_MAX_GPIOS) {
error = aggr_add_gpio(aggr, name, i, &n);
if (error)
- goto free_bitmap;
+ return error;
}
args = next_arg(args, &name, &p);
@@ -106,12 +106,10 @@ static int aggr_parse(struct gpio_aggregator *aggr)
if (!n) {
pr_err("No GPIOs specified\n");
- error = -EINVAL;
+ return -EINVAL;
}
-free_bitmap:
- bitmap_free(bitmap);
- return error;
+ return 0;
}
static ssize_t new_device_store(struct device_driver *driver, const char *buf,
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap
2024-09-30 16:32 [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap Bartosz Golaszewski
@ 2024-10-02 13:17 ` Linus Walleij
2024-10-02 13:31 ` Geert Uytterhoeven
2024-10-02 14:33 ` Bartosz Golaszewski
2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2024-10-02 13:17 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Geert Uytterhoeven, linux-gpio, linux-kernel, Bartosz Golaszewski
On Mon, Sep 30, 2024 at 6:32 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> 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.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Very neat!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap
2024-09-30 16:32 [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap Bartosz Golaszewski
2024-10-02 13:17 ` Linus Walleij
@ 2024-10-02 13:31 ` Geert Uytterhoeven
2024-10-02 14:33 ` Bartosz Golaszewski
2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2024-10-02 13:31 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski
On Mon, Sep 30, 2024 at 6:32 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> 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.
>
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
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] 4+ messages in thread
* Re: [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap
2024-09-30 16:32 [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap Bartosz Golaszewski
2024-10-02 13:17 ` Linus Walleij
2024-10-02 13:31 ` Geert Uytterhoeven
@ 2024-10-02 14:33 ` Bartosz Golaszewski
2 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2024-10-02 14:33 UTC (permalink / raw)
To: Geert Uytterhoeven, Linus Walleij, Bartosz Golaszewski
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
On Mon, 30 Sep 2024 18:32:07 +0200, Bartosz Golaszewski wrote:
> 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.
>
>
Applied, thanks!
[1/1] gpio: aggregator: simplify aggr_parse() with scoped bitmap
commit: 22dec5aa596ef805cccbcd3fbe5ebffbcb4fa559
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-02 14:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-30 16:32 [PATCH] gpio: aggregator: simplify aggr_parse() with scoped bitmap Bartosz Golaszewski
2024-10-02 13:17 ` Linus Walleij
2024-10-02 13:31 ` Geert Uytterhoeven
2024-10-02 14:33 ` Bartosz Golaszewski
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).