#include "comedi_internal.h"
struct comedi_driver *comedi_drivers;
+DEFINE_MUTEX(comedi_drivers_list_lock);
int comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev)
{
if (dev->attached)
return -EBUSY;
+ mutex_lock(&comedi_drivers_list_lock);
for (driv = comedi_drivers; driv; driv = driv->next) {
if (!try_module_get(driv->module))
continue;
comedi_report_boards(driv);
module_put(driv->module);
}
- return -EIO;
+ ret = -EIO;
+ goto out;
}
if (driv->attach == NULL) {
/* driver does not support manual configuration */
"driver '%s' does not support attach using comedi_config\n",
driv->driver_name);
module_put(driv->module);
- return -ENOSYS;
+ ret = -ENOSYS;
+ goto out;
}
/* initialize dev->driver here so
* comedi_error() can be called from attach */
module_put(dev->driver->module);
}
/* On success, the driver module count has been incremented. */
+out:
+ mutex_unlock(&comedi_drivers_list_lock);
return ret;
}
int comedi_driver_register(struct comedi_driver *driver)
{
+ mutex_lock(&comedi_drivers_list_lock);
driver->next = comedi_drivers;
comedi_drivers = driver;
+ mutex_unlock(&comedi_drivers_list_lock);
return 0;
}
struct comedi_driver *prev;
int i;
+ /* unlink the driver */
+ mutex_lock(&comedi_drivers_list_lock);
+ if (comedi_drivers == driver) {
+ comedi_drivers = driver->next;
+ } else {
+ for (prev = comedi_drivers; prev->next; prev = prev->next) {
+ if (prev->next == driver) {
+ prev->next = driver->next;
+ break;
+ }
+ }
+ }
+ mutex_unlock(&comedi_drivers_list_lock);
+
/* check for devices using this driver */
for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
struct comedi_device *dev = comedi_dev_from_minor(i);
}
mutex_unlock(&dev->mutex);
}
-
- if (comedi_drivers == driver) {
- comedi_drivers = driver->next;
- return;
- }
-
- for (prev = comedi_drivers; prev->next; prev = prev->next) {
- if (prev->next == driver) {
- prev->next = driver->next;
- return;
- }
- }
}
EXPORT_SYMBOL_GPL(comedi_driver_unregister);
if (!devices_q)
seq_puts(m, "no devices\n");
+ mutex_lock(&comedi_drivers_list_lock);
for (driv = comedi_drivers; driv; driv = driv->next) {
seq_printf(m, "%s:\n", driv->driver_name);
for (i = 0; i < driv->num_names; i++)
if (!driv->num_names)
seq_printf(m, " %s\n", driv->driver_name);
}
+ mutex_unlock(&comedi_drivers_list_lock);
return 0;
}