summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/comedi_fops.c
diff options
context:
space:
mode:
authorH Hartley Sweeten2013-06-20 00:24:36 +0200
committerGreg Kroah-Hartman2013-06-25 00:46:56 +0200
commit0480bcb9fb5e279df9d39f21bb0e87ab15b5092a (patch)
tree46fc47b3121ee4355f780bfcf570f4e7c02d5ad9 /drivers/staging/comedi/comedi_fops.c
parentstaging: comedi: addi-data: remove unused 'i_NbrTTLChannel' boardinfo (diff)
downloadkernel-qcow2-linux-0480bcb9fb5e279df9d39f21bb0e87ab15b5092a.tar.gz
kernel-qcow2-linux-0480bcb9fb5e279df9d39f21bb0e87ab15b5092a.tar.xz
kernel-qcow2-linux-0480bcb9fb5e279df9d39f21bb0e87ab15b5092a.zip
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/comedi_fops.c')
-rw-r--r--drivers/staging/comedi/comedi_fops.c14
1 files changed, 8 insertions, 6 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.