diff options
author | H Hartley Sweeten <hsweeten@visionengravers.com> | 2013-06-19 15:24:36 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-06-24 15:46:56 -0700 |
commit | 0480bcb9fb5e279df9d39f21bb0e87ab15b5092a (patch) | |
tree | 46fc47b3121ee4355f780bfcf570f4e7c02d5ad9 /drivers/staging/comedi | |
parent | 2eb226dcedd0257ae0d712f0c0c0c35de24465ea (diff) |
staging: comedi: have comedi_set_spriv() allocate the memory
As suggested by Ian Abbott, comedi_set_spriv() can only be used to
set the subdevice->private pointer to something that can be kfree()'d.
Rename the function to comedi_alloc_spriv() and have it kzalloc() the
memory as well as set the private pointer. This saves a function call
in the drivers and avoids the possibility of incorrectly calling
comedi_set_spriv() for some pointer that is not meant to be kfree()'d.
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')
-rw-r--r-- | drivers/staging/comedi/comedi_fops.c | 14 | ||||
-rw-r--r-- | drivers/staging/comedi/comedidev.h | 3 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/8255.c | 4 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/addi_watchdog.c | 3 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/amplc_dio200_common.c | 9 | ||||
-rw-r--r-- | drivers/staging/comedi/drivers/ni_65xx.c | 37 |
6 files changed, 28 insertions, 42 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index 423f882416d9..0794aacc928a 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -532,19 +532,21 @@ static bool comedi_is_subdevice_idle(struct comedi_subdevice *s) } /** - * 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. diff --git a/drivers/staging/comedi/comedidev.h b/drivers/staging/comedi/comedidev.h index e8dc7af8f5a1..b75915f30f48 100644 --- a/drivers/staging/comedi/comedidev.h +++ b/drivers/staging/comedi/comedidev.h @@ -270,7 +270,8 @@ enum subdevice_runflags { }; 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, diff --git a/drivers/staging/comedi/drivers/8255.c b/drivers/staging/comedi/drivers/8255.c index dca9b40cefdc..94e17500150f 100644 --- a/drivers/staging/comedi/drivers/8255.c +++ b/drivers/staging/comedi/drivers/8255.c @@ -76,7 +76,6 @@ I/O port base address can be found in the output of 'lspci -v'. #include "../comedidev.h" #include <linux/ioport.h> -#include <linux/slab.h> #include "comedi_fc.h" #include "8255.h" @@ -285,10 +284,9 @@ int subdev_8255_init(struct comedi_device *dev, struct comedi_subdevice *s, { 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; diff --git a/drivers/staging/comedi/drivers/addi_watchdog.c b/drivers/staging/comedi/drivers/addi_watchdog.c index decc97d0e415..7b21acc93929 100644 --- a/drivers/staging/comedi/drivers/addi_watchdog.c +++ b/drivers/staging/comedi/drivers/addi_watchdog.c @@ -126,10 +126,9 @@ int addi_watchdog_init(struct comedi_subdevice *s, unsigned long iobase) { 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; diff --git a/drivers/staging/comedi/drivers/amplc_dio200_common.c b/drivers/staging/comedi/drivers/amplc_dio200_common.c index 00c35a3541e8..649fc69724fb 100644 --- a/drivers/staging/comedi/drivers/amplc_dio200_common.c +++ b/drivers/staging/comedi/drivers/amplc_dio200_common.c @@ -556,10 +556,9 @@ dio200_subdev_intr_init(struct comedi_device *dev, struct comedi_subdevice *s, 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; @@ -883,10 +882,9 @@ dio200_subdev_8254_init(struct comedi_device *dev, struct comedi_subdevice *s, 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; @@ -1019,10 +1017,9 @@ static int dio200_subdev_8255_init(struct comedi_device *dev, { 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; diff --git a/drivers/staging/comedi/drivers/ni_65xx.c b/drivers/staging/comedi/drivers/ni_65xx.c index 5907fd262a38..42a78de47316 100644 --- a/drivers/staging/comedi/drivers/ni_65xx.c +++ b/drivers/staging/comedi/drivers/ni_65xx.c @@ -281,18 +281,6 @@ static inline struct ni_65xx_subdevice_private *sprivate(struct comedi_subdevice 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) @@ -587,6 +575,7 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, 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; @@ -635,10 +624,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, 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; } @@ -652,10 +641,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, 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; } @@ -670,10 +659,10 @@ static int ni_65xx_auto_attach(struct comedi_device *dev, 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, |