Skip to contentSkip to conversation

gpiolib: Fix the error path order in gpiochip_add_data_with_key()

PATCH In review Andy Shevchenko 2 participants 11 messages Feb 21, 2024 – Mar 1, 2024 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: Fix the error path order in gpiochip_add_data_with_key()

After shuffling the code, error path wasn't updated correctly. Fix it here.

Fixes ba5c5effe02c ("gpio: initialize descriptor SRCU structure before adding OF-based chips")
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
index 4b4812bbcafd..1706edb3ee3f 100644
@@ -1056,6 +1056,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	gpiochip_irqchip_free_valid_mask(gc);
 err_remove_acpi_chip:
 	acpi_gpiochip_remove(gc);
+	gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
 	gpiochip_free_hogs(gc);
 	of_gpiochip_remove(gc);
@@ -1063,7 +1064,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	for (i = 0; i < gdev->ngpio; i++)
 		cleanup_srcu_struct(&gdev->descs[i].srcu);
 err_free_gpiochip_mask:
-	gpiochip_remove_pin_ranges(gc);
 	gpiochip_free_valid_mask(gc);
 err_cleanup_gdev_srcu:
 	cleanup_srcu_struct(&gdev->srcu);
Signature · 1 line
2.43.0.rc1.1.gbec44491f096
#1 lore raw
Quoted 15 lines · Andy Shevchenko

After shuffling the code, error path wasn't updated correctly. Fix it here.

Fixes ba5c5effe02c ("gpio: initialize descriptor SRCU structure before adding OF-based chips")
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +0 -0
index 4b4812bbcafd..1706edb3ee3f 100644

drivers/gpio/gpiolib.c int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · line 1061

Quoted 6 lines
drivers/gpio/gpiolib.c +1 -0
@@ -1056,6 +1056,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
        gpiochip_irqchip_free_valid_mask(gc);
 err_remove_acpi_chip:
        acpi_gpiochip_remove(gc);
+       gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
        gpiochip_free_hogs(gc);

This undoes machine_gpiochip_add() and I think it also needs to be moved before acpi_gpiochip_remove().

Bart

Quoted 12 lines
drivers/gpio/gpiolib.c +0 -2
        of_gpiochip_remove(gc);
@@ -1063,7 +1064,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
        for (i = 0; i < gdev->ngpio; i++)
                cleanup_srcu_struct(&gdev->descs[i].srcu);
 err_free_gpiochip_mask:
-       gpiochip_remove_pin_ranges(gc);
        gpiochip_free_valid_mask(gc);
 err_cleanup_gdev_srcu:
        cleanup_srcu_struct(&gdev->srcu);
--

2.43.0.rc1.1.gbec44491f096

#2 lore raw
Quoted 14 lines · Bartosz Golaszewski
Quoted 11 lines · Andy Shevchenko

After shuffling the code, error path wasn't updated correctly. Fix it here.

        gpiochip_irqchip_free_valid_mask(gc);
 err_remove_acpi_chip:
        acpi_gpiochip_remove(gc);
+       gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
        gpiochip_free_hogs(gc);
        of_gpiochip_remove(gc);
Quoted 2 lines

This undoes machine_gpiochip_add() and I think it also needs to be moved before acpi_gpiochip_remove().

You mean it should be like

       gpiochip_irqchip_free_valid_mask(gc);
       gpiochip_free_hogs(gc);
err_remove_acpi_chip:
       acpi_gpiochip_remove(gc);
       gpiochip_remove_pin_ranges(gc);
err_remove_of_chip:
       of_gpiochip_remove(gc);

?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 28 lines · Andy Shevchenko
Quoted 14 lines · Bartosz Golaszewski
Quoted 11 lines · Andy Shevchenko

After shuffling the code, error path wasn't updated correctly. Fix it here.

        gpiochip_irqchip_free_valid_mask(gc);
 err_remove_acpi_chip:
        acpi_gpiochip_remove(gc);
