linux-mips
[Top] [All Lists]

Re: [PATCH] IOC3: Switch to pci refcounting safe APIs

To: Ralf Baechle <ralf@linux-mips.org>
Subject: Re: [PATCH] IOC3: Switch to pci refcounting safe APIs
From: Alan Cox <alan@lxorguk.ukuu.org.uk>
Date: Mon, 23 Apr 2007 16:18:35 +0100
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>, linux-mips@linux-mips.org
In-reply-to: <20070423143507.GA8877@linux-mips.org>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <20070423150640.1faf693f@the-village.bc.nu> <462CBE33.2060208@ru.mvista.com> <20070423151918.477ffb6a@the-village.bc.nu> <20070423143507.GA8877@linux-mips.org>
Sender: linux-mips-bounce@linux-mips.org
> > Makes no real difference, but if you know the MIPS tree never ends up
> > with pdev->bus = NULL for the root bus then its a trivial change
> 
> That's the case on MIPS.

Revised patch then


---

Convert the IOC3 driver to use ref counting pci interfaces so that we can
obsolete the (usually unsafe) pci_find_{slot/device} interfaces and avoid
future authors writing hotplug-unsafe device drivers.

Signed-off-by: Alan Cox <alan@redhat.com>

diff -u --new-file --recursive --exclude-from /usr/src/exclude 
linux.vanilla-2.6.21-rc6-mm1/drivers/net/ioc3-eth.c 
linux-2.6.21-rc6-mm1/drivers/net/ioc3-eth.c
--- linux.vanilla-2.6.21-rc6-mm1/drivers/net/ioc3-eth.c 2007-04-12 
14:15:04.000000000 +0100
+++ linux-2.6.21-rc6-mm1/drivers/net/ioc3-eth.c 2007-04-23 15:58:21.431489816 
+0100
@@ -1103,20 +1103,29 @@
  * MiniDINs; all other subdevices are left swinging in the wind, leave
  * them disabled.
  */
-static inline int ioc3_is_menet(struct pci_dev *pdev)
+ 
+static int ioc3_adjacent_is_ioc3(struct pci_dev *pdev, int dev)
+{
+       struct pci_dev *dev = pci_get_slot(pdev->bus, PCI_DEVFN(dev, 0));
+       int ret = 0;
+       
+       if (dev) {
+               if (dev->vendor == PCI_VENDOR_ID_SGI &&
+                       dev->device == PCI_DEVICE_ID_SGI_IOC3)
+                       ret = 1;
+               pci_dev_put(dev);
+       }
+       return ret;
+}
+
+static int ioc3_is_menet(struct pci_dev *pdev)
 {
        struct pci_dev *dev;
 
-       return pdev->bus->parent == NULL
-              && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(0, 0)))
-              && dev->vendor == PCI_VENDOR_ID_SGI
-              && dev->device == PCI_DEVICE_ID_SGI_IOC3
-              && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(1, 0)))
-              && dev->vendor == PCI_VENDOR_ID_SGI
-              && dev->device == PCI_DEVICE_ID_SGI_IOC3
-              && (dev = pci_find_slot(pdev->bus->number, PCI_DEVFN(2, 0)))
-              && dev->vendor == PCI_VENDOR_ID_SGI
-              && dev->device == PCI_DEVICE_ID_SGI_IOC3;
+       return pdev->bus->parent == NULL &&
+              ioc3_adjacent_is_ioc3(pdev, 0) &&
+              ioc3_adjacent_is_ioc3(pdev, 1) &&
+              ioc3_adjacent_is_ioc3(pdev, 2));
 }
 
 #ifdef CONFIG_SERIAL_8250

<Prev in Thread] Current Thread [Next in Thread>