Linux PCI subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ali Tariq" <alitariq45892@gmail.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI: starfive: Fix unchecked pm_runtime_get_sync() in probe
Date: Sun, 12 Jul 2026 18:04:39 +0000	[thread overview]
Message-ID: <20260712180440.423421F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260712175427.232234-1-alitariq45892@gmail.com>

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

Pre-existing issues:
- [High] The driver's removal path incorrectly calls asynchronous pm_runtime_put() before pm_runtime_disable(), and tears down PM references before disabling the hardware.
- [High] Failure in starfive_pcie_clk_rst_init() returns directly without powering off the PHY, causing a resource leak.
- [High] Missing return statement after regulator_enable() failure causes a silent fallthrough, later leading to an unbalanced regulator_disable().
--

--- Patch [1]: [PATCH] PCI: starfive: Fix unchecked pm_runtime_get_sync() in probe ---
commit 83a329f8aee98c4aec071468fc96ecc89497124e
Author: Ali Tariq <alitariq45892@gmail.com>

PCI: starfive: Fix unchecked pm_runtime_get_sync() in probe

This patch replaces pm_runtime_get_sync() with pm_runtime_resume_and_get()
in starfive_pcie_probe() to properly handle runtime resume failures. It
adds error handling to disable runtime PM and bail out of the probe
function if the device fails to resume, preventing unbalanced usage
counters and hardware configuration on an unpowered device.

> diff --git a/drivers/pci/controller/plda/pcie-starfive.c b/drivers/pci/controller/plda/pcie-starfive.c
> index 298036c3e7f94..e9a472985b8ac 100644
> --- a/drivers/pci/controller/plda/pcie-starfive.c
> +++ b/drivers/pci/controller/plda/pcie-starfive.c
> @@ -410,7 +410,11 @@ static int starfive_pcie_probe(struct platform_device *pdev)
>  		return ret;
>  
>  	pm_runtime_enable(&pdev->dev);
> -	pm_runtime_get_sync(&pdev->dev);
> +	ret = pm_runtime_resume_and_get(&pdev->dev);
> +	if (ret < 0) {
> +		pm_runtime_disable(&pdev->dev);
> +		return dev_err_probe(dev, ret, "failed to resume device\n");
> +	}
>  
>  	plda->host_ops = &sf_host_ops;
>  	plda->num_events = PLDA_MAX_EVENT_NUM;

[Severity: High]
This isn't a bug introduced by this patch, but looking at starfive_pcie_remove():

drivers/pci/controller/plda/pcie-starfive.c:starfive_pcie_remove() {
    ...
	pm_runtime_put(&pdev->dev);
	pm_runtime_disable(&pdev->dev);
	plda_pcie_host_deinit(&pcie->plda);
    ...
}

Does this leave the hardware in an active power state upon module unload?

Since pm_runtime_put() is asynchronous, wouldn't calling pm_runtime_disable()
immediately afterward risk canceling the idle/suspend work?

Also, does tearing down the PM reference before stopping the PCIe host
controller via plda_pcie_host_deinit() reverse the proper teardown order?
Could this cause the device to power off while still being actively accessed
by the core?

[Severity: High]
This is a pre-existing issue, but I noticed a potential resource leak in
starfive_pcie_host_init():

drivers/pci/controller/plda/pcie-starfive.c:starfive_pcie_host_init() {
    ...
	ret = starfive_pcie_enable_phy(dev, pcie);
	if (ret)
		return ret;
    ...
	ret = starfive_pcie_clk_rst_init(pcie);
	if (ret)
		return ret;
    ...
}

If starfive_pcie_clk_rst_init() fails, it returns the error code directly.
Does this fail to clean up the successfully initialized PHY?

Since plda_pcie_host_init() detects this initialization failure and returns
early without invoking host_deinit, does this result in permanently leaked
PHY resources and an unbalanced power state?

[Severity: High]
This is a pre-existing issue, but does this code swallow the regulator error?

drivers/pci/controller/plda/pcie-starfive.c:starfive_pcie_host_init() {
    ...
	if (pcie->vpcie3v3) {
		ret = regulator_enable(pcie->vpcie3v3);
		if (ret)
			dev_err_probe(dev, ret, "failed to enable vpcie3v3 regulator\n");
	}
    ...
}

Because there is no return statement after dev_err_probe(), the function
proceeds and eventually returns success at the end. Could this cause the
driver to continue operating with unpowered hardware?

Later on, starfive_pcie_host_deinit() unconditionally calls
regulator_disable(). Since the regulator was not successfully enabled,
would this trigger an unbalanced disable warning in the regulator core and
corrupt regulator use counts?

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

  reply	other threads:[~2026-07-12 18:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-12 17:54 [PATCH] PCI: starfive: Fix unchecked pm_runtime_get_sync() in probe Ali Tariq
2026-07-12 18:04 ` sashiko-bot [this message]
2026-07-13 12:48   ` Ali Tariq

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=20260712180440.423421F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alitariq45892@gmail.com \
    --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