Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Felix Gu <ustc.gu@gmail.com>
To: "Senchuan Zhang" <zhangsenchuan@eswincomputing.com>,
	"Lorenzo Pieralisi" <lpieralisi@kernel.org>,
	"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
	"Manivannan Sadhasivam" <mani@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Yu Ning" <ningyu@eswincomputing.com>,
	"Yanghui Ou" <ouyanghui@eswincomputing.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Felix Gu <ustc.gu@gmail.com>
Subject: [PATCH v2] PCI: eswin: Fix resource leak on dw_pcie_host_init() failure
Date: Wed, 20 May 2026 22:45:04 +0800	[thread overview]
Message-ID: <20260520-eswin-v2-1-a221438a6317@gmail.com> (raw)

When dw_pcie_host_init() fails, the code jumps to err_init which
only calls pm_runtime_put() but skips the cleanup of port resources
allocated by eswin_pcie_parse_ports().

Additionally, the incorrect port cleanup code in
eswin_pcie_host_init() error path is removed since port resources
should be released in probe's error handler, not in host_init.

Fixes: b593c26d081a ("PCI: eswin: Add ESWIN PCIe Root Complex driver")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
   Changes in v2:
   - Fix Mani's comment.
   - Remove incorrect port cleanup code in eswin_pcie_host_init() error path.
   - Link to v1: https://lore.kernel.org/lkml/20260416-eswin-v1-1-a4991725b5ca@gmail.com/
---
 drivers/pci/controller/dwc/pcie-eswin.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-eswin.c b/drivers/pci/controller/dwc/pcie-eswin.c
index ce8d64f8a395..7a02ab91a190 100644
--- a/drivers/pci/controller/dwc/pcie-eswin.c
+++ b/drivers/pci/controller/dwc/pcie-eswin.c
@@ -182,7 +182,7 @@ static int eswin_pcie_host_init(struct dw_pcie_rp *pp)
 {
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 	struct eswin_pcie *pcie = to_eswin_pcie(pci);
-	struct eswin_pcie_port *port, *tmp;
+	struct eswin_pcie_port *port;
 	u32 val;
 	int ret;
 
@@ -252,10 +252,6 @@ static int eswin_pcie_host_init(struct dw_pcie_rp *pp)
 	reset_control_bulk_assert(ESWIN_NUM_RSTS, pcie->resets);
 err_deassert:
 	clk_bulk_disable_unprepare(pcie->num_clks, pcie->clks);
-	list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
-		reset_control_put(port->perst);
-		list_del(&port->list);
-	}
 
 	return ret;
 }
@@ -347,18 +343,17 @@ static int eswin_pcie_probe(struct platform_device *pdev)
 	ret = dw_pcie_host_init(&pci->pp);
 	if (ret) {
 		dev_err(dev, "Failed to init host\n");
-		goto err_init;
+		goto err_pm_runtime_put;
 	}
 
 	return 0;
 
 err_pm_runtime_put:
+	pm_runtime_put(dev);
 	list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
 		reset_control_put(port->perst);
 		list_del(&port->list);
 	}
-err_init:
-	pm_runtime_put(dev);
 
 	return ret;
 }

---
base-commit: e98d21c170b01ddef366f023bbfcf6b31509fa83
change-id: 20260519-eswin-997a8fa10245

Best regards,
--  
Felix Gu <ustc.gu@gmail.com>


             reply	other threads:[~2026-05-20 14:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 14:45 Felix Gu [this message]
2026-05-21  7:08 ` [PATCH v2] PCI: eswin: Fix resource leak on dw_pcie_host_init() failure zhangsenchuan
2026-05-21 10:39   ` Felix Gu
2026-06-10 17:21 ` Manivannan Sadhasivam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260520-eswin-v2-1-a221438a6317@gmail.com \
    --to=ustc.gu@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=ningyu@eswincomputing.com \
    --cc=ouyanghui@eswincomputing.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=zhangsenchuan@eswincomputing.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox