int comedi_alloc_subdevices(struct comedi_device *, int);
+void comedi_spriv_free(struct comedi_device *, int subdev_num);
+
int __comedi_request_region(struct comedi_device *,
unsigned long start, unsigned long len);
int comedi_request_region(struct comedi_device *,
}
EXPORT_SYMBOL_GPL(comedi_alloc_subdevices);
+void comedi_spriv_free(struct comedi_device *dev, int subdev_num)
+{
+ struct comedi_subdevice *s;
+
+ if (dev->subdevices && subdev_num < dev->n_subdevices) {
+ s = &dev->subdevices[subdev_num];
+ kfree(s->private);
+ s->private = NULL;
+ }
+}
+EXPORT_SYMBOL_GPL(comedi_spriv_free);
+
static void cleanup_device(struct comedi_device *dev)
{
int i;
}
EXPORT_SYMBOL_GPL(subdev_8255_init_irq);
-void subdev_8255_cleanup(struct comedi_device *dev, struct comedi_subdevice *s)
-{
- kfree(s->private);
-}
-EXPORT_SYMBOL_GPL(subdev_8255_cleanup);
-
/*
Start of the 8255 standalone device
spriv = s->private;
release_region(spriv->iobase, _8255_SIZE);
}
- subdev_8255_cleanup(dev, s);
+ comedi_spriv_free(dev, i);
}
}
int subdev_8255_init_irq(struct comedi_device *dev, struct comedi_subdevice *s,
int (*io) (int, int, int, unsigned long),
unsigned long iobase);
-void subdev_8255_cleanup(struct comedi_device *dev, struct comedi_subdevice *s);
void subdev_8255_interrupt(struct comedi_device *dev,
struct comedi_subdevice *s);
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);
}
{
if (dev->iobase)
apci1516_reset(dev);
- if (dev->subdevices)
- addi_watchdog_cleanup(&dev->subdevices[2]);
+ comedi_spriv_free(dev, 2);
comedi_pci_disable(dev);
}
free_irq(dev->irq, dev);
if (dev->read_subdev)
kfree(dev->read_subdev->private);
- if (dev->subdevices)
- addi_watchdog_cleanup(&dev->subdevices[1]);
+ comedi_spriv_free(dev, 1);
comedi_pci_disable(dev);
}
{
if (dev->iobase)
apci2200_reset(dev);
- if (dev->subdevices)
- addi_watchdog_cleanup(&dev->subdevices[2]);
+ comedi_spriv_free(dev, 2);
comedi_pci_disable(dev);
}
}
EXPORT_SYMBOL_GPL(addi_watchdog_init);
-void addi_watchdog_cleanup(struct comedi_subdevice *s)
-{
- kfree(s->private);
-}
-EXPORT_SYMBOL_GPL(addi_watchdog_cleanup);
-
static int __init addi_watchdog_module_init(void)
{
return 0;
void addi_watchdog_reset(unsigned long iobase);
int addi_watchdog_init(struct comedi_subdevice *, unsigned long iobase);
-void addi_watchdog_cleanup(struct comedi_subdevice *s);
#endif
if (devpriv->valid)
pci_dio_reset(dev);
}
- if (dev->subdevices) {
- for (i = 0; i < dev->n_subdevices; i++) {
- s = &dev->subdevices[i];
- if (s->type == COMEDI_SUBD_DIO)
- subdev_8255_cleanup(dev, s);
- s->private = NULL;
- }
+ for (i = 0; i < dev->n_subdevices; i++) {
+ s = &dev->subdevices[i];
+ if (s->type == COMEDI_SUBD_DIO)
+ comedi_spriv_free(dev, i);
+ s->private = NULL; /* some private data is static */
}
comedi_pci_disable(dev);
}
static void aio_aio12_8_detach(struct comedi_device *dev)
{
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[2]);
+ comedi_spriv_free(dev, 2);
if (dev->iobase)
release_region(dev->iobase, 24);
}
}
/*
- * This function cleans up an 'INTERRUPT' subdevice.
- */
-static void
-dio200_subdev_intr_cleanup(struct comedi_device *dev,
- struct comedi_subdevice *s)
-{
- struct dio200_subdev_intr *subpriv = s->private;
- kfree(subpriv);
-}
-
-/*
* Interrupt service routine.
*/
static irqreturn_t dio200_interrupt(int irq, void *d)
}
/*
- * This function cleans up an '8254' counter subdevice.
- */
-static void
-dio200_subdev_8254_cleanup(struct comedi_device *dev,
- struct comedi_subdevice *s)
-{
- struct dio200_subdev_intr *subpriv = s->private;
- kfree(subpriv);
-}
-
-/*
* This function sets I/O directions for an '8255' DIO subdevice.
*/
static void dio200_subdev_8255_set_dir(struct comedi_device *dev,
}
/*
- * This function cleans up an '8255' DIO subdevice.
- */
-static void dio200_subdev_8255_cleanup(struct comedi_device *dev,
- struct comedi_subdevice *s)
-{
- struct dio200_subdev_8255 *subpriv = s->private;
-
- kfree(subpriv);
-}
-
-/*
* Handle 'insn_read' for a timer subdevice.
*/
static int dio200_subdev_timer_read(struct comedi_device *dev,
return 0;
}
-/*
- * This function cleans up a timer subdevice.
- */
-static void dio200_subdev_timer_cleanup(struct comedi_device *dev,
- struct comedi_subdevice *s)
-{
- /* Nothing to do. */
-}
-
void amplc_dio200_set_enhance(struct comedi_device *dev, unsigned char val)
{
dio200_write8(dev, DIO200_ENHANCE, val);
if (dev->subdevices) {
layout = dio200_board_layout(thisboard);
for (n = 0; n < dev->n_subdevices; n++) {
- struct comedi_subdevice *s = &dev->subdevices[n];
switch (layout->sdtype[n]) {
case sd_8254:
- dio200_subdev_8254_cleanup(dev, s);
- break;
case sd_8255:
- dio200_subdev_8255_cleanup(dev, s);
- break;
case sd_intr:
- dio200_subdev_intr_cleanup(dev, s);
+ comedi_spriv_free(dev, n);
break;
case sd_timer:
- dio200_subdev_timer_cleanup(dev, s);
- break;
default:
break;
}
pc236_intr_disable(dev);
if (dev->irq)
free_irq(dev->irq, dev);
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[0]);
+ comedi_spriv_free(dev, 0);
if (is_isa_board(thisboard)) {
if (dev->iobase)
release_region(dev->iobase, PC236_IO_SIZE);
static void pci230_detach(struct comedi_device *dev)
{
- const struct pci230_board *thisboard = comedi_board(dev);
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
- if (dev->subdevices && thisboard->have_dio)
- subdev_8255_cleanup(dev, &dev->subdevices[2]);
+ comedi_spriv_free(dev, 2);
if (dev->irq)
free_irq(dev->irq, dev);
comedi_pci_disable(dev);
}
if (dev->irq)
free_irq(dev->irq, dev);
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[2]);
+ comedi_spriv_free(dev, 2);
comedi_pci_disable(dev);
}
devpriv->ao_dma_desc_bus_addr);
}
}
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[4]);
+ comedi_spriv_free(dev, 4);
comedi_pci_disable(dev);
}
static void cb_pcidda_detach(struct comedi_device *dev)
{
- if (dev->subdevices) {
- subdev_8255_cleanup(dev, &dev->subdevices[1]);
- subdev_8255_cleanup(dev, &dev->subdevices[2]);
- }
+ comedi_spriv_free(dev, 1);
+ comedi_spriv_free(dev, 2);
comedi_pci_disable(dev);
}
static void cb_pcimdda_detach(struct comedi_device *dev)
{
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[1]);
+ comedi_spriv_free(dev, 1);
comedi_pci_disable(dev);
}
{
struct daqboard2000_private *devpriv = dev->private;
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[2]);
+ comedi_spriv_free(dev, 2);
if (dev->irq)
free_irq(dev->irq, dev);
if (devpriv) {
void das08_common_detach(struct comedi_device *dev)
{
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[4]);
+ comedi_spriv_free(dev, 4);
}
EXPORT_SYMBOL_GPL(das08_common_detach);
struct das16_private_struct *devpriv = dev->private;
das16_reset(dev);
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[4]);
+ comedi_spriv_free(dev, 4);
if (devpriv) {
int i;
for (i = 0; i < 2; i++) {
static void das16m1_detach(struct comedi_device *dev)
{
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[3]);
+ comedi_spriv_free(dev, 3);
if (dev->irq)
free_irq(dev->irq, dev);
if (dev->iobase) {
static void ni_65xx_detach(struct comedi_device *dev)
{
struct ni_65xx_private *devpriv = dev->private;
+ int i;
if (devpriv && devpriv->mite && devpriv->mite->daq_io_addr) {
writeb(0x00,
}
if (dev->irq)
free_irq(dev->irq, dev);
+ for (i = 0; i < dev->n_subdevices; ++i)
+ comedi_spriv_free(dev, i);
if (devpriv) {
- struct comedi_subdevice *s;
- unsigned i;
-
- for (i = 0; i < dev->n_subdevices; ++i) {
- s = &dev->subdevices[i];
- kfree(s->private);
- s->private = NULL;
- }
if (devpriv->mite) {
mite_unsetup(devpriv->mite);
mite_free(devpriv->mite);
static void atmio16d_detach(struct comedi_device *dev)
{
- const struct atmio16_board_t *board = comedi_board(dev);
- struct comedi_subdevice *s;
-
- if (dev->subdevices && board->has_8255) {
- s = &dev->subdevices[3];
- subdev_8255_cleanup(dev, s);
- }
+ comedi_spriv_free(dev, 3);
if (dev->irq)
free_irq(dev->irq, dev);
reset_atmio16d(dev);
static void dio24_detach(struct comedi_device *dev)
{
- if (dev->subdevices)
- subdev_8255_cleanup(dev, &dev->subdevices[0]);
+ comedi_spriv_free(dev, 0);
comedi_pcmcia_disable(dev);
}
{
const struct labpc_boardinfo *board = comedi_board(dev);
struct labpc_private *devpriv = dev->private;
- struct comedi_subdevice *s;
if (!board)
return;
- if (dev->subdevices) {
- s = &dev->subdevices[2];
- subdev_8255_cleanup(dev, s);
- }
+ comedi_spriv_free(dev, 2);
#ifdef CONFIG_ISA_DMA_API
/* only free stuff if it has been allocated by _attach */
kfree(devpriv->dma_buffer);
static void mio_common_detach(struct comedi_device *dev)
{
- const struct ni_board_struct *board = comedi_board(dev);
struct ni_private *devpriv = dev->private;
- struct comedi_subdevice *s;
if (devpriv) {
if (devpriv->counter_dev) {
ni_gpct_device_destroy(devpriv->counter_dev);
}
}
- if (dev->subdevices && board->has_8255) {
- s = &dev->subdevices[NI_8255_DIO_SUBDEV];
- subdev_8255_cleanup(dev, s);
- }
+ comedi_spriv_free(dev, NI_8255_DIO_SUBDEV);
}
static void init_ao_67xx(struct comedi_device *dev, struct comedi_subdevice *s)
static void pcl724_detach(struct comedi_device *dev)
{
const struct pcl724_board *board = comedi_board(dev);
- struct comedi_subdevice *s;
int i;
- for (i = 0; i < dev->n_subdevices; i++) {
- s = &dev->subdevices[i];
- subdev_8255_cleanup(dev, s);
- }
+ for (i = 0; i < dev->n_subdevices; i++)
+ comedi_spriv_free(dev, i);
#ifdef PCL724_IRQ
if (dev->irq)
free_irq(dev->irq, dev);
static void pcm3724_detach(struct comedi_device *dev)
{
- struct comedi_subdevice *s;
int i;
- if (dev->subdevices) {
- for (i = 0; i < dev->n_subdevices; i++) {
- s = &dev->subdevices[i];
- subdev_8255_cleanup(dev, s);
- }
- }
+ for (i = 0; i < dev->n_subdevices; i++)
+ comedi_spriv_free(dev, i);
if (dev->iobase)
release_region(dev->iobase, PCM3724_SIZE);
}