summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/staging/comedi/comedi_fops.c12
-rw-r--r--drivers/staging/comedi/drivers.c32
2 files changed, 17 insertions, 27 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 1c310e790b62..229be419b014 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -520,7 +520,6 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
struct comedi_devconfig __user *arg)
{
struct comedi_devconfig it;
- int ret;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
@@ -551,15 +550,8 @@ static int do_devconfig_ioctl(struct comedi_device *dev,
/* don't re-use dynamically allocated comedi devices */
return -EBUSY;
- ret = comedi_device_attach(dev, &it);
- if (ret == 0) {
- if (!try_module_get(dev->driver->module)) {
- comedi_device_detach(dev);
- ret = -ENOSYS;
- }
- }
-
- return ret;
+ /* This increments the driver module count on success. */
+ return comedi_device_attach(dev, &it);
}
/*
diff --git a/drivers/staging/comedi/drivers.c b/drivers/staging/comedi/drivers.c
index caadd3bd72ac..73727a73bd34 100644
--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -277,11 +277,11 @@ static int __comedi_device_postconfig(struct comedi_device *dev)
}
/* do a little post-config cleanup */
-/* called with module refcount incremented, decrements it */
static int comedi_device_postconfig(struct comedi_device *dev)
{
- int ret = __comedi_device_postconfig(dev);
- module_put(dev->driver->module);
+ int ret;
+
+ ret = __comedi_device_postconfig(dev);
if (ret < 0) {
__comedi_device_detach(dev);
return ret;
@@ -400,7 +400,11 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
__comedi_device_detach(dev);
return ret;
}
- return comedi_device_postconfig(dev);
+ ret = comedi_device_postconfig(dev);
+ if (ret < 0)
+ module_put(dev->driver->module);
+ /* On success, the driver module count has been incremented. */
+ return ret;
}
int comedi_auto_config(struct device *hardware_device,
@@ -431,19 +435,13 @@ int comedi_auto_config(struct device *hardware_device,
return PTR_ERR(comedi_dev);
/* Note: comedi_alloc_board_minor() locked comedi_dev->mutex. */
- if (!try_module_get(driver->module))
- ret = -EIO;
- else {
- comedi_set_hw_dev(comedi_dev, hardware_device);
- comedi_dev->driver = driver;
- ret = driver->auto_attach(comedi_dev, context);
- if (ret < 0) {
- module_put(driver->module);
- __comedi_device_detach(comedi_dev);
- } else {
- ret = comedi_device_postconfig(comedi_dev);
- }
- }
+ comedi_set_hw_dev(comedi_dev, hardware_device);
+ comedi_dev->driver = driver;
+ ret = driver->auto_attach(comedi_dev, context);
+ if (ret < 0)
+ __comedi_device_detach(comedi_dev);
+ else
+ ret = comedi_device_postconfig(comedi_dev);
mutex_unlock(&comedi_dev->mutex);
if (ret < 0)