From: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
To: bhelgaas@google.com
Cc: linux-pci@vger.kernel.org,
Kaushlendra Kumar <kaushlendra.kumar@intel.com>
Subject: [PATCH] PCI: Add lock and reference count in pci_get_domain_bus_and_slot()
Date: Wed, 1 Oct 2025 10:07:05 +0530 [thread overview]
Message-ID: <20251001043705.263609-1-kaushlendra.kumar@intel.com> (raw)
Add proper locking and reference counting to pci_get_domain_bus_and_slot
during PCI device enumeration. The function now holds pci_bus_sem during
device iteration and properly increments the device reference count
before returning.
Signed-off-by: Kaushlendra Kumar <kaushlendra.kumar@intel.com>
---
drivers/pci/search.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/search.c b/drivers/pci/search.c
index 53840634fbfc..dc49d3db69a4 100644
--- a/drivers/pci/search.c
+++ b/drivers/pci/search.c
@@ -230,12 +230,17 @@ struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
{
struct pci_dev *dev = NULL;
+ down_read(&pci_bus_sem);
for_each_pci_dev(dev) {
if (pci_domain_nr(dev->bus) == domain &&
(dev->bus->number == bus && dev->devfn == devfn))
- return dev;
+ goto out;
}
- return NULL;
+ dev = NULL;
+ out:
+ pci_dev_get(dev);
+ up_read(&pci_bus_sem);
+ return dev;
}
EXPORT_SYMBOL(pci_get_domain_bus_and_slot);
--
2.34.1
next reply other threads:[~2025-10-01 4:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 4:37 Kaushlendra Kumar [this message]
2025-10-01 11:25 ` [PATCH] PCI: Add lock and reference count in pci_get_domain_bus_and_slot() Ilpo Järvinen
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=20251001043705.263609-1-kaushlendra.kumar@intel.com \
--to=kaushlendra.kumar@intel.com \
--cc=bhelgaas@google.com \
--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