All of lore.kernel.org
 help / color / mirror / Atom feed
* [Kernel-janitors] [PATCH 2.6.9-rc2-mm2] Create new function to see
@ 2004-09-23 22:26 ` Hanna Linder
  0 siblings, 0 replies; 28+ messages in thread
From: Hanna Linder @ 2004-09-23 22:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: greg, hannal, kernel-janitors, davej, hpa

[-- Attachment #1: Type: text/plain, Size: 3543 bytes --]


Greg asked in a previous janitors thread:
"What we need is a simple "Is this pci device present right now" type
function, to solve the mess that logic like this needs."

OK. How about this one? It uses pci_get_device but instead of returning
the dev it returns 1 if the device is present and 0 if it isnt. This take the
burdon off the driver from having to know when to use pci_dev_put or
not and should be cleaner for future maintenance work.

Ive tested it with two patches that will follow.

Hanna Linder
IBM Linux Technology Center

Signed-off-by: Hanna Linder <hannal@us.ibm.com>
----

diff -Nrup linux-2.6.9-rc2-mm2cln/drivers/pci/search.c linux-2.6.9-rc2-mm2patch/drivers/pci/search.c
--- linux-2.6.9-rc2-mm2cln/drivers/pci/search.c	2004-09-23 11:49:04.000000000 -0700
+++ linux-2.6.9-rc2-mm2patch/drivers/pci/search.c	2004-09-23 15:03:58.000000000 -0700
@@ -271,6 +271,30 @@ pci_get_device(unsigned int vendor, unsi
 	return pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
 }
 
+/**
+ * pci_dev_present - Returns 1 if device is present, 0 if device is not.
+ * @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
+ * @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
+ * @from: Previous PCI device found in search, or %NULL for new search.
+ *
+ * If pci_get_device returns a pci_dev pointer then the device exists and the
+ * reference count is decremented before returning 1. If pci_get_device
+ * returns %NULL then 0 is returned to indicate the device was not
+ * present. Obvious fact: You do not have a reference to the device so if
+ * it is removed from the system before this function returns the value
+ * will be stale. 
+ */
+int 
+pci_dev_present(unsigned int vendor, unsigned int device, struct pci_dev *from)
+{
+	struct pci_dev *dev;
+	dev = pci_get_device(vendor, device, from);
+	if (dev){
+		pci_dev_put(dev);
+		return 1;
+	}
+	return 0;
+}
 
 /**
  * pci_find_device_reverse - begin or continue searching for a PCI device by vendor/device id
@@ -352,3 +376,5 @@ EXPORT_SYMBOL(pci_get_device);
 EXPORT_SYMBOL(pci_get_subsys);
 EXPORT_SYMBOL(pci_get_slot);
 EXPORT_SYMBOL(pci_get_class);
+EXPORT_SYMBOL(pci_dev_present);
+
diff -Nrup linux-2.6.9-rc2-mm2cln/include/linux/pci.h linux-2.6.9-rc2-mm2patch/include/linux/pci.h
--- linux-2.6.9-rc2-mm2cln/include/linux/pci.h	2004-09-23 11:49:27.000000000 -0700
+++ linux-2.6.9-rc2-mm2patch/include/linux/pci.h	2004-09-23 15:03:01.000000000 -0700
@@ -733,6 +733,8 @@ struct pci_dev *pci_get_subsys (unsigned
 struct pci_dev *pci_get_slot (struct pci_bus *bus, unsigned int devfn);
 struct pci_dev *pci_get_class (unsigned int class, struct pci_dev *from);
 
+int pci_dev_present(unsigned int vendor, unsigned int device, struct pci_dev *from);
+
 int pci_bus_read_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u8 *val);
 int pci_bus_read_config_word (struct pci_bus *bus, unsigned int devfn, int where, u16 *val);
 int pci_bus_read_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u32 *val);
@@ -900,6 +902,9 @@ unsigned int ss_vendor, unsigned int ss_
 static inline struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
 { return NULL; }
 
+static inline int pci_dev_present(unsigned int vendor, unsigned int device, struct pci_dev *from)
+{return -1; }
+
 static inline void pci_set_master(struct pci_dev *dev) { }
 static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
 static inline void pci_disable_device(struct pci_dev *dev) { }






[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
http://lists.osdl.org/mailman/listinfo/kernel-janitors

^ permalink raw reply	[flat|nested] 28+ messages in thread
* [Kernel-janitors] [PATCH 2.6.9-rc2-mm4 pci_bus_cvlink.c] Replace
@ 2004-10-01 18:10 ` Hanna Linder
  0 siblings, 0 replies; 28+ messages in thread
From: Hanna Linder @ 2004-10-01 18:10 UTC (permalink / raw)
  To: linux-kernel
  Cc: greg, kernel-janitors, Judith Lebzelter, davidm, hannal, jbarnes

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

As pci_find_device is going away soon I have replaced the call with pci_get_device.
Judith, could you run these 3 ia64 ones through PLM, please? 

Thanks a lot.

Hanna Linder
IBM Linux Technology Center

