Commit 1c16519f authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

staging: comedi: amplc_pc263: cleanup "find pci device" code

For aesthetic reasons, rename the function and pass the
comedi_devconfig struct instead of pre-parsing out the bus/slot
information.

Use for_each_pci_dev() instead of open-coding the loop using
pci_get_device().

Consolidate the dev_err messages when a pci device is not found.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b6d446b5
...@@ -121,26 +121,27 @@ static const struct pc263_board *pc263_find_pci_board(struct pci_dev *pci_dev) ...@@ -121,26 +121,27 @@ static const struct pc263_board *pc263_find_pci_board(struct pci_dev *pci_dev)
* This function looks for a PCI device matching the requested board name, * This function looks for a PCI device matching the requested board name,
* bus and slot. * bus and slot.
*/ */
static struct pci_dev * static struct pci_dev *pc263_find_pci_dev(struct comedi_device *dev,
pc263_find_pci(struct comedi_device *dev, int bus, int slot) struct comedi_devconfig *it)
{ {
const struct pc263_board *thisboard = comedi_board(dev); const struct pc263_board *thisboard = comedi_board(dev);
struct pci_dev *pci_dev = NULL; struct pci_dev *pci_dev = NULL;
int bus = it->options[0];
int slot = it->options[1];
/* Look for matching PCI device. */ for_each_pci_dev(pci_dev) {
for (pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON, PCI_ANY_ID, NULL);
pci_dev != NULL;
pci_dev = pci_get_device(PCI_VENDOR_ID_AMPLICON,
PCI_ANY_ID, pci_dev)) {
/* If bus/slot specified, check them. */
if (bus || slot) { if (bus || slot) {
if (bus != pci_dev->bus->number if (bus != pci_dev->bus->number ||
|| slot != PCI_SLOT(pci_dev->devfn)) slot != PCI_SLOT(pci_dev->devfn))
continue; continue;
} }
if (pci_dev->vendor != PCI_VENDOR_ID_AMPLICON)
continue;
if (thisboard->model == anypci_model) { if (thisboard->model == anypci_model) {
/* Wildcard board matches any supported PCI board. */ /* Wildcard board matches any supported PCI board. */
const struct pc263_board *foundboard; const struct pc263_board *foundboard;
foundboard = pc263_find_pci_board(pci_dev); foundboard = pc263_find_pci_board(pci_dev);
if (foundboard == NULL) if (foundboard == NULL)
continue; continue;
...@@ -151,19 +152,11 @@ pc263_find_pci(struct comedi_device *dev, int bus, int slot) ...@@ -151,19 +152,11 @@ pc263_find_pci(struct comedi_device *dev, int bus, int slot)
if (pci_dev->device != thisboard->devid) if (pci_dev->device != thisboard->devid)
continue; continue;
} }
/* Found a match. */
return pci_dev; return pci_dev;
} }
/* No match found. */ dev_err(dev->class_dev,
if (bus || slot) { "No supported board found! (req. bus %d, slot %d)\n",
dev_err(dev->class_dev, bus, slot);
"error! no %s found at pci %02x:%02x!\n",
thisboard->name, bus, slot);
} else {
dev_err(dev->class_dev, "error! no %s found!\n",
thisboard->name);
}
return NULL; return NULL;
} }
/* /*
...@@ -285,17 +278,14 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -285,17 +278,14 @@ static int pc263_attach(struct comedi_device *dev, struct comedi_devconfig *it)
} else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) && } else if (IS_ENABLED(CONFIG_COMEDI_AMPLC_PC263_PCI) &&
thisboard->bustype == pci_bustype) { thisboard->bustype == pci_bustype) {
struct pci_dev *pci_dev; struct pci_dev *pci_dev;
int bus, slot;
ret = alloc_private(dev, sizeof(struct pc263_private)); ret = alloc_private(dev, sizeof(struct pc263_private));
if (ret < 0) { if (ret < 0) {
dev_err(dev->class_dev, "error! out of memory!\n"); dev_err(dev->class_dev, "error! out of memory!\n");
return ret; return ret;
} }
bus = it->options[0]; pci_dev = pc263_find_pci_dev(dev, it);
slot = it->options[1]; if (!pci_dev)
pci_dev = pc263_find_pci(dev, bus, slot);
if (pci_dev == NULL)
return -EIO; return -EIO;
return pc263_pci_common_attach(dev, pci_dev); return pc263_pci_common_attach(dev, pci_dev);
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment