linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure
@ 2025-06-04  8:38 Geert Uytterhoeven
  2025-06-04 17:23 ` Manivannan Sadhasivam
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2025-06-04  8:38 UTC (permalink / raw)
  To: Bartosz Golaszewski, Bjorn Helgaas, Krzysztof Wilczyński,
	Manivannan Sadhasivam, Marek Vasut
  Cc: linux-pci, linux-kernel, Geert Uytterhoeven

When devm_add_action_or_reset() fails, it calls the passed cleanup
function.  Hence the caller must not repeat that cleanup.

Replace the "goto err_regulator_free" by the actual freeing, as there
will never be a need again for a second user of this label.

Fixes: 75996c92f4de309f ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
Compile-tested only.
---
 drivers/pci/pwrctrl/slot.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/pwrctrl/slot.c b/drivers/pci/pwrctrl/slot.c
index 18becc144913e047..26b21746da50baa4 100644
--- a/drivers/pci/pwrctrl/slot.c
+++ b/drivers/pci/pwrctrl/slot.c
@@ -47,13 +47,14 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)
 	ret = regulator_bulk_enable(slot->num_supplies, slot->supplies);
 	if (ret < 0) {
 		dev_err_probe(dev, ret, "Failed to enable slot regulators\n");
-		goto err_regulator_free;
+		regulator_bulk_free(slot->num_supplies, slot->supplies);
+		return ret;
 	}
 
 	ret = devm_add_action_or_reset(dev, devm_pci_pwrctrl_slot_power_off,
 				       slot);
 	if (ret)
-		goto err_regulator_disable;
+		return ret;
 
 	pci_pwrctrl_init(&slot->ctx, dev);
 
@@ -62,13 +63,6 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, ret, "Failed to register pwrctrl driver\n");
 
 	return 0;
-
-err_regulator_disable:
-	regulator_bulk_disable(slot->num_supplies, slot->supplies);
-err_regulator_free:
-	regulator_bulk_free(slot->num_supplies, slot->supplies);
-
-	return ret;
 }
 
 static const struct of_device_id pci_pwrctrl_slot_of_match[] = {
-- 
2.43.0


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

* Re: [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure
  2025-06-04  8:38 [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure Geert Uytterhoeven
@ 2025-06-04 17:23 ` Manivannan Sadhasivam
  2025-06-08 13:43 ` Marek Vasut
  2025-06-10  8:11 ` Bartosz Golaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Manivannan Sadhasivam @ 2025-06-04 17:23 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bartosz Golaszewski, Bjorn Helgaas, Krzysztof Wilczyński,
	Marek Vasut, linux-pci, linux-kernel

On Wed, Jun 04, 2025 at 10:38:33AM +0200, Geert Uytterhoeven wrote:
> When devm_add_action_or_reset() fails, it calls the passed cleanup
> function.  Hence the caller must not repeat that cleanup.
> 
> Replace the "goto err_regulator_free" by the actual freeing, as there
> will never be a need again for a second user of this label.
> 
> Fixes: 75996c92f4de309f ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> ---
> Compile-tested only.
> ---
>  drivers/pci/pwrctrl/slot.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pci/pwrctrl/slot.c b/drivers/pci/pwrctrl/slot.c
> index 18becc144913e047..26b21746da50baa4 100644
> --- a/drivers/pci/pwrctrl/slot.c
> +++ b/drivers/pci/pwrctrl/slot.c
> @@ -47,13 +47,14 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)
>  	ret = regulator_bulk_enable(slot->num_supplies, slot->supplies);
>  	if (ret < 0) {
>  		dev_err_probe(dev, ret, "Failed to enable slot regulators\n");
> -		goto err_regulator_free;
> +		regulator_bulk_free(slot->num_supplies, slot->supplies);
> +		return ret;
>  	}
>  
>  	ret = devm_add_action_or_reset(dev, devm_pci_pwrctrl_slot_power_off,
>  				       slot);
>  	if (ret)
> -		goto err_regulator_disable;
> +		return ret;
>  
>  	pci_pwrctrl_init(&slot->ctx, dev);
>  
> @@ -62,13 +63,6 @@ static int pci_pwrctrl_slot_probe(struct platform_device *pdev)
>  		return dev_err_probe(dev, ret, "Failed to register pwrctrl driver\n");
>  
>  	return 0;
> -
> -err_regulator_disable:
> -	regulator_bulk_disable(slot->num_supplies, slot->supplies);
> -err_regulator_free:
> -	regulator_bulk_free(slot->num_supplies, slot->supplies);
> -
> -	return ret;
>  }
>  
>  static const struct of_device_id pci_pwrctrl_slot_of_match[] = {
> -- 
> 2.43.0
> 

-- 
மணிவண்ணன் சதாசிவம்

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

* Re: [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure
  2025-06-04  8:38 [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure Geert Uytterhoeven
  2025-06-04 17:23 ` Manivannan Sadhasivam
@ 2025-06-08 13:43 ` Marek Vasut
  2025-06-10  8:11 ` Bartosz Golaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Marek Vasut @ 2025-06-08 13:43 UTC (permalink / raw)
  To: Geert Uytterhoeven, Bartosz Golaszewski, Bjorn Helgaas,
	Krzysztof Wilczyński, Manivannan Sadhasivam, Marek Vasut
  Cc: linux-pci, linux-kernel

On 6/4/25 10:38 AM, Geert Uytterhoeven wrote:
> When devm_add_action_or_reset() fails, it calls the passed cleanup
> function.  Hence the caller must not repeat that cleanup.
> 
> Replace the "goto err_regulator_free" by the actual freeing, as there
> will never be a need again for a second user of this label.
> 
> Fixes: 75996c92f4de309f ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> Compile-tested only.
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Tested-by: Marek Vasut <marek.vasut+renesas@mailbox.org> # V4H Sparrow Hawk

Thanks !

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

* Re: [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure
  2025-06-04  8:38 [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure Geert Uytterhoeven
  2025-06-04 17:23 ` Manivannan Sadhasivam
  2025-06-08 13:43 ` Marek Vasut
@ 2025-06-10  8:11 ` Bartosz Golaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2025-06-10  8:11 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Bjorn Helgaas, Krzysztof Wilczyński, Manivannan Sadhasivam,
	Marek Vasut, linux-pci, linux-kernel

On Wed, Jun 4, 2025 at 10:38 AM Geert Uytterhoeven
<geert+renesas@glider.be> wrote:
>
> When devm_add_action_or_reset() fails, it calls the passed cleanup
> function.  Hence the caller must not repeat that cleanup.
>
> Replace the "goto err_regulator_free" by the actual freeing, as there
> will never be a need again for a second user of this label.
>
> Fixes: 75996c92f4de309f ("PCI/pwrctrl: Add pwrctrl driver for PCI slots")
> Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> Compile-tested only.
> ---

Acked-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

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

end of thread, other threads:[~2025-06-10  8:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-04  8:38 [PATCH] PCI/pwrctrl: Fix double cleanup on devm_add_action_or_reset() failure Geert Uytterhoeven
2025-06-04 17:23 ` Manivannan Sadhasivam
2025-06-08 13:43 ` Marek Vasut
2025-06-10  8:11 ` 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).