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

staging: comedi: dyna_pci10xx: factor out the "find pci device" code

Factor the "find pci device" code out of the attach function.
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 9e9e13f5
...@@ -229,36 +229,15 @@ static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev, ...@@ -229,36 +229,15 @@ static int dyna_pci10xx_do_insn_bits(struct comedi_device *dev,
return insn->n; return insn->n;
} }
/******************************************************************************/ static struct pci_dev *dyna_pci10xx_find_pci_dev(struct comedi_device *dev,
/*********************** INITIALIZATION FUNCTIONS *****************************/ struct comedi_devconfig *it)
/******************************************************************************/
static int dyna_pci10xx_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
{ {
struct comedi_subdevice *s; struct pci_dev *pcidev = NULL;
struct pci_dev *pcidev; int opt_bus = it->options[0];
unsigned int opt_bus, opt_slot; int opt_slot = it->options[1];
int board_index, i; int board_index;
int ret; int i;
mutex_lock(&start_stop_sem);
if (alloc_private(dev, sizeof(struct dyna_pci10xx_private)) < 0) {
printk(KERN_ERR "comedi: dyna_pci10xx: "
"failed to allocate memory!\n");
mutex_unlock(&start_stop_sem);
return -ENOMEM;
}
opt_bus = it->options[0];
opt_slot = it->options[1];
dev->board_name = thisboard->name;
dev->irq = 0;
/*
* Probe the PCI bus and located the matching device
*/
for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); for (pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
pcidev != NULL; pcidev != NULL;
pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) { pcidev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, pcidev)) {
...@@ -285,8 +264,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev, ...@@ -285,8 +264,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
goto found; goto found;
} }
printk(KERN_ERR "comedi: dyna_pci10xx: no supported device found!\n"); printk(KERN_ERR "comedi: dyna_pci10xx: no supported device found!\n");
mutex_unlock(&start_stop_sem); return NULL;
return -EIO;
found: found:
...@@ -299,9 +277,38 @@ static int dyna_pci10xx_attach(struct comedi_device *dev, ...@@ -299,9 +277,38 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
printk(KERN_ERR "comedi: dyna_pci10xx: " printk(KERN_ERR "comedi: dyna_pci10xx: "
"invalid PCI device\n"); "invalid PCI device\n");
} }
return NULL;
}
dev->board_ptr = &boardtypes[board_index];
return pcidev;
}
static int dyna_pci10xx_attach(struct comedi_device *dev,
struct comedi_devconfig *it)
{
struct pci_dev *pcidev;
struct comedi_subdevice *s;
int ret;
mutex_lock(&start_stop_sem);
if (alloc_private(dev, sizeof(struct dyna_pci10xx_private)) < 0) {
printk(KERN_ERR "comedi: dyna_pci10xx: "
"failed to allocate memory!\n");
mutex_unlock(&start_stop_sem);
return -ENOMEM;
}
pcidev = dyna_pci10xx_find_pci_dev(dev, it);
if (!pcidev) {
mutex_unlock(&start_stop_sem); mutex_unlock(&start_stop_sem);
return -EIO; return -EIO;
} }
devpriv->pci_dev = pcidev;
dev->board_name = thisboard->name;
dev->irq = 0;
if (comedi_pci_enable(pcidev, DRV_NAME)) { if (comedi_pci_enable(pcidev, DRV_NAME)) {
printk(KERN_ERR "comedi: dyna_pci10xx: " printk(KERN_ERR "comedi: dyna_pci10xx: "
...@@ -311,8 +318,6 @@ static int dyna_pci10xx_attach(struct comedi_device *dev, ...@@ -311,8 +318,6 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
} }
mutex_init(&devpriv->mutex); mutex_init(&devpriv->mutex);
dev->board_ptr = &boardtypes[board_index];
devpriv->pci_dev = pcidev;
printk(KERN_INFO "comedi: dyna_pci10xx: device found!\n"); printk(KERN_INFO "comedi: dyna_pci10xx: device found!\n");
...@@ -375,7 +380,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev, ...@@ -375,7 +380,7 @@ static int dyna_pci10xx_attach(struct comedi_device *dev,
mutex_unlock(&start_stop_sem); mutex_unlock(&start_stop_sem);
printk(KERN_INFO "comedi: dyna_pci10xx: %s - device setup completed!\n", printk(KERN_INFO "comedi: dyna_pci10xx: %s - device setup completed!\n",
boardtypes[board_index].name); thisboard->name);
return 1; return 1;
} }
......
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