Skip to contentSkip to conversation

gpio: fix resource unwinding order in error path

PATCH In review Bartosz Golaszewski 3 participants 5 messages Feb 29, 2024 – Mar 1, 2024 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: fix resource unwinding order in error path

From: Bartosz Golaszewski <[email protected]>

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

Fixes 6d86750ce623 ("gpio: fix gpio leak in gpiochip_add error path")
---
 drivers/gpio/gpiolib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib.c +4 -4
index 21edc5eafa68..7fd9c59e73c5 100644
@@ -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++)
Signature · 1 line
2.40.1
#2 lore raw
In reply to Bartosz Golaszewski
Quoted 44 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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

Fixes 6d86750ce623 ("gpio: fix gpio leak in gpiochip_add error path")
---
 drivers/gpio/gpiolib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpio/gpiolib.c +4 -5
index 21edc5eafa68..7fd9c59e73c5 100644
@@ -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++)
--
Quoted 2 lines

2.40.1

Queued for fixes.

Bart

#3 lore raw
In reply to Bartosz Golaszewski
Quoted 5 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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

#4 lore raw
Quoted 6 lines · Johan Hovold
Quoted 4 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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

Quoted 8 lines
Quoted 1 line
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