linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: fix resource unwinding order in error path
@ 2024-02-29 17:25 Bartosz Golaszewski
  2024-02-29 18:29 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-02-29 17:25 UTC (permalink / raw)
  To: Linus Walleij, Johan Hovold, Andy Shevchenko
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Hogs are added *after* ACPI so should be removed *before* in error path.

Fixes: 6d86750ce623 ("gpio: fix gpio leak in gpiochip_add error path")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 21edc5eafa68..7fd9c59e73c5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1025,11 +1025,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 
 	ret = gpiochip_irqchip_init_valid_mask(gc);
 	if (ret)
-		goto err_remove_acpi_chip;
+		goto err_free_hogs;
 
 	ret = gpiochip_irqchip_init_hw(gc);
 	if (ret)
-		goto err_remove_acpi_chip;
+		goto err_remove_irqchip_mask;
 
 	ret = gpiochip_add_irqchip(gc, lock_key, request_key);
 	if (ret)
@@ -1054,11 +1054,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	gpiochip_irqchip_remove(gc);
 err_remove_irqchip_mask:
 	gpiochip_irqchip_free_valid_mask(gc);
-err_remove_acpi_chip:
+err_free_hogs:
+	gpiochip_free_hogs(gc);
 	acpi_gpiochip_remove(gc);
 	gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
-	gpiochip_free_hogs(gc);
 	of_gpiochip_remove(gc);
 err_cleanup_desc_srcu:
 	for (i = 0; i < gdev->ngpio; i++)
-- 
2.40.1


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

* Re: [PATCH] gpio: fix resource unwinding order in error path
  2024-02-29 17:25 [PATCH] gpio: fix resource unwinding order in error path Bartosz Golaszewski
@ 2024-02-29 18:29 ` Andy Shevchenko
  2024-03-01  7:57 ` Bartosz Golaszewski
  2024-03-01  8:23 ` Johan Hovold
  2 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2024-02-29 18:29 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Johan Hovold, linux-gpio, linux-kernel,
	Bartosz Golaszewski

On Thu, Feb 29, 2024 at 06:25:49PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> Hogs are added *after* ACPI so should be removed *before* in error path.

Now I got it, thanks for fixing that!

FWIW,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
With Best Regards,
Andy Shevchenko



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

* Re: [PATCH] gpio: fix resource unwinding order in error path
  2024-02-29 17:25 [PATCH] gpio: fix resource unwinding order in error path Bartosz Golaszewski
  2024-02-29 18:29 ` Andy Shevchenko
@ 2024-03-01  7:57 ` Bartosz Golaszewski
  2024-03-01  8:23 ` Johan Hovold
  2 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-03-01  7:57 UTC (permalink / raw)
  To: Linus Walleij, Johan Hovold, Andy Shevchenko
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

On Thu, Feb 29, 2024 at 6:25 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Hogs are added *after* ACPI so should be removed *before* in error path.
>
> Fixes: 6d86750ce623 ("gpio: fix gpio leak in gpiochip_add error path")
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
>  drivers/gpio/gpiolib.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 21edc5eafa68..7fd9c59e73c5 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1025,11 +1025,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
>
>         ret = gpiochip_irqchip_init_valid_mask(gc);
>         if (ret)
> -               goto err_remove_acpi_chip;
> +               goto err_free_hogs;
>
>         ret = gpiochip_irqchip_init_hw(gc);
>         if (ret)
> -               goto err_remove_acpi_chip;
> +               goto err_remove_irqchip_mask;
>
>         ret = gpiochip_add_irqchip(gc, lock_key, request_key);
>         if (ret)
> @@ -1054,11 +1054,11 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
>         gpiochip_irqchip_remove(gc);
>  err_remove_irqchip_mask:
>         gpiochip_irqchip_free_valid_mask(gc);
> -err_remove_acpi_chip:
> +err_free_hogs:
> +       gpiochip_free_hogs(gc);
>         acpi_gpiochip_remove(gc);
>         gpiochip_remove_pin_ranges(gc);
>  err_remove_of_chip:
> -       gpiochip_free_hogs(gc);
>         of_gpiochip_remove(gc);
>  err_cleanup_desc_srcu:
>         for (i = 0; i < gdev->ngpio; i++)
> --
> 2.40.1
>

Queued for fixes.

Bart

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

* Re: [PATCH] gpio: fix resource unwinding order in error path
  2024-02-29 17:25 [PATCH] gpio: fix resource unwinding order in error path Bartosz Golaszewski
  2024-02-29 18:29 ` Andy Shevchenko
  2024-03-01  7:57 ` Bartosz Golaszewski
@ 2024-03-01  8:23 ` Johan Hovold
  2024-03-01  8:30   ` Bartosz Golaszewski
  2 siblings, 1 reply; 5+ messages in thread
From: Johan Hovold @ 2024-03-01  8:23 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Andy Shevchenko, linux-gpio, linux-kernel,
	Bartosz Golaszewski

On Thu, Feb 29, 2024 at 06:25:49PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> 
> Hogs are added *after* ACPI so should be removed *before* in error path.
> 
> Fixes: 6d86750ce623 ("gpio: fix gpio leak in gpiochip_add error path")

This Fixes tag is not correct. Back then hogs were only implemented by
OF so you need to find another commit to blame here.

	git grep -pW '^int gpiochip_add(' 6d86750ce62391f5a0a7985d5c050c2e3c823ab9

Johan

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

* Re: [PATCH] gpio: fix resource unwinding order in error path
  2024-03-01  8:23 ` Johan Hovold
@ 2024-03-01  8:30   ` Bartosz Golaszewski
  0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2024-03-01  8:30 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Linus Walleij, Andy Shevchenko, linux-gpio, linux-kernel,
	Bartosz Golaszewski

On Fri, Mar 1, 2024 at 9:23 AM Johan Hovold <johan@kernel.org> wrote:
>
> On Thu, Feb 29, 2024 at 06:25:49PM +0100, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > Hogs are added *after* ACPI so should be removed *before* in error path.
> >
> > Fixes: 6d86750ce623 ("gpio: fix gpio leak in gpiochip_add error path")
>
> This Fixes tag is not correct. Back then hogs were only implemented by
> OF so you need to find another commit to blame here.
>
>         git grep -pW '^int gpiochip_add(' 6d86750ce62391f5a0a7985d5c050c2e3c823ab9
>
> Johan

Ah, indeed, looks like it's me who really borked with commit
a411e81e61df ("gpiolib: add hogs support for machine code").

Let me fix that right up.

Bart

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

end of thread, other threads:[~2024-03-01  8:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-29 17:25 [PATCH] gpio: fix resource unwinding order in error path Bartosz Golaszewski
2024-02-29 18:29 ` Andy Shevchenko
2024-03-01  7:57 ` Bartosz Golaszewski
2024-03-01  8:23 ` Johan Hovold
2024-03-01  8:30   ` 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).