Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Zhijian Han" <hanzhijian1991@gmail.com>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH v4] PCI: imx6: fix resource leaks in probe error paths
Date: Mon, 24 Aug 2026 15:28:57 +0000	[thread overview]
Message-ID: <20260824152857.DB9771F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260824150454.3511203-1-hanzhijian1991@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Unbounded resource leak (clocks, regulators, PHYs) during repeated endpoint probe deferrals.
--

--- Patch [1]: [PATCH v4] PCI: imx6: fix resource leaks in probe error paths ---
commit 4146a6183d1b75bd09bf97a22116274151dfc0ca
Author: Zhijian Han <hanzhijian1991@gmail.com>

PCI: imx6: fix resource leaks in probe error paths

This commit addresses resource leaks in the imx6 pcie probe error paths by
introducing imx_pcie_detach_pd() to clean up power domains and pwrctrl
devices. It also adds DL_FLAG_AUTOREMOVE_CONSUMER to device links so they
are cleaned up automatically.

Link: https://lore.kernel.org/all/20260822013640.182C01F000E9@smtp.kernel.org/

> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index 39790e66b98dc..0b42093654f04 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c

[ ... ]

> @@ -1956,8 +1974,10 @@ static int imx_pcie_probe(struct platform_device *pdev)
>  		return ret;
>  
>  	ret = pci_pwrctrl_create_devices(dev);
> -	if (ret)
> +	if (ret) {
> +		imx_pcie_detach_pd(imx_pcie);
>  		return dev_err_probe(dev, ret, "failed to create pwrctrl devices\n");
> +	}
>  
>  	pci->use_parent_dt_ranges = true;
>  	if (imx_pcie->drvdata->mode == DW_PCIE_EP_TYPE) {

[Severity: High]
This is a pre-existing issue, but does imx_add_pcie_ep() leak hardware
resources such as clocks, regulators, and PHYs if endpoint initialization
fails or defers?

Looking at imx_add_pcie_ep(), it allocates hardware resources via
imx_pcie_host_init(pp), but if dw_pcie_ep_init(ep) returns an error
(like -EPROBE_DEFER), it returns directly without cleaning them up:

drivers/pci/controller/dwc/pci-imx6.c:imx_add_pcie_ep() {
    ...
	ret = dw_pcie_ep_init(ep);
	if (ret) {
		dev_err(dev, "failed to initialize endpoint\n");
		return ret;
	}
    ...
}

Similarly, if dw_pcie_ep_init_registers(ep) fails, it calls
dw_pcie_ep_deinit(ep) but still misses cleaning up the host resources:

drivers/pci/controller/dwc/pci-imx6.c:imx_add_pcie_ep() {
    ...
	ret = dw_pcie_ep_init_registers(ep);
	if (ret) {
		dev_err(dev, "Failed to initialize DWC endpoint registers\n");
		dw_pcie_ep_deinit(ep);
		return ret;
	}
    ...
}

Should these error paths call imx_pcie_host_exit(pp) to avoid permanently
leaking power and resource references during repeated probe deferrals?

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260824150454.3511203-1-hanzhijian1991@gmail.com?part=1

      reply	other threads:[~2026-08-24 15:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 15:04 [PATCH v4] PCI: imx6: fix resource leaks in probe error paths Zhijian Han
2026-08-24 15:28 ` sashiko-bot [this message]

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=20260824152857.DB9771F00A3D@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=hanzhijian1991@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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