+       gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
        gpiochip_free_hogs(gc);
        of_gpiochip_remove(gc);
Quoted 2 lines

This undoes machine_gpiochip_add() and I think it also needs to be moved before acpi_gpiochip_remove().

You mean it should be like

       gpiochip_irqchip_free_valid_mask(gc);
       gpiochip_free_hogs(gc);
err_remove_acpi_chip:
       acpi_gpiochip_remove(gc);
       gpiochip_remove_pin_ranges(gc);
err_remove_of_chip:
       of_gpiochip_remove(gc);
Quoted 8 lines

?

--
With Best Regards,
Andy Shevchenko

Yes, because the sequence is:

	ret = of_gpiochip_add(gc);
	if (ret)
		goto err_cleanup_desc_srcu;

	ret = gpiochip_add_pin_ranges(gc);
	if (ret)
		goto err_remove_of_chip;

	acpi_gpiochip_add(gc);

	machine_gpiochip_add(gc);

	ret = gpiochip_irqchip_init_valid_mask(gc);
	if (ret)
		goto err_remove_acpi_chip;

Bartosz

#4 lore raw
Quoted 16 lines · Bartosz Golaszewski
Quoted 14 lines · Andy Shevchenko
Quoted 13 lines · Bartosz Golaszewski
Quoted 10 lines · Andy Shevchenko

After shuffling the code, error path wasn't updated correctly. Fix it here.

        gpiochip_irqchip_free_valid_mask(gc);
 err_remove_acpi_chip:
        acpi_gpiochip_remove(gc);
+       gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
        gpiochip_free_hogs(gc);
        of_gpiochip_remove(gc);
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

This undoes machine_gpiochip_add() and I think it also needs to be moved before acpi_gpiochip_remove().

You mean it should be like

       gpiochip_irqchip_free_valid_mask(gc);

       gpiochip_free_hogs(gc);

But should it be here...

Quoted 1 line
Quoted 1 line

err_remove_acpi_chip:

...or here?

I'm sorry I really need more (morning) coffee, maybe you can simply update yourself or submit a correct fix?

Quoted 24 lines
Quoted 6 lines
       acpi_gpiochip_remove(gc);
       gpiochip_remove_pin_ranges(gc);
err_remove_of_chip:
       of_gpiochip_remove(gc);

?

Yes, because the sequence is:

	ret = of_gpiochip_add(gc);
	if (ret)
		goto err_cleanup_desc_srcu;

	ret = gpiochip_add_pin_ranges(gc);
	if (ret)
		goto err_remove_of_chip;

	acpi_gpiochip_add(gc);

	machine_gpiochip_add(gc);

	ret = gpiochip_irqchip_init_valid_mask(gc);
	if (ret)
		goto err_remove_acpi_chip;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw
Quoted 27 lines · Andy Shevchenko
Quoted 16 lines · Bartosz Golaszewski
Quoted 14 lines · Andy Shevchenko
Quoted 13 lines · Bartosz Golaszewski
Quoted 10 lines · Andy Shevchenko

After shuffling the code, error path wasn't updated correctly. Fix it here.

        gpiochip_irqchip_free_valid_mask(gc);
 err_remove_acpi_chip:
        acpi_gpiochip_remove(gc);
+       gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
        gpiochip_free_hogs(gc);
        of_gpiochip_remove(gc);
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

This undoes machine_gpiochip_add() and I think it also needs to be moved before acpi_gpiochip_remove().

You mean it should be like

       gpiochip_irqchip_free_valid_mask(gc);

       gpiochip_free_hogs(gc);
Quoted 8 lines

But should it be here...

Quoted 1 line
Quoted 1 line

err_remove_acpi_chip:

...or here?

I'm sorry I really need more (morning) coffee, maybe you can simply update yourself or submit a correct fix?

Ok, I'll apply this and send a fix on top of it.

Bart