Signed-off-by: Hanna Linder <hannal@us.ibm.com>

---

diff -Nrup linux-2.6.9-rc2-mm4cln/arch/ia64/sn/io/machvec/pci_bus_cvlink.c linux-2.6.9-rc2-mm4patch2/arch/ia64/sn/io/machvec/pci_bus_cvlink.c
--- linux-2.6.9-rc2-mm4cln/arch/ia64/sn/io/machvec/pci_bus_cvlink.c	2004-09-28 14:58:07.000000000 -0700
+++ linux-2.6.9-rc2-mm4patch2/arch/ia64/sn/io/machvec/pci_bus_cvlink.c	2004-09-30 16:56:57.454516072 -0700
@@ -904,7 +904,7 @@ sn_pci_init (void)
 	/*
 	 * Initialize the device vertex in the pci_dev struct.
 	 */
-	while ((pci_dev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
+	while ((pci_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci_dev)) != NULL) {
 		ret = sn_pci_fixup_slot(pci_dev);
 		if ( ret ) {
 			printk(KERN_WARNING


[-- Attachment #2: Type: text/plain, Size: 167 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
http://lists.osdl.org/mailman/listinfo/kernel-janitors

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

end of thread, other threads:[~2004-10-02  5:36 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-23 22:26 [Kernel-janitors] [PATCH 2.6.9-rc2-mm2] Create new function to see Hanna Linder
2004-09-23 22:26 ` [PATCH 2.6.9-rc2-mm2] Create new function to see if pci dev is present Hanna Linder
2004-09-23 22:28 ` [Kernel-janitors] [PATCH 2.6.9-rc2-mm2] Change cyrix.c driver to Hanna Linder
2004-09-23 22:28   ` [PATCH 2.6.9-rc2-mm2] Change cyrix.c driver to use new pci_dev_present Hanna Linder
2004-09-23 22:28 ` [Kernel-janitors] [PATCH 2.6.9-rc2-mm2] Change irq.c driver to use Hanna Linder
2004-09-23 22:28   ` [PATCH 2.6.9-rc2-mm2] Change irq.c driver to use new pci_dev_present Hanna Linder
2004-09-23 22:50 ` [Kernel-janitors] Re: [PATCH 2.6.9-rc2-mm2] Create new function to Greg KH
2004-09-23 22:50   ` [PATCH 2.6.9-rc2-mm2] Create new function to see if pci dev is present Greg KH
2004-10-02  5:35   ` [Kernel-janitors] Re: [PATCH 2.6.9-rc2-mm4 pci_bus_cvlink.c] Judith Lebzelter
2004-10-02  5:35     ` [PATCH 2.6.9-rc2-mm4 pci_bus_cvlink.c] Replace pci_find_device with pci_get_device Judith Lebzelter
2004-09-24 19:02 ` [Kernel-janitors] Re: [PATCH 2.6.9-rc2-mm2] Create new function to Christoph Hellwig
2004-09-24 19:02   ` [PATCH 2.6.9-rc2-mm2] Create new function to see if pci dev is present Christoph Hellwig
2004-09-24 21:19   ` [Kernel-janitors] Re: [PATCH 2.6.9-rc2-mm2] Create new function to Greg KH
2004-09-24 21:19     ` [PATCH 2.6.9-rc2-mm2] Create new function to see if pci dev is present Greg KH
2004-09-24 21:00     ` [Kernel-janitors] Re: [PATCH 2.6.9-rc2-mm2] Create new function to Alan Cox
2004-09-24 21:00       ` [PATCH 2.6.9-rc2-mm2] Create new function to see if pci dev is present Alan Cox
2004-09-26 14:10       ` [Kernel-janitors] Re: [PATCH 2.6.9-rc2-mm2] Create new function to Greg KH
2004-09-26 14:10         ` [PATCH 2.6.9-rc2-mm2] Create new function to see if pci dev is present Greg KH
2004-09-28 17:24         ` [Kernel-janitors] Re: Create new function to see if pci dev is Greg KH
2004-09-28 17:24           ` Create new function to see if pci dev is present Greg KH
2004-09-28 17:25           ` [Kernel-janitors] Re: Create new function to see if pci dev is Greg KH
2004-09-28 17:25             ` Create new function to see if pci dev is present Greg KH
2004-09-28 17:26           ` [Kernel-janitors] Re: Create new function to see if pci dev is Greg KH
2004-09-28 17:26             ` Create new function to see if pci dev is present Greg KH
2004-09-24 21:26     ` [Kernel-janitors] Re: [PATCH 2.6.9-rc2-mm2] Create new function to H. Peter Anvin
2004-09-24 21:26       ` [PATCH 2.6.9-rc2-mm2] Create new function to see if pci dev is present H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2004-10-01 18:10 [Kernel-janitors] [PATCH 2.6.9-rc2-mm4 pci_bus_cvlink.c] Replace Hanna Linder
2004-10-01 18:10 ` [PATCH 2.6.9-rc2-mm4 pci_bus_cvlink.c] Replace pci_find_device with pci_get_device Hanna Linder

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.