Re: [PATCH v2] PCI: eswin: Fix resource leak on dw_pcie_host_init() failure

From: zhangsenchuan

Date: Thu May 21 2026 - 03:10:32 EST




> Fixes: b593c26d081a ("PCI: eswin: Add ESWIN PCIe Root Complex driver")
> Signed-off-by: Felix Gu <ustc.gu@xxxxxxxxx>
> ---
> 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@xxxxxxxxx/
> ---
> 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);
> - }

Hi, Felix

If removed, in the dw_pcie_resume_noirq function, if the execution of
"pci->pp.ops->init(&pci->pp)" fails, the resources will not be released.

Kind regards,
Senchuan

>
> 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;
> }