PCI/pwrctrl: generic: Fix leak on clock error path
Subsystems (2)
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.
--- drivers/pci/pwrctrl/generic.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/pci/pwrctrl/generic.c +4 -4
@@ -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]>
[email protected]
AI reviewSashiko 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 byof_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 <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
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 byof_regulator_bulk_get_all()
allocated?
Quoted 1 line
is never freed.
…
are?
Regards,
Markus
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 byof_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 <[email protected]>---
Bjorn Helgaas
Applied[+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 byof_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 <[email protected]>
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@@ -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-6a85275b0c97Best regards,
Signature · 1 line
Felix Gu <[email protected]>