diff options
author | Ian Abbott <abbotti@mev.co.uk> | 2013-04-04 13:58:45 (GMT) |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-04-05 21:33:16 (GMT) |
commit | a649a6754d246d5b5447f74b86ed4b947e5f5446 (patch) | |
tree | 97ebe4002b891f9aaf1c6535f6153f7b0f644aa9 /drivers/staging/comedi/comedi_fops.c | |
parent | 4ca7da6e8234c864c8694237c26e4d574b9fd00a (diff) | |
download | linux-fsl-qoriq-a649a6754d246d5b5447f74b86ed4b947e5f5446.tar.xz |
staging: comedi: adjust module count on device cleanup
`comedi_device_cleanup()` is called just before freeing a comedi device.
It is possible for the device to still be open in which case the module
reference counts for the core comedi module and possibly the low-level
driver module will remain out of whack because `comedi_close()` will not
find the comedi device and so will not decrement the module counts.
This really needs to be handled better, but for now decrement the module
counts in `comedi_device_cleanup()` according to the number of
outstanding opens.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com>
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.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c index f2bfa0e..70b2034 100644 --- a/drivers/staging/comedi/comedi_fops.c +++ b/drivers/staging/comedi/comedi_fops.c @@ -2256,10 +2256,20 @@ static void comedi_device_init(struct comedi_device *dev) static void comedi_device_cleanup(struct comedi_device *dev) { + struct module *driver_module = NULL; + if (dev == NULL) return; mutex_lock(&dev->mutex); + if (dev->attached) + driver_module = dev->driver->module; comedi_device_detach(dev); + while (dev->use_count > 0) { + if (driver_module) + module_put(driver_module); + module_put(THIS_MODULE); + dev->use_count--; + } mutex_unlock(&dev->mutex); mutex_destroy(&dev->mutex); } |