Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: qcom-ep: fix refcount leak in qcom_pcie_ep_probe()
@ 2026-06-09 10:07 Wentao Liang
  2026-06-09 10:15 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-06-09 10:07 UTC (permalink / raw)
  To: mani, lpieralisi, kwilczynski, robh, bhelgaas
  Cc: linux-pci, linux-arm-msm, linux-kernel, Wentao Liang, stable

qcom_pcie_ep_probe() obtains a runtime PM reference via
pm_runtime_get_noresume() but only releases it on the successful
completion of the function using pm_runtime_put_sync().  The devm
cleanup registered by devm_pm_runtime_enable() does not put the
reference - it only disables autosuspend and calls
pm_runtime_disable(), which does not decrement usage_count.  Thus
if any of the probe error paths are taken (e.g. resource acquisition
or endpoint init failure) the reference is leaked, permanently
elevating the device's usage_count and preventing proper runtime
suspend or clean removal.

Add a new error label that calls pm_runtime_put_noidle() and
pm_runtime_disable() before returning the error, and convert the
early return statements to use that label.  This ensures the
reference is correctly released on all error paths.

Cc: stable@vger.kernel.org
Fixes: 5b026a9e714d ("PCI: qcom-ep: Add support for firmware-managed PCIe Endpoint")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/pci/controller/dwc/pcie-qcom-ep.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
index 257c2bcb5f76..c01d4d3b4952 100644
--- a/drivers/pci/controller/dwc/pcie-qcom-ep.c
+++ b/drivers/pci/controller/dwc/pcie-qcom-ep.c
@@ -892,16 +892,16 @@ static int qcom_pcie_ep_probe(struct platform_device *pdev)
 	pm_runtime_set_active(dev);
 	ret = devm_pm_runtime_enable(dev);
 	if (ret)
-		return ret;
+		goto err_rpm_put;
 
 	ret = qcom_pcie_ep_get_resources(pdev, pcie_ep);
 	if (ret)
-		return ret;
+		goto err_rpm_put;
 
 	ret = dw_pcie_ep_init(&pcie_ep->pci.ep);
 	if (ret) {
 		dev_err(dev, "Failed to initialize endpoint: %d\n", ret);
-		return ret;
+		goto err_rpm_put;
 	}
 
 	ret = qcom_pcie_ep_enable_irq_resources(pdev, pcie_ep);
@@ -932,6 +932,10 @@ static int qcom_pcie_ep_probe(struct platform_device *pdev)
 err_ep_deinit:
 	dw_pcie_ep_deinit(&pcie_ep->pci.ep);
 
+err_rpm_put:
+	pm_runtime_put_noidle(dev);
+	pm_runtime_disable(dev);
+
 	return ret;
 }
 
-- 
2.34.1


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

end of thread, other threads:[~2026-06-09 10:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-09 10:07 [PATCH] PCI: qcom-ep: fix refcount leak in qcom_pcie_ep_probe() Wentao Liang
2026-06-09 10:15 ` sashiko-bot

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