Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI: Add lock  and reference count in pci_get_domain_bus_and_slot()
@ 2025-10-01  4:37 Kaushlendra Kumar
  2025-10-01 11:25 ` Ilpo Järvinen
  0 siblings, 1 reply; 2+ messages in thread
From: Kaushlendra Kumar @ 2025-10-01  4:37 UTC (permalink / raw)
  To: bhelgaas; +Cc: linux-pci, Kaushlendra Kumar

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-01 11:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-01  4:37 [PATCH] PCI: Add lock and reference count in pci_get_domain_bus_and_slot() Kaushlendra Kumar
2025-10-01 11:25 ` Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox