All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Wentao Liang" <vulab@iscas.ac.cn>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH v2] PCI: qcom-ep: Fix runtime PM reference leak in probe error paths
Date: Wed, 24 Jun 2026 13:39:27 +0000	[thread overview]
Message-ID: <20260624133928.4844B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260624132943.40718-1-vulab@iscas.ac.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double-disable of runtime PM on `devm_pm_runtime_enable()` failure permanently breaks runtime PM.
- [High] Double-put of the runtime PM usage counter due to unhandled fall-through on `pm_runtime_put_sync()` failure.
--

commit c1b17f3fe6107b8e2d84d7608e5bf717e1aa999e
Author: Wentao Liang <vulab@iscas.ac.cn>

PCI: qcom-ep: Fix runtime PM reference leak in probe error paths

This commit updates qcom_pcie_ep_probe() to distinguish between error
paths before and after devm_pm_runtime_enable() succeeds. It adds
manual cleanup for early errors and uses pm_runtime_put_sync() for
later errors to prevent runtime PM reference leaks.

> - On the successful probe path: call pm_runtime_put_sync() to drop
>   the initial reference. The return value of pm_runtime_put_sync()
>   is ignored because errors like -EAGAIN or -EBUSY only indicate
>   that the device cannot be suspended at this moment and do not
>   represent a fatal probe failure.

[Severity: High]
The commit message states that the return value of pm_runtime_put_sync()
is ignored, but the code still checks the return value and jumps to the
error path if it fails.

> diff --git a/drivers/pci/controller/dwc/pcie-qcom-ep.c b/drivers/pci/controller/dwc/pcie-qcom-ep.c
> --- 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_manual_cleanup;

[Severity: High]
If devm_pm_runtime_enable() fails (for example, due to a devres memory
allocation failure), it internally guarantees its cleanup action is executed,
which already calls pm_runtime_disable().

By jumping to err_manual_cleanup and calling pm_runtime_disable() again,
will this incorrectly increment the device's disable_depth to 2? Could this
permanently leave runtime PM disabled for the device on subsequent deferred
probe attempts?

[ ... ]

> @@ -932,6 +932,13 @@ static int qcom_pcie_ep_probe(struct platform_device *pdev)
>  err_ep_deinit:
>  	dw_pcie_ep_deinit(&pcie_ep->pci.ep);
>  
> +err_put_ref:
> +	pm_runtime_put_sync(dev);
> +	return ret;

[Severity: High]
Because the patch leaves the original error check intact on the successful
probe path:

    ret = pm_runtime_put_sync(dev);
    if (ret < 0) {
        dev_err(dev, "Failed to suspend device: %d\n", ret);
        goto err_disable_irqs;
    }

If the initial put returns a transient error like -EAGAIN, the usage count
has already been decremented by the PM core. However, the code jumps to
err_disable_irqs, unwinds the probe, and falls through to err_put_ref here.

Could this result in calling pm_runtime_put_sync() a second time, causing
a usage counter underflow?

> +err_manual_cleanup:
> +	pm_runtime_put_noidle(dev);
> +	pm_runtime_disable(dev);
>  	return ret;
>  }
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260624132943.40718-1-vulab@iscas.ac.cn?part=1

      reply	other threads:[~2026-06-24 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-24 13:29 [PATCH v2] PCI: qcom-ep: Fix runtime PM reference leak in probe error paths Wentao Liang
2026-06-24 13:39 ` 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=20260624133928.4844B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vulab@iscas.ac.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.