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

staging: comedi: simplify comedi_auto_attach()

`comedi_auto_config()` just calls internal function
`comedi_auto_config_helper()`, passing it a wrapper function
`comedi_auto_config_wrapper()` to handle the specifics of checking and
calling the low-level comedi driver's `auto_attach()` handler.

Since there are no other callers of `comedi_auto_config_helper()` or
`comedi_auto_config_wrapper()`, combine everything into the single
exported function `comedi_auto_config()`.

Change the ordering of the check for existence of the low-level comedi
driver's `auto_attach()` handler and the allocation of the comedi minor
device number.  This means the log message warning of the absence of the
handler now has to be refer to the hardware device instead of the
not-yet-allocated comedi device.
Signed-off-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent af448aca
...@@ -833,12 +833,8 @@ void comedi_reset_async_buf(struct comedi_async *async) ...@@ -833,12 +833,8 @@ void comedi_reset_async_buf(struct comedi_async *async)
async->events = 0; async->events = 0;
} }
static int int comedi_auto_config(struct device *hardware_device,
comedi_auto_config_helper(struct device *hardware_device, struct comedi_driver *driver, unsigned long context)
struct comedi_driver *driver,
int (*attach_wrapper) (struct comedi_device *,
unsigned long),
unsigned long context)
{ {
int minor; int minor;
struct comedi_device_file_info *dev_file_info; struct comedi_device_file_info *dev_file_info;
...@@ -848,6 +844,13 @@ comedi_auto_config_helper(struct device *hardware_device, ...@@ -848,6 +844,13 @@ comedi_auto_config_helper(struct device *hardware_device,
if (!comedi_autoconfig) if (!comedi_autoconfig)
return 0; return 0;
if (!driver->auto_attach) {
dev_warn(hardware_device,
"BUG! comedi driver '%s' has no auto_attach handler\n",
driver->driver_name);
return -EINVAL;
}
minor = comedi_alloc_board_minor(hardware_device); minor = comedi_alloc_board_minor(hardware_device);
if (minor < 0) if (minor < 0)
return minor; return minor;
...@@ -862,9 +865,8 @@ comedi_auto_config_helper(struct device *hardware_device, ...@@ -862,9 +865,8 @@ comedi_auto_config_helper(struct device *hardware_device,
ret = -EIO; ret = -EIO;
else { else {
comedi_set_hw_dev(comedi_dev, hardware_device); comedi_set_hw_dev(comedi_dev, hardware_device);
/* set comedi_dev->driver here for attach wrapper */
comedi_dev->driver = driver; comedi_dev->driver = driver;
ret = (*attach_wrapper)(comedi_dev, context); ret = driver->auto_attach(comedi_dev, context);
if (ret < 0) { if (ret < 0) {
module_put(driver->module); module_put(driver->module);
__comedi_device_detach(comedi_dev); __comedi_device_detach(comedi_dev);
...@@ -878,25 +880,6 @@ comedi_auto_config_helper(struct device *hardware_device, ...@@ -878,25 +880,6 @@ comedi_auto_config_helper(struct device *hardware_device,
comedi_free_board_minor(minor); comedi_free_board_minor(minor);
return ret; return ret;
} }
static int comedi_auto_config_wrapper(struct comedi_device *dev,
unsigned long context)
{
if (!dev->driver->auto_attach) {
dev_warn(dev->class_dev,
"BUG! driver '%s' has no auto_attach handler\n",
dev->driver->driver_name);
return -EINVAL;
}
return dev->driver->auto_attach(dev, context);
}
int comedi_auto_config(struct device *hardware_device,
struct comedi_driver *driver, unsigned long context)
{
return comedi_auto_config_helper(hardware_device, driver,
comedi_auto_config_wrapper, context);
}
EXPORT_SYMBOL_GPL(comedi_auto_config); EXPORT_SYMBOL_GPL(comedi_auto_config);
void comedi_auto_unconfig(struct device *hardware_device) void comedi_auto_unconfig(struct device *hardware_device)
......
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