[PATCH] PCI: starfive: Fix resource leaks on error paths in host_init()

From: Ali Tariq

Date: Tue Jul 14 2026 - 07:35:11 EST


starfive_pcie_host_init() acquires the PHY, clocks/resets, and an
optional regulator in sequence, but does not correctly unwind these
resources when a later step fails.

If starfive_pcie_clk_rst_init() fails after the PHY has already been
successfully enabled, the function returns directly without disabling
the PHY, leaking it and leaving it powered.

If regulator_enable() fails for the optional vpcie3v3 regulator, the
failure is only logged; the function falls through and returns
success, leaving the driver believing the regulator is enabled while
continuing to configure PCIe hardware that may be unpowered. This
also leaves the clocks and PHY enabled with nothing to clean them up.

Disable the PHY on the clk/reset failure path, and disable the
clocks/resets and PHY, then return the error, if the regulator fails
to enable.

Build-tested and boot-tested on StarFive VisionFive 2 v1.2A

Signed-off-by: Ali Tariq <alitariq45892@xxxxxxxxx>
---
drivers/pci/controller/plda/pcie-starfive.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/controller/plda/pcie-starfive.c b/drivers/pci/controller/plda/pcie-starfive.c
index ba8ef7842e35..156b31eef868 100644
--- a/drivers/pci/controller/plda/pcie-starfive.c
+++ b/drivers/pci/controller/plda/pcie-starfive.c
@@ -303,13 +303,19 @@ static int starfive_pcie_host_init(struct plda_pcie_rp *plda)
STG_SYSCON_CLKREQ, STG_SYSCON_CLKREQ);

ret = starfive_pcie_clk_rst_init(pcie);
- if (ret)
+ if (ret) {
+ starfive_pcie_disable_phy(pcie);
return ret;
+ }

if (pcie->vpcie3v3) {
ret = regulator_enable(pcie->vpcie3v3);
- if (ret)
+ if (ret) {
dev_err_probe(dev, ret, "failed to enable vpcie3v3 regulator\n");
+ starfive_pcie_clk_rst_deinit(pcie);
+ starfive_pcie_disable_phy(pcie);
+ return ret;
+ }
}

if (pcie->reset_gpio)
--
2.34.1