if (arg == NULL) {
if (is_device_busy(dev))
return -EBUSY;
- comedi_device_detach(dev);
+ if(dev->attached)
+ {
+ struct module *driver_module = dev->driver->module;
+ comedi_device_detach(dev);
+ module_put(driver_module);
+ }
return 0;
}
}
ret = comedi_device_attach(dev, &it);
+ if(ret == 0)
+ {
+ if(!try_module_get(dev->driver->module)) {
+ comedi_device_detach(dev);
+ return -ENOSYS;
+ }
+ }
if (aux_data)
vfree(aux_data);
mutex_unlock(&dev->mutex);
return -ENODEV;
}
- ok:
+ok:
__module_get(THIS_MODULE);
if (dev->attached) {
{
if(dev == NULL) return;
mutex_lock(&dev->mutex);
- if (dev->attached)
- comedi_device_detach(dev);
+ comedi_device_detach(dev);
mutex_unlock(&dev->mutex);
mutex_destroy(&dev->mutex);
}
dev->driver = driv;
ret = driv->attach(dev, it);
if (ret < 0) {
+ module_put(dev->driver->module);
__comedi_device_detach(dev);
return ret;
}
attached:
/* do a little post-config cleanup */
ret = postconfig(dev);
+ module_put(dev->driver->module);
if (ret < 0) {
__comedi_device_detach(dev);
return ret;
}
smp_wmb();
dev->attached = 1;
- module_put(dev->driver->module);
return 0;
}