Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI/pwrctrl: generic: Fix leak on clock error path
@ 2026-10-30 17:49 Felix Gu
  2026-10-30 17:53 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Felix Gu @ 2026-10-30 17:49 UTC (permalink / raw)
  To: Bartosz Golaszewski, Manivannan Sadhasivam, Bjorn Helgaas
  Cc: Manivannan Sadhasivam, linux-pci, linux-kernel, Felix Gu

The devm release action for the slot supplies is registered after
devm_clk_get_optional().  If clock acquisition fails, probe returns
immediately, so the resources eallocated by of_regulator_bulk_get_all()
is never freed.

Register the devm action right after of_regulator_bulk_get_all()
succeeds, so the resources are released on any subsequent probe failure.

Fixes: 9cb64f61ec7a9 ("PCI/pwrctrl: Add PCIe M.2 connector support")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/pci/pwrctrl/generic.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/pwrctrl/generic.c b/drivers/pci/pwrctrl/generic.c
index 4b6cbbb52248..85d568b381e2 100644
--- a/drivers/pci/pwrctrl/generic.c
+++ b/drivers/pci/pwrctrl/generic.c
@@ -92,6 +92,10 @@ static int slot_pwrctrl_probe(struct platform_device *pdev)
 
 	slot->num_supplies = ret;
 
+	ret = devm_add_action_or_reset(dev, devm_slot_pwrctrl_release, slot);
+	if (ret)
+		return ret;
+
 	slot->clk = devm_clk_get_optional(dev, NULL);
 	if (IS_ERR(slot->clk))
 		return dev_err_probe(dev, PTR_ERR(slot->clk),
@@ -101,10 +105,6 @@ static int slot_pwrctrl_probe(struct platform_device *pdev)
 	slot->pwrctrl.power_on = slot_pwrctrl_power_on;
 	slot->pwrctrl.power_off = slot_pwrctrl_power_off;
 
-	ret = devm_add_action_or_reset(dev, devm_slot_pwrctrl_release, slot);
-	if (ret)
-		return ret;
-
 	pci_pwrctrl_init(&slot->pwrctrl, dev);
 
 	ret = devm_pci_pwrctrl_device_set_ready(dev, &slot->pwrctrl);

---
base-commit: a39c950806213f6861d00f90729acaaa21f2d95a
change-id: 20261030-pwrctrl-6a85275b0c97

Best regards,
--  
Felix Gu <ustc.gu@gmail.com>


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

* Re: [PATCH] PCI/pwrctrl: generic: Fix leak on clock error path
  2026-10-30 17:49 [PATCH] PCI/pwrctrl: generic: Fix leak on clock error path Felix Gu
@ 2026-10-30 17:53 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-10-30 17:53 UTC (permalink / raw)
  To: Felix Gu; +Cc: linux-pci

> The devm release action for the slot supplies is registered after
> devm_clk_get_optional().  If clock acquisition fails, probe returns
> immediately, so the resources eallocated by of_regulator_bulk_get_all()
> is never freed.
> 
> Register the devm action right after of_regulator_bulk_get_all()
> succeeds, so the resources are released on any subsequent probe failure.
> 
> Fixes: 9cb64f61ec7a9 ("PCI/pwrctrl: Add PCIe M.2 connector support")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261031-pwrctrl-v1-1-405af11c5662@gmail.com?part=1


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

end of thread, other threads:[~2026-10-30 17:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-30 17:49 [PATCH] PCI/pwrctrl: generic: Fix leak on clock error path Felix Gu
2026-10-30 17:53 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox