Commit 3902a370 authored by Ian Abbott's avatar Ian Abbott Committed by Greg Kroah-Hartman

staging: comedi: refactor comedi_device_attach() a bit

Split the post-config part of comedi_device_attach() into new function
comedi_device_postconfig() and rearrange the rest of the function a bit.

The new comedi_device_postconfig() function will be called by some new
bus-type-specific auto-attach functions.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d8b6ca08
...@@ -106,6 +106,26 @@ void comedi_device_detach(struct comedi_device *dev) ...@@ -106,6 +106,26 @@ void comedi_device_detach(struct comedi_device *dev)
__comedi_device_detach(dev); __comedi_device_detach(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 = postconfig(dev);
module_put(dev->driver->module);
if (ret < 0) {
__comedi_device_detach(dev);
return ret;
}
if (!dev->board_name) {
printk(KERN_WARNING "BUG: dev->board_name=<%p>\n",
dev->board_name);
dev->board_name = "BUG";
}
smp_wmb();
dev->attached = 1;
return 0;
}
int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
{ {
struct comedi_driver *driv; struct comedi_driver *driv;
...@@ -121,28 +141,13 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -121,28 +141,13 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
} }
if (driv->num_names) { if (driv->num_names) {
dev->board_ptr = comedi_recognize(driv, it->board_name); dev->board_ptr = comedi_recognize(driv, it->board_name);
if (dev->board_ptr == NULL) { if (dev->board_ptr)
module_put(driv->module); break;
continue; } else if (strcmp(driv->driver_name, it->board_name))
} break;
} else {
if (strcmp(driv->driver_name, it->board_name)) {
module_put(driv->module); module_put(driv->module);
continue;
}
} }
/* initialize dev->driver here so if (driv == NULL) {
* comedi_error() can be called from attach */
dev->driver = driv;
ret = driv->attach(dev, it);
if (ret < 0) {
module_put(dev->driver->module);
__comedi_device_detach(dev);
return ret;
}
goto attached;
}
/* recognize has failed if we get here */ /* recognize has failed if we get here */
/* report valid board names before returning error */ /* report valid board names before returning error */
for (driv = comedi_drivers; driv; driv = driv->next) { for (driv = comedi_drivers; driv; driv = driv->next) {
...@@ -155,25 +160,17 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -155,25 +160,17 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
module_put(driv->module); module_put(driv->module);
} }
return -EIO; return -EIO;
}
attached: /* initialize dev->driver here so
/* do a little post-config cleanup */ * comedi_error() can be called from attach */
ret = postconfig(dev); dev->driver = driv;
module_put(dev->driver->module); ret = driv->attach(dev, it);
if (ret < 0) { if (ret < 0) {
module_put(dev->driver->module);
__comedi_device_detach(dev); __comedi_device_detach(dev);
return ret; return ret;
} }
return comedi_device_postconfig(dev);
if (!dev->board_name) {
printk(KERN_WARNING "BUG: dev->board_name=<%p>\n",
dev->board_name);
dev->board_name = "BUG";
}
smp_wmb();
dev->attached = 1;
return 0;
} }
int comedi_driver_register(struct comedi_driver *driver) int comedi_driver_register(struct comedi_driver *driver)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment