From 8fc369ae38ff281d38e9ea11805a5cae862989bc Mon Sep 17 00:00:00 2001 From: Ian Abbott Date: Tue, 21 Apr 2015 13:18:10 +0100 Subject: staging: comedi: wrap COMEDI_SRF_FREE_SPRIV usage The `COMEDI_SRF_FREE_SPRIV` flag in the `runflags` member of `struct comedi_subdevice` indicates that the memory pointed to by the `private` member can be automatically freed by the comedi core on subdevice clean-up (when the low-level comedi device is being "detached"). the flag doesn't really belong in `runflags`, but it was somewhere convenient to keep it without having to add a new member to the structure. Rather than access the `COMEDI_SRF_FREE_SPRIV` flag directly, use some new wrapper functions: * comedi_can_auto_free_spriv(s) - checks whether the subdevice's `s->private` points to memory that can be freed automatically. * comedi_set_spriv_auto_free(s) - marks the subdevice as having a `s->private` that points to memory that can be freed automatically. Export `comedi_set_spriv_auto_free()` for use by the low-level comedi driver modules, in particular the "amplc_dio200_common" module. Signed-off-by: Ian Abbott Reviewed-by: H Hartley Sweeten Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_fops.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 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 e78ddbe5a954..fc339c5c50fc 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -679,8 +679,28 @@ static bool comedi_is_subdevice_idle(struct comedi_subdevice *s) return !(runflags & COMEDI_SRF_BUSY_MASK); } +bool comedi_can_auto_free_spriv(struct comedi_subdevice *s) +{ + unsigned runflags = __comedi_get_subdevice_runflags(s); + + return runflags & COMEDI_SRF_FREE_SPRIV; +} + +/** + * comedi_set_spriv_auto_free - mark subdevice private data as freeable + * @s: comedi_subdevice struct + * + * Mark the subdevice as having a pointer to private data that can be + * automatically freed by the comedi core during the detach. + */ +void comedi_set_spriv_auto_free(struct comedi_subdevice *s) +{ + __comedi_set_subdevice_runflags(s, COMEDI_SRF_FREE_SPRIV); +} +EXPORT_SYMBOL_GPL(comedi_set_spriv_auto_free); + /** - * comedi_alloc_spriv() - Allocate memory for the subdevice private data. + * comedi_alloc_spriv - Allocate memory for the subdevice private data. * @s: comedi_subdevice struct * @size: size of the memory to allocate * @@ -691,7 +711,7 @@ void *comedi_alloc_spriv(struct comedi_subdevice *s, size_t size) { s->private = kzalloc(size, GFP_KERNEL); if (s->private) - s->runflags |= COMEDI_SRF_FREE_SPRIV; + comedi_set_spriv_auto_free(s); return s->private; } EXPORT_SYMBOL_GPL(comedi_alloc_spriv); -- cgit v1.2.3-55-g7522