All of lore.kernel.org
 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 resource leaks on error paths in host_init()
Date: Tue, 14 Jul 2026 11:53:42 +0000	[thread overview]
Message-ID: <20260714115343.4D49E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260714113029.326207-1-alitariq45892@gmail.com>

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

Pre-existing issues:
- [High] Use-after-free of IRQ domains during driver unbind or when probe fails after interrupt initialization.
--

--- Patch [1]: [PATCH] PCI: starfive: Fix resource leaks on error paths in host_init() ---
commit 64603196409722c49e238cd53d9d6a6b7efd0b22
Author: Ali Tariq <alitariq45892@gmail.com>

PCI: starfive: Fix resource leaks on error paths in host_init()

This commit unwinds previously acquired PHY and clock/reset resources in
starfive_pcie_host_init() when subsequent initialization steps or regulator
enablement fails.

> diff --git a/drivers/pci/controller/plda/pcie-starfive.c b/drivers/pci/controller/plda/pcie-starfive.c
> index 298036c3e7f94..86b248a1ea758 100644
> --- a/drivers/pci/controller/plda/pcie-starfive.c
> +++ b/drivers/pci/controller/plda/pcie-starfive.c
[ ... ]
> @@ -303,13 +303,19 @@ static int starfive_pcie_host_init(struct plda_pcie_rp *plda)
>  			   STG_SYSCON_CLKREQ, STG_SYSCON_CLKREQ);
>  
>  	ret = starfive_pcie_clk_rst_init(pcie);
> -	if (ret)
> +	if (ret) {
> +		starfive_pcie_disable_phy(pcie);
>  		return ret;
> +	}
>  
>  	if (pcie->vpcie3v3) {
>  		ret = regulator_enable(pcie->vpcie3v3);
> -		if (ret)
> +		if (ret) {
>  			dev_err_probe(dev, ret, "failed to enable vpcie3v3 regulator\n");
> +			starfive_pcie_clk_rst_deinit(pcie);
> +			starfive_pcie_disable_phy(pcie);
> +			return ret;
> +		}
>  	}

[Severity: High]
This is a pre-existing issue, but since we are fixing error paths in the
host initialization, I noticed a potential use-after-free in the related
PLDA host initialization code.

In drivers/pci/controller/plda/pcie-plda-host.c, plda_init_interrupts()
allocates the interrupt using devm_request_irq():

plda_init_interrupts() {
    ...
    ret = devm_request_irq(dev, event_irq,
                           plda_event_handler,
                           0, NULL, port);
    ...
}

However, on device removal or if probe fails, plda_pcie_host_init() calls
plda_pcie_irq_domain_deinit(), which explicitly removes and frees the event
domain:

plda_pcie_host_init() {
    ...
err_probe:
    plda_pcie_irq_domain_deinit(port);
    ...
}

plda_pcie_irq_domain_deinit() {
    ...
    irq_domain_remove(pcie->event_domain);
    ...
}

Because the IRQs are devm-managed, their cleanup is deferred until after the
driver's probe or remove function returns.

When devres eventually calls free_irq(), will the IRQ core attempt to
deactivate the interrupt using the now-freed irq_data->domain pointer?

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

  reply	other threads:[~2026-07-14 11:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-14 11:30 [PATCH] PCI: starfive: Fix resource leaks on error paths in host_init() Ali Tariq
2026-07-14 11:53 ` sashiko-bot [this message]
2026-07-14 15:49   ` 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=20260714115343.4D49E1F000E9@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 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.