Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Aadityarangan Shridhar Iyengar <adiyenga@cisco.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
	adiyenga@cisco.com
Subject: [PATCH] PCI/AER: Fix device reference leak in aer_inject()
Date: Tue, 17 Mar 2026 22:57:32 +0530	[thread overview]
Message-ID: <20260317172732.58053-1-adiyenga@cisco.com> (raw)

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.

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 17:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 17:27 Aadityarangan Shridhar Iyengar [this message]
2026-03-17 21:17 ` [PATCH] PCI/AER: Fix device reference leak in aer_inject() Bjorn Helgaas
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=20260317172732.58053-1-adiyenga@cisco.com \
    --to=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