Skip to contentSkip to conversation

PCI: aspeed: fix clk and phy leak in aspeed_pcie_port_init error paths

PATCH Applied Liu Zhenlong 3 participants 3 messages Aug 16 – Aug 31

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: aspeed: fix clk and phy leak in aspeed_pcie_port_init error paths

aspeed_pcie_port_init() calls clk_prepare_enable() to enable the port clock, but if phy_init() or phy_set_mode_ext() fails afterwards, the function returns without calling clk_disable_unprepare(), leaking the clock reference on every probe failure. Additionally, when phy_set_mode_ext() fails, phy_init() has already succeeded, so phy_exit() is also missing, leaking the phy reference.

Add the matching clk_disable_unprepare() to both error paths, and phy_exit() to the phy_set_mode_ext() failure path, mirroring the cleanup pattern in pci-aardvark.

Compile-tested with gcc on arm64 defconfig using COMPILE_TEST; no hardware available for runtime testing.

Fixes 9aa0cb68fcc1 ("PCI: aspeed: Add ASPEED PCIe RC driver")
Assisted-by Claude:claude-opus-5
---
 drivers/pci/controller/pcie-aspeed.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-aspeed.c +7 -2
index 9aa9e14c6148..1fd663ea3bf8 100644
@@ -761,16 +761,21 @@ static int aspeed_pcie_port_init(struct aspeed_pcie_port *port)
 				     port->slot);
 
 	ret = phy_init(port->phy);
-	if (ret)
+	if (ret) {
+		clk_disable_unprepare(port->clk);
 		return dev_err_probe(dev, ret,
 				     "failed to init phy pcie for slot (%d)\n",
 				     port->slot);
+	}
 
 	ret = phy_set_mode_ext(port->phy, PHY_MODE_PCIE, PHY_MODE_PCIE_RC);
-	if (ret)
+	if (ret) {
+		phy_exit(port->phy);
+		clk_disable_unprepare(port->clk);
 		return dev_err_probe(dev, ret,
 				     "failed to set phy mode for slot (%d)\n",
 				     port->slot);
+	}
 
 	reset_control_deassert(port->perst);
 	msleep(PCIE_RESET_CONFIG_WAIT_MS);
Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

aspeed_pcie_port_init() calls clk_prepare_enable() to enable the port clock, but if phy_init() or phy_set_mode_ext() fails afterwards, the function returns without calling clk_disable_unprepare(), leaking the clock reference on every probe failure. Additionally, when phy_set_mode_ext() fails, phy_init() has already succeeded, so phy_exit() is also missing, leaking the phy reference.

Add the matching clk_disable_unprepare() to both error paths, and phy_exit() to the phy_set_mode_ext() failure path, mirroring the cleanup pattern in pci-aardvark.

Quoted 7 lines

Compile-tested with gcc on arm64 defconfig using COMPILE_TEST; no hardware available for runtime testing.

Fixes 9aa0cb68fcc1 ("PCI: aspeed: Add ASPEED PCIe RC driver")
Assisted-by Claude:claude-opus-5

Sashiko has reviewed this patch and found no issues. It looks great!

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

aspeed_pcie_port_init() calls clk_prepare_enable() to enable the port clock, but if phy_init() or phy_set_mode_ext() fails afterwards, the function returns without calling clk_disable_unprepare(), leaking the clock reference on every probe failure. Additionally, when phy_set_mode_ext() fails, phy_init() has already succeeded, so phy_exit() is also missing, leaking the phy reference.

[...]

Applied, thanks!

[1/1] PCI: aspeed: fix clk and phy leak in aspeed_pcie_port_init error paths

      commit: 6c566177fc8f728271bed8018ac77b0a8199200d

Best regards,

Signature · 1 line
மணிவண்ணன் சதாசிவம்