}
/**
- * comedi_set_spriv() - Set the subdevice private data pointer.
+ * comedi_alloc_spriv() - Allocate memory for the subdevice private data.
* @s: comedi_subdevice struct
- * @data: pointer to the private data
+ * @size: size of the memory to allocate
*
* 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)
+void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size)
{
- s->private = data;
- comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV);
+ s->private = kzalloc(size, GFP_KERNEL);
+ if (s->private)
+ comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV);
+ return s->private;
}
-EXPORT_SYMBOL_GPL(comedi_set_spriv);
+EXPORT_SYMBOL_GPL(comedi_alloc_spriv);
/*
This function restores a subdevice to an idle state.
};
bool comedi_is_subdevice_running(struct comedi_subdevice *s);
-void comedi_set_spriv(struct comedi_subdevice *s, void *data);
+
+void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size);
int comedi_check_chanlist(struct comedi_subdevice *s,
int n,
#include "../comedidev.h"
#include <linux/ioport.h>
-#include <linux/slab.h>
#include "comedi_fc.h"
#include "8255.h"
{
struct subdev_8255_private *spriv;
- spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
+ spriv = comedi_alloc_spriv(s, sizeof(*spriv));
if (!spriv)
return -ENOMEM;
- comedi_set_spriv(s, spriv);
spriv->iobase = iobase;
spriv->io = io ? io : subdev_8255_io;
{
struct addi_watchdog_private *spriv;
- spriv = kzalloc(sizeof(*spriv), GFP_KERNEL);
+ spriv = comedi_alloc_spriv(s, sizeof(*spriv));
if (!spriv)
return -ENOMEM;
- comedi_set_spriv(s, spriv);
spriv->iobase = iobase;
const struct dio200_layout *layout = dio200_dev_layout(dev);
struct dio200_subdev_intr *subpriv;
- subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
+ subpriv = comedi_alloc_spriv(s, sizeof(*subpriv));
if (!subpriv)
return -ENOMEM;
- comedi_set_spriv(s, subpriv);
subpriv->ofs = offset;
subpriv->valid_isns = valid_isns;
struct dio200_subdev_8254 *subpriv;
unsigned int chan;
- subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
+ subpriv = comedi_alloc_spriv(s, sizeof(*subpriv));
if (!subpriv)
return -ENOMEM;
- comedi_set_spriv(s, subpriv);
s->type = COMEDI_SUBD_COUNTER;
s->subdev_flags = SDF_WRITABLE | SDF_READABLE;
{
struct dio200_subdev_8255 *subpriv;
- subpriv = kzalloc(sizeof(*subpriv), GFP_KERNEL);
+ subpriv = comedi_alloc_spriv(s, sizeof(*subpriv));
if (!subpriv)
return -ENOMEM;
- comedi_set_spriv(s, subpriv);
subpriv->ofs = offset;
return subdev->private;
}
-static int ni_65xx_alloc_subdevice_private(struct comedi_subdevice *s)
-{
- 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,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct pci_dev *pcidev = comedi_to_pci_dev(dev);
const struct ni_65xx_board *board = NULL;
struct ni_65xx_private *devpriv;
+ struct ni_65xx_subdevice_private *spriv;
struct comedi_subdevice *s;
unsigned i;
int ret;
s->maxdata = 1;
s->insn_config = ni_65xx_dio_insn_config;
s->insn_bits = ni_65xx_dio_insn_bits;
- ret = ni_65xx_alloc_subdevice_private(s);
- if (ret)
- return ret;
- sprivate(s)->base_port = 0;
+ spriv = comedi_alloc_spriv(s, sizeof(*spriv));
+ if (!spriv)
+ return -ENOMEM;
+ spriv->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;
- ret = ni_65xx_alloc_subdevice_private(s);
- if (ret)
- return ret;
- sprivate(s)->base_port = board->num_di_ports;
+ spriv = comedi_alloc_spriv(s, sizeof(*spriv));
+ if (!spriv)
+ return -ENOMEM;
+ spriv->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;
- ret = ni_65xx_alloc_subdevice_private(s);
- if (ret)
- return ret;
- sprivate(s)->base_port = 0;
+ spriv = comedi_alloc_spriv(s, sizeof(*spriv));
+ if (!spriv)
+ return -ENOMEM;
+ spriv->base_port = 0;
for (i = 0; i < board->num_dio_ports; ++i) {
/* configure all ports for input */
writeb(0x1,