staging: comedi: ni_labpc_common: move comedi_alloc_devpriv() to common code

The ni_labpc_common module is used by the ni_labpc, ni_labpc_pci, and ni_labpc_cs
drivers to provide the common code support. Those drivers currently all call
comedi_alloc_devpriv() to allocate the private data before calling the common
attach function.

For aesthetics, move the private data allocation into the common code.

Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
H Hartley Sweeten 2015-01-21 15:11:44 -07:00 committed by Greg Kroah-Hartman
parent c0e4a8decb
commit 83d682bda1
4 changed files with 5 additions and 16 deletions

View File

@ -84,15 +84,10 @@ static const struct labpc_boardinfo labpc_boards[] = {
static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it) static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{ {
struct labpc_private *devpriv;
unsigned int irq = it->options[1]; unsigned int irq = it->options[1];
unsigned int dma_chan = it->options[2]; unsigned int dma_chan = it->options[2];
int ret; int ret;
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv)
return -ENOMEM;
ret = comedi_request_region(dev, it->options[0], 0x20); ret = comedi_request_region(dev, it->options[0], 0x20);
if (ret) if (ret)
return ret; return ret;

View File

@ -1215,11 +1215,15 @@ int labpc_common_attach(struct comedi_device *dev,
unsigned int irq, unsigned long isr_flags) unsigned int irq, unsigned long isr_flags)
{ {
const struct labpc_boardinfo *board = dev->board_ptr; const struct labpc_boardinfo *board = dev->board_ptr;
struct labpc_private *devpriv = dev->private; struct labpc_private *devpriv;
struct comedi_subdevice *s; struct comedi_subdevice *s;
int ret; int ret;
int i; int i;
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv)
return -ENOMEM;
if (dev->mmio) { if (dev->mmio) {
devpriv->read_byte = labpc_readb; devpriv->read_byte = labpc_readb;
devpriv->write_byte = labpc_writeb; devpriv->write_byte = labpc_writeb;

View File

@ -80,7 +80,6 @@ static int labpc_auto_attach(struct comedi_device *dev,
unsigned long context) unsigned long context)
{ {
struct pcmcia_device *link = comedi_to_pcmcia_dev(dev); struct pcmcia_device *link = comedi_to_pcmcia_dev(dev);
struct labpc_private *devpriv;
int ret; int ret;
/* The ni_labpc driver needs the board_ptr */ /* The ni_labpc driver needs the board_ptr */
@ -96,10 +95,6 @@ static int labpc_auto_attach(struct comedi_device *dev,
if (!link->irq) if (!link->irq)
return -EINVAL; return -EINVAL;
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv)
return -ENOMEM;
return labpc_common_attach(dev, link->irq, IRQF_SHARED); return labpc_common_attach(dev, link->irq, IRQF_SHARED);
} }

View File

@ -79,7 +79,6 @@ static int labpc_pci_auto_attach(struct comedi_device *dev,
{ {
struct pci_dev *pcidev = comedi_to_pci_dev(dev); struct pci_dev *pcidev = comedi_to_pci_dev(dev);
const struct labpc_boardinfo *board = NULL; const struct labpc_boardinfo *board = NULL;
struct labpc_private *devpriv;
int ret; int ret;
if (context < ARRAY_SIZE(labpc_pci_boards)) if (context < ARRAY_SIZE(labpc_pci_boards))
@ -101,10 +100,6 @@ static int labpc_pci_auto_attach(struct comedi_device *dev,
if (!dev->mmio) if (!dev->mmio)
return -ENOMEM; return -ENOMEM;
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv)
return -ENOMEM;
return labpc_common_attach(dev, pcidev->irq, IRQF_SHARED); return labpc_common_attach(dev, pcidev->irq, IRQF_SHARED);
} }