From 0480bcb9fb5e279df9d39f21bb0e87ab15b5092a Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Wed, 19 Jun 2013 15:24:36 -0700 Subject: 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 Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_fops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'drivers/staging/comedi/comedi_fops.c') 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. -- cgit v1.2.3-55-g7522