Skip to contentSkip to conversation

PCI/pwrctrl: generic: Fix leak on clock error path

PATCH Applied Felix Gu 5 participants 5 messages Oct 30 – Nov 2

Subsystems (2)
lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 PCI/pwrctrl: generic: Fix leak on clock error path

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")
---
 drivers/pci/pwrctrl/generic.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/pwrctrl/generic.c +4 -4
index 4b6cbbb52248..85d568b381e2 100644
@@ -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,

Signature · 1 line
Felix Gu <[email protected]>
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

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")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Felix Gu
Quoted 3 lines

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()

allocated?

Quoted 1 line

is never freed.

…
are?

Regards,
Markus

maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Felix Gu
Quoted 11 lines · 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")

---

#4 lore raw
In reply to Felix Gu

[+cc Markus]

Quoted 10 lines · 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")

Applied to pci/pwrctrl for v7.5, thanks!

Fixed the eallocated->allocated and is->are commit log typos.

Quoted 39 lines
---
 drivers/pci/pwrctrl/generic.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/pwrctrl/generic.c +4 -5
index 4b6cbbb52248..85d568b381e2 100644
@@ -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,

Signature · 1 line
Felix Gu <[email protected]>