aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH Hartley Sweeten <hartleys@visionengravers.com>2012-07-18 22:03:43 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-07-19 19:51:39 -0400
commit81f9334602a4bec05614cdc228ac5515f03b854e (patch)
treeef6097a8ea7ba30c6c9933e199f9fadb1d11f7b2
parentb92169fd857421825e16f68d178c48f8727e75cc (diff)
staging: comedi: me_daq: cleanup "find pci device" code
Cleanup the "find pci device" code so that it follows the style of the other comedi pci drivers. 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>
-rw-r--r--drivers/staging/comedi/drivers/me_daq.c63
1 files changed, 23 insertions, 40 deletions
diff --git a/drivers/staging/comedi/drivers/me_daq.c b/drivers/staging/comedi/drivers/me_daq.c
index dc0fbbd895ff..cd66af936dc5 100644
--- a/drivers/staging/comedi/drivers/me_daq.c
+++ b/drivers/staging/comedi/drivers/me_daq.c
@@ -231,8 +231,6 @@ static const struct me_board me_boards[] = {
231 } 231 }
232}; 232};
233 233
234#define me_board_nbr (sizeof(me_boards)/sizeof(struct me_board))
235
236/* Private data structure */ 234/* Private data structure */
237struct me_private_data { 235struct me_private_data {
238 struct pci_dev *pci_device; 236 struct pci_dev *pci_device;
@@ -613,49 +611,34 @@ static int me_reset(struct comedi_device *dev)
613static struct pci_dev *me_find_pci_dev(struct comedi_device *dev, 611static struct pci_dev *me_find_pci_dev(struct comedi_device *dev,
614 struct comedi_devconfig *it) 612 struct comedi_devconfig *it)
615{ 613{
616 struct pci_dev *pci_device = NULL; 614 const struct me_board *board;
615 struct pci_dev *pcidev = NULL;
616 int bus = it->options[0];
617 int slot = it->options[1];
617 int i; 618 int i;
618 619
619 /* Probe the device to determine what device in the series it is. */ 620 for_each_pci_dev(pcidev) {
620 for_each_pci_dev(pci_device) { 621 if (bus || slot) {
621 if (pci_device->vendor == PCI_VENDOR_ID_MEILHAUS) { 622 if (pcidev->bus->number != bus ||
622 for (i = 0; i < me_board_nbr; i++) { 623 PCI_SLOT(pcidev->devfn) != slot)
623 if (me_boards[i].device_id == 624 continue;
624 pci_device->device) {
625 /*
626 * was a particular bus/slot requested?
627 */
628 if ((it->options[0] != 0)
629 || (it->options[1] != 0)) {
630 /*
631 * are we on the wrong bus/slot?
632 */
633 if (pci_device->bus->number !=
634 it->options[0]
635 ||
636 PCI_SLOT(pci_device->devfn)
637 != it->options[1]) {
638 continue;
639 }
640 }
641
642 dev->board_ptr = me_boards + i;
643 goto found;
644 }
645 }
646 } 625 }
647 } 626 if (pcidev->vendor != PCI_VENDOR_ID_MEILHAUS)
627 continue;
648 628
649 printk(KERN_ERR 629 for (i = 0; i < ARRAY_SIZE(me_boards); i++) {
650 "comedi%d: no supported board found! (req. bus/slot : %d/%d)\n", 630 board = &me_boards[i];
651 dev->minor, it->options[0], it->options[1]); 631 if (board->device_id != pcidev->device)
652 return NULL; 632 continue;
653 633
654found: 634 dev->board_ptr = board;
655 printk(KERN_INFO "comedi%d: found %s at PCI bus %d, slot %d\n", 635 return pcidev;
656 dev->minor, me_boards[i].name, 636 }
657 pci_device->bus->number, PCI_SLOT(pci_device->devfn)); 637 }
658 return pci_device; 638 dev_err(dev->class_dev,
639 "No supported board found! (req. bus %d, slot %d)\n",
640 bus, slot);
641 return NULL;
659} 642}
660 643
661static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it) 644static int me_attach(struct comedi_device *dev, struct comedi_devconfig *it)