Skip to contentSkip to conversation

pci: gt96100eth avoid pci_find_device

PATCH Jiri Slaby 1 participant 1 message Jun 5, 2006 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Jiri Slaby

author
#1 lore raw
In reply to a message not in the archive

Jiri Slaby napsal(a):

Quoted 43 lines

gt96100eth avoid pci_find_device

Change pci_find_device to safer pci_get_device with support for more bridges.

---
commit fd863b81ac491faf783ff7f2dcf6032177c5ab7f
tree d7eb59f897505230023754f19ad7227eec39e676
parent 4b73c16f5411d97360d5f26f292ffddeb670ff75
author Jiri Slaby <[email protected]> Mon, 05 Jun 2006 22:01:20 +0159 committer Jiri Slaby <[email protected]> Mon, 05 Jun 2006 22:01:20 +0159

 drivers/net/gt96100eth.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)
drivers/net/gt96100eth.c +6 -0
index 2d24354..3066c86 100644
@@ -600,6 +600,11 @@ disable_ether_irq(struct net_device *dev
 	GT96100ETH_WRITE(gp, GT96100_ETH_INT_MASK, 0);
 }
 
+static struct pci_device_id gt96100_ids[] = {
+	{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT96100) },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_GT96100A) },
+	{ 0 }
+};
 
 /*
  * Init GT96100 ethernet controller driver
@@ -607,16 +612,20 @@ disable_ether_irq(struct net_device *dev
 static int gt96100_init_module(void)
 {
 	struct pci_dev *pci;
+	struct pci_device_id *id;
 	int i, retval=0;
 	u32 cpuConfig;
 
 	/*
 	 * Stupid probe because this really isn't a PCI device

drivers/net/gt96100eth.c disable_ether_irq(struct net_device *dev · line 626

Quoted 10 lines
drivers/net/gt96100eth.c +5 -4
 	 */
-	if (!(pci = pci_find_device(PCI_VENDOR_ID_MARVELL,
-	                            PCI_DEVICE_ID_MARVELL_GT96100, NULL)) &&
-	    !(pci = pci_find_device(PCI_VENDOR_ID_MARVELL,
-		                    PCI_DEVICE_ID_MARVELL_GT96100A, NULL))) {
+	for (id = gt96100_ids; id->vendor; id++) {
+		pci = pci_get_device(id->vendor, id->device, NULL);
+		if (pci != NULL)
+			break;
+	}

I wonder if this is even better:
while ((pci = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pci)) != NULL)

    if (pci_match_id(gt96100_ids, pci) != NULL)
         break;

What do you think?

Quoted 24 lines
drivers/net/gt96100eth.c +7 -1
+
+	if (!id->vendor) {
 		printk(KERN_ERR __FILE__ ": GT96100 not found!\n");
 		return -ENODEV;
 	}
@@ -625,12 +634,16 @@ static int gt96100_init_module(void)
 	if (cpuConfig & (1<<12)) {
 		printk(KERN_ERR __FILE__
 		       ": must be in Big Endian mode!\n");
-		return -ENODEV;
+		retval = -ENODEV;
+		goto err_pput;
 	}
 
 	for (i=0; i < NUM_INTERFACES; i++)
 		retval |= gt96100_probe1(pci, i);
 
+err_pput:
+	pci_dev_put(pci);
+
 	return retval;
 }
 
Signature · 3 lines
Jiri Slaby         www.fi.muni.cz/~xslaby
\_.-^-._   [email protected]   _.-^-._/
B67499670407CE62ACC8 22A032CC55C339D47A7E