static struct pci_dev * __devinit tg3_find_5704_peer(struct tg3 *tp)
{
- struct pci_dev *peer = NULL;
- unsigned int func;
+ struct pci_dev *peer;
+ unsigned int func, devnr = tp->pdev->devfn & ~7;
- for (func = 0; func < 7; func++) {
- unsigned int devfn = tp->pdev->devfn;
-
- devfn &= ~7;
- devfn |= func;
-
- if (devfn == tp->pdev->devfn)
- continue;
- peer = pci_find_slot(tp->pdev->bus->number, devfn);
- if (peer)
+ for (func = 0; func < 8; func++) {
+ peer = pci_get_slot(tp->pdev->bus, devnr | func);
+ if (peer && peer != tp->pdev)
break;
+ pci_dev_put(peer);
}
if (!peer || peer == tp->pdev)
BUG();
+
+ /*
+ * We don't need to keep the refcount elevated; there's no way
+ * to remove one half of this device without removing the other
+ */
+ pci_dev_put(peer);
+
return peer;
}