mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-25 16:05:34 +07:00
staging: comedi: replace __comedi_device_detach()
`comedi_device_detach()` does nothing if the `struct comedi_device`'s `attached` member is false, otherwise it calls `__comedi_device_detach()` to do the real work. `__comedi_device_detach()` is called from various other functions in "drivers.c" (`comedi_device_postconfig()`, `comedi_device_attach()`, and `comedi_auto_config()`) to bypass the check for the `attached` member being false. If we make `__comedi_device_detach()` safe to call when the `attached` member is already false, we can remove the check in `comedi_device_detach()`, subsume `__comedi_device_detach()` within `comedi_device_detach()`, and replace all the calls to `__comedi_device_detach()` with calls to `comedi_device_detach()`. In fact, it is already safe to call `__comedi_device_detach()` when the `attached` member is false. We just need to remove the warning message it outputs when the `driver` member is NULL. Then the function becomes idempotent without outputting spurious warnings. (It is idempotent because `dev->driver->detach()` will only be called once at most and the call to `cleanup_device()` is idempotent itself.) Combine `comedi_device_detach()` with `__comedi_device_detach()`, removing the check for the `attached` member being false and removing the warning about the `driver` member being NULL, and replace all calls to `__comedi_device_detach()` with calls to the combined `comedi_device_detach()`. A beneficial side-effect of the above change is that a call to `comedi_device_detach()` will always result in a call to `cleanup_device()` and so always result in a call to `comedi_clear_hw_dev()`. We will make use of this beneficial side-effect in a later patch. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Reviewed-by: H Hartley Sweeten <hsweeten@visionengravers.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
dcd7b8bd63
commit
016599f589
@ -119,24 +119,14 @@ static void cleanup_device(struct comedi_device *dev)
|
||||
comedi_clear_hw_dev(dev);
|
||||
}
|
||||
|
||||
static void __comedi_device_detach(struct comedi_device *dev)
|
||||
void comedi_device_detach(struct comedi_device *dev)
|
||||
{
|
||||
dev->attached = false;
|
||||
if (dev->driver)
|
||||
dev->driver->detach(dev);
|
||||
else
|
||||
dev_warn(dev->class_dev,
|
||||
"BUG: dev->driver=NULL in comedi_device_detach()\n");
|
||||
cleanup_device(dev);
|
||||
}
|
||||
|
||||
void comedi_device_detach(struct comedi_device *dev)
|
||||
{
|
||||
if (!dev->attached)
|
||||
return;
|
||||
__comedi_device_detach(dev);
|
||||
}
|
||||
|
||||
static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
|
||||
{
|
||||
return -EINVAL;
|
||||
@ -283,7 +273,7 @@ static int comedi_device_postconfig(struct comedi_device *dev)
|
||||
|
||||
ret = __comedi_device_postconfig(dev);
|
||||
if (ret < 0) {
|
||||
__comedi_device_detach(dev);
|
||||
comedi_device_detach(dev);
|
||||
return ret;
|
||||
}
|
||||
if (!dev->board_name) {
|
||||
@ -396,7 +386,7 @@ int comedi_device_attach(struct comedi_device *dev, struct comedi_devconfig *it)
|
||||
dev->driver = driv;
|
||||
ret = driv->attach(dev, it);
|
||||
if (ret < 0) {
|
||||
__comedi_device_detach(dev);
|
||||
comedi_device_detach(dev);
|
||||
module_put(dev->driver->module);
|
||||
return ret;
|
||||
}
|
||||
@ -439,7 +429,7 @@ int comedi_auto_config(struct device *hardware_device,
|
||||
comedi_dev->driver = driver;
|
||||
ret = driver->auto_attach(comedi_dev, context);
|
||||
if (ret < 0)
|
||||
__comedi_device_detach(comedi_dev);
|
||||
comedi_device_detach(comedi_dev);
|
||||
else
|
||||
ret = comedi_device_postconfig(comedi_dev);
|
||||
mutex_unlock(&comedi_dev->mutex);
|
||||
|
Loading…
Reference in New Issue
Block a user