summaryrefslogtreecommitdiff
path: root/drivers/staging/comedi/drivers/8255_pci.c
diff options
context:
space:
mode:
authorH Hartley Sweeten <hsweeten@visionengravers.com>2013-04-15 16:41:57 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-17 10:13:01 -0700
commit2f69915c728c3be41e12dbbbdd4eeb8d3388d58c (patch)
tree973bb9528708de0b589471d0d1aba4cfa951de79 /drivers/staging/comedi/drivers/8255_pci.c
parentf4362867e047a254b745741d09fa68a583f50499 (diff)
staging: comedi: introduce, and use, comedi_spriv_free()
The comedi_subdevice 'private' variable is a void * that is available for the subdevice to use in manner. It's common in comedi drivers for the driver to allocate memory for a subdevice and store the pointer to that memory in the 'private' variable. It's then the responsibility of the driver to free that memory when the device is detached. Due to how the attach/detach works in comedi, the drivers need to do some sanity checking before they can free the allocated memory during the detach. Introduce a helper function, comedi_spriv_free(), to handle freeing the private data allocated for a subdevice. This allows moving all the sanity checks into the helper function and makes it safe to call with any context. It also allows removing some of the boilerplate code in the (*detach) functions. Remove the subdev_8255_cleanup() export in the 8255 subdevice driver as well as the addi_watchdog_cleanup() export in the addi_watchdog driver and use the new helper instead. The amplc_dio200_common driver uses a number of local helper functions to free the private data for it's subdevices. Remove those as well and use the new helper. 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>
Diffstat (limited to 'drivers/staging/comedi/drivers/8255_pci.c')
-rw-r--r--drivers/staging/comedi/drivers/8255_pci.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/drivers/staging/comedi/drivers/8255_pci.c b/drivers/staging/comedi/drivers/8255_pci.c
index de54ad3a64e6..76dec96aeb2a 100644
--- a/drivers/staging/comedi/drivers/8255_pci.c
+++ b/drivers/staging/comedi/drivers/8255_pci.c
@@ -241,20 +241,12 @@ static int pci_8255_auto_attach(struct comedi_device *dev,
static void pci_8255_detach(struct comedi_device *dev)
{
- const struct pci_8255_boardinfo *board = comedi_board(dev);
struct pci_8255_private *devpriv = dev->private;
- struct comedi_subdevice *s;
int i;
- if (!board || !devpriv)
- return;
- if (dev->subdevices) {
- for (i = 0; i < board->n_8255; i++) {
- s = &dev->subdevices[i];
- subdev_8255_cleanup(dev, s);
- }
- }
- if (devpriv->mmio_base)
+ for (i = 0; i < dev->n_subdevices; i++)
+ comedi_spriv_free(dev, i);
+ if (devpriv && devpriv->mmio_base)
iounmap(devpriv->mmio_base);
comedi_pci_disable(dev);
}