return (runflags & (SRF_ERROR | SRF_RUNNING)) ? false : true;
}
+/**
+ * comedi_set_spriv() - Set the subdevice private data pointer.
+ * @s: comedi_subdevice struct
+ * @data: pointer to the private data
+ *
+ * This also sets the subdevice runflags to allow the core to automatically
+ * free the private data during the detach.
+ */
+void comedi_set_spriv(struct comedi_subdevice *s, void *data)
+{
+ s->private = data;
+ comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV);
+}
+EXPORT_SYMBOL_GPL(comedi_set_spriv);
+
/*
This function restores a subdevice to an idle state.
*/
/* indicates an COMEDI_CB_ERROR event has occurred since the last
* command was started */
SRF_ERROR = 0x00000004,
- SRF_RUNNING = 0x08000000
+ SRF_RUNNING = 0x08000000,
+ SRF_FREE_SPRIV = 0x80000000, /* free s->private on detach */
};
bool comedi_is_subdevice_running(struct comedi_subdevice *s);
+void comedi_set_spriv(struct comedi_subdevice *s, void *data);
int comedi_check_chanlist(struct comedi_subdevice *s,
int n,
int comedi_alloc_subdevices(struct comedi_device *, int);
-void comedi_spriv_free(struct comedi_device *, int subdev_num);
-
int comedi_load_firmware(struct comedi_device *, struct device *,
const char *name,
int (*cb)(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;
if (dev->subdevices) {
for (i = 0; i < dev->n_subdevices; i++) {
s = &dev->subdevices[i];
+ if (s->runflags & SRF_FREE_SPRIV)
+ kfree(s->private);
comedi_free_subdevice_minor(s);
if (s->async) {
comedi_buf_alloc(dev, s, 0);
spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
if (!spriv)
return -ENOMEM;
+ comedi_set_spriv(s, spriv);
spriv->iobase = iobase;
spriv->io = io ? io : subdev_8255_io;
- s->private = spriv;
-
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = 24;
spriv = s->private;
release_region(spriv->iobase, _8255_SIZE);
}
- comedi_spriv_free(dev, i);
}
}
static void pci_8255_detach(struct comedi_device *dev)
{
struct pci_8255_private *devpriv = dev->private;
- int i;
- 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);
- comedi_spriv_free(dev, 2);
comedi_pci_disable(dev);
}
free_irq(dev->irq, dev);
if (dev->read_subdev)
kfree(dev->read_subdev->private);
- comedi_spriv_free(dev, 1);
comedi_pci_disable(dev);
}
{
if (dev->iobase)
apci2200_reset(dev);
- comedi_spriv_free(dev, 2);
comedi_pci_disable(dev);
}
spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
if (!spriv)
return -ENOMEM;
+ comedi_set_spriv(s, spriv);
spriv->iobase = iobase;
- s->private = spriv;
-
s->type = COMEDI_SUBD_TIMER;
s->subdev_flags = SDF_WRITEABLE;
s->n_chan = 1;
static void pci_dio_detach(struct comedi_device *dev)
{
struct pci_dio_private *devpriv = dev->private;
- struct comedi_subdevice *s;
- int i;
if (devpriv) {
if (devpriv->valid)
pci_dio_reset(dev);
}
- 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);
}
return 0;
}
-static void aio_aio12_8_detach(struct comedi_device *dev)
-{
- comedi_spriv_free(dev, 2);
- comedi_legacy_detach(dev);
-}
-
static struct comedi_driver aio_aio12_8_driver = {
.driver_name = "aio_aio12_8",
.module = THIS_MODULE,
.attach = aio_aio12_8_attach,
- .detach = aio_aio12_8_detach,
+ .detach = comedi_legacy_detach,
.board_name = &board_types[0].name,
.num_names = ARRAY_SIZE(board_types),
.offset = sizeof(struct aio12_8_boardtype),
subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
if (!subpriv)
return -ENOMEM;
+ comedi_set_spriv(s, subpriv);
subpriv->ofs = offset;
subpriv->valid_isns = valid_isns;
/* Disable interrupt sources. */
dio200_write8(dev, subpriv->ofs, 0);
- s->private = subpriv;
s->type = COMEDI_SUBD_DI;
s->subdev_flags = SDF_READABLE | SDF_CMD_READ;
if (layout->has_int_sce) {
subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
if (!subpriv)
return -ENOMEM;
+ comedi_set_spriv(s, subpriv);
- s->private = subpriv;
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
s->n_chan = 3;
subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
if (!subpriv)
return -ENOMEM;
+ comedi_set_spriv(s, subpriv);
+
subpriv->ofs = offset;
- s->private = subpriv;
+
s->type = COMEDI_SUBD_DIO;
s->subdev_flags = SDF_READABLE | SDF_WRITABLE;
s->n_chan = 24;
{
const struct dio200_board *thisboard = comedi_board(dev);
struct dio200_private *devpriv = dev->private;
- const struct dio200_layout *layout;
- unsigned n;
if (!thisboard || !devpriv)
return;
if (dev->irq)
free_irq(dev->irq, dev);
- if (dev->subdevices) {
- layout = dio200_board_layout(thisboard);
- for (n = 0; n < dev->n_subdevices; n++) {
- switch (layout->sdtype[n]) {
- case sd_8254:
- case sd_8255:
- case sd_intr:
- comedi_spriv_free(dev, n);
- break;
- case sd_timer:
- default:
- break;
- }
- }
- }
}
EXPORT_SYMBOL_GPL(amplc_dio200_common_detach);
return;
if (dev->iobase)
pc236_intr_disable(dev);
- comedi_spriv_free(dev, 0);
if (is_isa_board(thisboard)) {
comedi_legacy_detach(dev);
} else if (is_pci_board(thisboard)) {
{
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
- 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);
- comedi_spriv_free(dev, 2);
comedi_pci_disable(dev);
}
devpriv->ao_dma_desc_bus_addr);
}
}
- comedi_spriv_free(dev, 4);
comedi_pci_disable(dev);
}
return 0;
}
-static void cb_pcidda_detach(struct comedi_device *dev)
-{
- comedi_spriv_free(dev, 1);
- comedi_spriv_free(dev, 2);
- comedi_pci_disable(dev);
-}
-
static struct comedi_driver cb_pcidda_driver = {
.driver_name = "cb_pcidda",
.module = THIS_MODULE,
.auto_attach = cb_pcidda_auto_attach,
- .detach = cb_pcidda_detach,
+ .detach = comedi_pci_disable,
};
static int cb_pcidda_pci_probe(struct pci_dev *dev,
return 1;
}
-static void cb_pcimdda_detach(struct comedi_device *dev)
-{
- comedi_spriv_free(dev, 1);
- comedi_pci_disable(dev);
-}
-
static struct comedi_driver cb_pcimdda_driver = {
.driver_name = "cb_pcimdda",
.module = THIS_MODULE,
.auto_attach = cb_pcimdda_auto_attach,
- .detach = cb_pcimdda_detach,
+ .detach = comedi_pci_disable,
};
static int cb_pcimdda_pci_probe(struct pci_dev *dev,
{
struct daqboard2000_private *devpriv = dev->private;
- comedi_spriv_free(dev, 2);
if (dev->irq)
free_irq(dev->irq, dev);
if (devpriv) {
}
EXPORT_SYMBOL_GPL(das08_common_attach);
-void das08_common_detach(struct comedi_device *dev)
-{
- comedi_spriv_free(dev, 4);
-}
-EXPORT_SYMBOL_GPL(das08_common_detach);
-
static int __init das08_init(void)
{
return 0;
};
int das08_common_attach(struct comedi_device *dev, unsigned long iobase);
-void das08_common_detach(struct comedi_device *dev);
#endif /* _DAS08_H */
return das08_common_attach(dev, iobase);
}
-static void das08_cs_detach(struct comedi_device *dev)
-{
- das08_common_detach(dev);
- comedi_pcmcia_disable(dev);
-}
-
static struct comedi_driver driver_das08_cs = {
.driver_name = "das08_cs",
.module = THIS_MODULE,
.auto_attach = das08_cs_auto_attach,
- .detach = das08_cs_detach,
+ .detach = comedi_pcmcia_disable,
};
static int das08_pcmcia_attach(struct pcmcia_device *link)
return das08_common_attach(dev, dev->iobase);
}
-static void das08_isa_detach(struct comedi_device *dev)
-{
- das08_common_detach(dev);
- comedi_legacy_detach(dev);
-}
-
static struct comedi_driver das08_isa_driver = {
.driver_name = "isa-das08",
.module = THIS_MODULE,
.attach = das08_isa_attach,
- .detach = das08_isa_detach,
+ .detach = comedi_legacy_detach,
.board_name = &das08_isa_boards[0].name,
.num_names = ARRAY_SIZE(das08_isa_boards),
.offset = sizeof(das08_isa_boards[0]),
return das08_common_attach(dev, dev->iobase);
}
-static void das08_pci_detach(struct comedi_device *dev)
-{
- das08_common_detach(dev);
- comedi_pci_disable(dev);
-}
-
static struct comedi_driver das08_pci_comedi_driver = {
.driver_name = "pci-das08",
.module = THIS_MODULE,
.auto_attach = das08_pci_auto_attach,
- .detach = das08_pci_detach,
+ .detach = comedi_pci_disable,
};
static int das08_pci_probe(struct pci_dev *dev,
struct das16_private_struct *devpriv = dev->private;
das16_reset(dev);
- comedi_spriv_free(dev, 4);
if (devpriv) {
int i;
for (i = 0; i < 2; i++) {
{
struct das16m1_private_struct *devpriv = dev->private;
- comedi_spriv_free(dev, 3);
if (devpriv && devpriv->extra_iobase)
release_region(devpriv->extra_iobase, DAS16M1_SIZE2);
comedi_legacy_detach(dev);
return subdev->private;
}
-static struct ni_65xx_subdevice_private *ni_65xx_alloc_subdevice_private(void)
+static int ni_65xx_alloc_subdevice_private(struct comedi_subdevice *s)
{
- struct ni_65xx_subdevice_private *subdev_private =
- kzalloc(sizeof(struct ni_65xx_subdevice_private), GFP_KERNEL);
- if (subdev_private == NULL)
- return NULL;
- return subdev_private;
+ struct ni_65xx_subdevice_private *spriv;
+
+ spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
+ if (!spriv)
+ return -ENOMEM;
+ comedi_set_spriv(s, spriv);
+
+ return 0;
}
static int ni_65xx_config_filter(struct comedi_device *dev,
s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config;
s->insn_bits = ni_65xx_dio_insn_bits;
- s->private = ni_65xx_alloc_subdevice_private();
- if (s->private == NULL)
- return -ENOMEM;
+ ret = ni_65xx_alloc_subdevice_private(s);
+ if (ret)
+ return ret;
sprivate(s)->base_port = 0;
} else {
s->type = COMEDI_SUBD_UNUSED;
s->range_table = &range_digital;
s->maxdata = 1;
s->insn_bits = ni_65xx_dio_insn_bits;
- s->private = ni_65xx_alloc_subdevice_private();
- if (s->private == NULL)
- return -ENOMEM;
+ ret = ni_65xx_alloc_subdevice_private(s);
+ if (ret)
+ return ret;
sprivate(s)->base_port = board->num_di_ports;
} else {
s->type = COMEDI_SUBD_UNUSED;
s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config;
s->insn_bits = ni_65xx_dio_insn_bits;
- s->private = ni_65xx_alloc_subdevice_private();
- if (s->private == NULL)
- return -ENOMEM;
+ ret = ni_65xx_alloc_subdevice_private(s);
+ if (ret)
+ return ret;
sprivate(s)->base_port = 0;
for (i = 0; i < board->num_dio_ports; ++i) {
/* configure all ports for input */
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) {
if (devpriv->mite) {
mite_unsetup(devpriv->mite);
static void atmio16d_detach(struct comedi_device *dev)
{
- comedi_spriv_free(dev, 3);
reset_atmio16d(dev);
comedi_legacy_detach(dev);
}
return 0;
}
-static void dio24_detach(struct comedi_device *dev)
-{
- comedi_spriv_free(dev, 0);
- comedi_pcmcia_disable(dev);
-}
-
static struct comedi_driver driver_dio24 = {
.driver_name = "ni_daq_dio24",
.module = THIS_MODULE,
.auto_attach = dio24_auto_attach,
- .detach = dio24_detach,
+ .detach = comedi_pcmcia_disable,
};
static int dio24_cs_attach(struct pcmcia_device *link)
}
EXPORT_SYMBOL_GPL(labpc_common_attach);
-void labpc_common_detach(struct comedi_device *dev)
-{
- comedi_spriv_free(dev, 2);
-}
-EXPORT_SYMBOL_GPL(labpc_common_detach);
-
#if IS_ENABLED(CONFIG_COMEDI_NI_LABPC_ISA)
static int labpc_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{
{
struct labpc_private *devpriv = dev->private;
- labpc_common_detach(dev);
-
if (devpriv) {
kfree(devpriv->dma_buffer);
if (devpriv->dma_chan)
int labpc_common_attach(struct comedi_device *dev,
unsigned int irq, unsigned long isr_flags);
-void labpc_common_detach(struct comedi_device *dev);
#endif /* _NI_LABPC_H */
return labpc_common_attach(dev, link->irq, IRQF_SHARED);
}
-static void labpc_detach(struct comedi_device *dev)
-{
- labpc_common_detach(dev);
- comedi_pcmcia_disable(dev);
-}
-
static struct comedi_driver driver_labpc_cs = {
.driver_name = "ni_labpc_cs",
.module = THIS_MODULE,
.auto_attach = labpc_auto_attach,
- .detach = labpc_detach,
+ .detach = comedi_pcmcia_disable,
};
static int labpc_cs_attach(struct pcmcia_device *link)
{
struct labpc_private *devpriv = dev->private;
- labpc_common_detach(dev);
-
if (devpriv && devpriv->mite) {
mite_unsetup(devpriv->mite);
mite_free(devpriv->mite);
ni_gpct_device_destroy(devpriv->counter_dev);
}
}
- comedi_spriv_free(dev, NI_8255_DIO_SUBDEV);
}
static void init_ao_67xx(struct comedi_device *dev, struct comedi_subdevice *s)
return 0;
}
-static void pcl724_detach(struct comedi_device *dev)
-{
- int i;
-
- for (i = 0; i < dev->n_subdevices; i++)
- comedi_spriv_free(dev, i);
- comedi_legacy_detach(dev);
-}
-
static struct comedi_driver pcl724_driver = {
.driver_name = "pcl724",
.module = THIS_MODULE,
.attach = pcl724_attach,
- .detach = pcl724_detach,
+ .detach = comedi_legacy_detach,
.board_name = &boardtypes[0].name,
.num_names = ARRAY_SIZE(boardtypes),
.offset = sizeof(struct pcl724_board),
return 0;
}
-static void pcm3724_detach(struct comedi_device *dev)
-{
- int i;
-
- for (i = 0; i < dev->n_subdevices; i++)
- comedi_spriv_free(dev, i);
- comedi_legacy_detach(dev);
-}
-
static struct comedi_driver pcm3724_driver = {
.driver_name = "pcm3724",
.module = THIS_MODULE,
.attach = pcm3724_attach,
- .detach = pcm3724_detach,
+ .detach = comedi_legacy_detach,
};
module_comedi_driver(pcm3724_driver);