summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/adv_pci1710.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-07-18 18:31:43 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-19 16:19:42 -0700
commit5aa53d5f2e9cf38112b8087ead926fcaacaa5abe (patch)
tree346a979e7851f35ffb83a54ca51e5c68e62b1a05 /drivers/staging/comedi/drivers/adv_pci1710.c
parent96554c81d512d171b2e3b9dd3769bed8280ded2f (diff)
staging: comedi: adv_pci1710: cleanup "find pci device" code
Use for_each_pci_dev() instead of open-coding the loop using pci_get_device(). Drop the printk error messages. They just add noise. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Cc: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi/drivers/adv_pci1710.c')
-rw-r--r--drivers/staging/comedi/drivers/adv_pci1710.c63
1 files changed, 17 insertions, 46 deletions
diff --git a/drivers/staging/comedi/drivers/adv_pci1710.c b/drivers/staging/comedi/drivers/adv_pci1710.c
index 0823a3681a8e..5eecf6bc31e3 100644
--- a/drivers/staging/comedi/drivers/adv_pci1710.c
+++ b/drivers/staging/comedi/drivers/adv_pci1710.c
@@ -1336,24 +1336,21 @@ static int pci1710_reset(struct comedi_device *dev)
static struct pci_dev *pci1710_find_pci_dev(struct comedi_device *dev,
struct comedi_devconfig *it)
{
- struct pci_dev *pcidev;
- int opt_bus, opt_slot;
- const char *errstr;
- unsigned char pci_bus, pci_slot, pci_func;
+ struct pci_dev *pcidev = NULL;
+ int bus = it->options[0];
+ int slot = it->options[1];
+ int board_index = this_board - boardtypes;
int i;
- int board_index;
- unsigned int irq;
- unsigned long iobase;
- opt_bus = it->options[0];
- opt_slot = it->options[1];
+ for_each_pci_dev(pcidev) {
+ if (bus || slot) {
+ if (bus != pcidev->bus->number ||
+ slot != PCI_SLOT(pcidev->devfn))
+ continue;
+ }
+ if (pcidev->vendor != PCI_VENDOR_ID_ADVANTECH)
+ continue;
- /* Look for matching PCI device */
- errstr = "not found!";
- pcidev = NULL;
- board_index = this_board - boardtypes;
- while (NULL != (pcidev = pci_get_device(PCI_VENDOR_ID_ADVANTECH,
- PCI_ANY_ID, pcidev))) {
if (strcmp(this_board->name, DRV_NAME) == 0) {
for (i = 0; i < ARRAY_SIZE(boardtypes); ++i) {
if (pcidev->device == boardtypes[i].device_id) {
@@ -1368,47 +1365,21 @@ static struct pci_dev *pci1710_find_pci_dev(struct comedi_device *dev,
continue;
}
- /* Found matching vendor/device. */
- if (opt_bus || opt_slot) {
- /* Check bus/slot. */
- if (opt_bus != pcidev->bus->number
- || opt_slot != PCI_SLOT(pcidev->devfn))
- continue; /* no match */
- }
/*
* Look for device that isn't in use.
* Enable PCI device and request regions.
*/
if (comedi_pci_enable(pcidev, DRV_NAME)) {
- errstr =
- "failed to enable PCI device and request regions!";
continue;
}
/* fixup board_ptr in case we were using the dummy entry with the driver name */
dev->board_ptr = &boardtypes[board_index];
- break;
+ return pcidev;
}
-
- if (!pcidev) {
- if (opt_bus || opt_slot) {
- dev_err(dev->class_dev, "- Card at b:s %d:%d %s\n",
- opt_bus, opt_slot, errstr);
- } else {
- dev_err(dev->class_dev, "- Card %s\n", errstr);
- }
- return NULL;
- }
-
- pci_bus = pcidev->bus->number;
- pci_slot = PCI_SLOT(pcidev->devfn);
- pci_func = PCI_FUNC(pcidev->devfn);
- irq = pcidev->irq;
- iobase = pci_resource_start(pcidev, 2);
-
- dev_dbg(dev->class_dev, "b:s:f=%d:%d:%d, io=0x%4lx\n",
- pci_bus, pci_slot, pci_func, iobase);
-
- return pcidev;
+ dev_err(dev->class_dev,
+ "No supported board found! (req. bus %d, slot %d)\n",
+ bus, slot);
+ return NULL;
}
static int pci1710_attach(struct comedi_device *dev,