Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Aadityarangan Shridhar Iyengar <adiyenga@cisco.com>
Cc: bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] PCI/AER: Fix device reference leak in aer_inject()
Date: Tue, 17 Mar 2026 16:17:41 -0500	[thread overview]
Message-ID: <20260317211741.GA107878@bhelgaas> (raw)
In-Reply-To: <20260317172732.58053-1-adiyenga@cisco.com>

On Tue, Mar 17, 2026 at 10:57:32PM +0530, Aadityarangan Shridhar Iyengar wrote:
> In aer_inject(), pcie_port_find_device() returns a device with an
> incremented reference count. The function returns this device but never
> calls put_device() to release the reference, resulting in a reference leak.

From AI
(https://sashiko.dev/#/patchset/20260317172732.58053-1-adiyenga%40cisco.com):

  Is this description accurate? Looking at pcie_port_find_device(), it
  uses device_for_each_child() with the find_service_iter() callback.
  Unlike device_find_child(), neither of these functions calls
  get_device() on the matched child device to increment its reference
  count.

> Fix this by calling put_device() after using the device in both the success
> and error paths.
> 
> Fixes: 0e98db259fd8 ("PCI/AER: Reuse existing pcie_port_find_device() interface")
> Signed-off-by: Aadityarangan Shridhar Iyengar <adiyenga@cisco.com>
> ---
>  drivers/pci/pcie/aer_inject.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/pci/pcie/aer_inject.c b/drivers/pci/pcie/aer_inject.c
> index 09bfc7194ef3..5025843157b1 100644
> --- a/drivers/pci/pcie/aer_inject.c
> +++ b/drivers/pci/pcie/aer_inject.c
> @@ -467,11 +467,13 @@ static int aer_inject(struct aer_error_inj *einj)
>  		if (!get_service_data(edev)) {
>  			pci_warn(edev->port, "AER service is not initialized\n");
>  			ret = -EPROTONOSUPPORT;
> +			put_device(device);
>  			goto out_put;
>  		}
>  		pci_info(edev->port, "Injecting errors %08x/%08x into device %s\n",
>  			 einj->cor_status, einj->uncor_status, pci_name(dev));
>  		ret = irq_inject_interrupt(edev->irq);
> +		put_device(device);
>  	} else {
>  		pci_err(rpdev, "AER device not found\n");
>  		ret = -ENODEV;
> -- 
> 2.35.6
> 

  reply	other threads:[~2026-03-17 21:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 17:27 [PATCH] PCI/AER: Fix device reference leak in aer_inject() Aadityarangan Shridhar Iyengar
2026-03-17 21:17 ` Bjorn Helgaas [this message]
2026-03-18 10:35 ` Aadityarangan Shridhar Iyengar
  -- strict thread matches above, loose matches on Subject: below --
2026-01-11 16:36 [PATCH] PCI/PTM: Fix memory leak in pcie_ptm_create_debugfs() error path Aadityarangan Shridhar Iyengar
2026-01-14 16:26 ` [PATCH] PCI/AER: Fix device reference leak in aer_inject() Aadityarangan Shridhar Iyengar

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=20260317211741.GA107878@bhelgaas \
    --to=helgaas@kernel.org \
    --cc=adiyenga@cisco.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    /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