#6 lore raw
Quoted 8 lines · Bartosz Golaszewski
Quoted 6 lines · Andy Shevchenko
Quoted 5 lines · Bartosz Golaszewski
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Bartosz Golaszewski

On Wed, Feb 21, 2024 at 8:28 PM Andy Shevchenko
<[email protected]> wrote:

...

Quoted 19 lines
Quoted 19 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
        gpiochip_irqchip_free_valid_mask(gc);
 err_remove_acpi_chip:
        acpi_gpiochip_remove(gc);
+       gpiochip_remove_pin_ranges(gc);
 err_remove_of_chip:
        gpiochip_free_hogs(gc);
        of_gpiochip_remove(gc);
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

This undoes machine_gpiochip_add() and I think it also needs to be moved before acpi_gpiochip_remove().

You mean it should be like

       gpiochip_irqchip_free_valid_mask(gc);

       gpiochip_free_hogs(gc);

But should it be here...

Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line

err_remove_acpi_chip:

...or here?

I'm sorry I really need more (morning) coffee, maybe you can simply update yourself or submit a correct fix?

Ok, I'll apply this and send a fix on top of it.

I don't see any progress with this. Do I need to do something?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#7 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines
Quoted 4 lines

I'm sorry I really need more (morning) coffee, maybe you can simply update yourself or submit a correct fix?

Ok, I'll apply this and send a fix on top of it.

I don't see any progress with this. Do I need to do something?

No, it just fell through the cracks. I applied this now and sent my own fix on top.

Bart

#8 lore raw
Quoted 6 lines · Bartosz Golaszewski
Quoted 4 lines · Andy Shevchenko
Quoted 4 lines
Quoted 3 lines

I'm sorry I really need more (morning) coffee, maybe you can simply update yourself or submit a correct fix?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Ok, I'll apply this and send a fix on top of it.

I don't see any progress with this. Do I need to do something?

No, it just fell through the cracks. I applied this now and sent my own fix on top.

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#9 lore raw
Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Bartosz Golaszewski
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines
Quoted 3 lines

I'm sorry I really need more (morning) coffee, maybe you can simply update yourself or submit a correct fix?

Ok, I'll apply this and send a fix on top of it.

I don't see any progress with this. Do I need to do something?

Quoted 10 lines
Quoted 2 lines

No, it just fell through the cracks. I applied this now and sent my own fix on top.

Thank you!

--
With Best Regards,
Andy Shevchenko

Hey!

I now realized that this commit doesn't really fix ba5c5effe02c ("gpio: initialize descriptor SRCU structure before adding OF-based chips"). It addresses an issue introduced as long ago as commit 2f4133bb5f14 ("gpiolib: No need to call gpiochip_remove_pin_ranges() twice").

I will change the Fixes tag, queue it for fixes and send it to Torvalds for rc7, then merge them back into for-next.

Bart

#10 lore raw
Quoted 13 lines · Bartosz Golaszewski
Quoted 11 lines · Andy Shevchenko
Quoted 10 lines · Bartosz Golaszewski
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines
Quoted 3 lines

I'm sorry I really need more (morning) coffee, maybe you can simply update yourself or submit a correct fix?

Ok, I'll apply this and send a fix on top of it.

I don't see any progress with this. Do I need to do something?

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

No, it just fell through the cracks. I applied this now and sent my own fix on top.

I now realized that this commit doesn't really fix ba5c5effe02c ("gpio: initialize descriptor SRCU structure before adding OF-based chips"). It addresses an issue introduced as long ago as commit 2f4133bb5f14 ("gpiolib: No need to call gpiochip_remove_pin_ranges() twice").

Oh, that means it revealed the issue :-)

Quoted 2 lines

I will change the Fixes tag, queue it for fixes and send it to Torvalds for rc7, then merge them back into for-next.

Thank you!

Signature · 2 lines
With Best Regards,
Andy Shevchenko