From 588ba6dc5fb4bdca47a3da38c2718fbb82d3eee1 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Tue, 11 Jun 2013 11:32:29 -0700 Subject: staging: comedi: drivers: let core handle freeing s->private Introduce a new subdevice runflags, SRF_FREE_SPRIV, and a new helper function, comedi_set_spriv(), that the drivers can use to set the comedi_subdevice private data pointer. The helper function will also set SRF_FREE_SPRIV to allow the comedi core to automatically free the subdevice private data during the cleanup_device() stage of the detach. Currently s->private is only allocated by the 8255, addi_watchdog, amplc_dio200_common, and ni_65xx drivers. All users of those drivers can then have the comedi_spriv_free() calls removed and in many cases the (*detach) can then simply be the appropriate comedi core provided function. The ni_65xx driver uses a helper function, ni_65xx_alloc_subdevice_private(), to allocate the private data. Refactor the function to return an errno or call comedi_set_spriv() instead of returning a pointer to the private data and requiring the caller to handle it. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/comedi_fops.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (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 c561a0eda92a..423f882416d9 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -531,6 +531,21 @@ static bool comedi_is_subdevice_idle(struct comedi_subdevice *s) return (runflags & (SRF_ERROR | SRF_RUNNING)) ? false : true; } +/** + * comedi_set_spriv() - Set the subdevice private data pointer. + * @s: comedi_subdevice struct + * @data: pointer to the private data + * + * 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) +{ + s->private = data; + comedi_set_subdevice_runflags(s, ~0, SRF_FREE_SPRIV); +} +EXPORT_SYMBOL_GPL(comedi_set_spriv); + /* This function restores a subdevice to an idle state. */ -- cgit v1.2.3-55-g7522