Acquire the `attach_lock` semaphore in the `struct comedi_device` while
modifying the `attached` flag. This is a "write" acquire. Note that
the main mutex in the `struct comedi_device` is also held at this time.
Tasks wishing to check the device is attached will need to either
acquire the main mutex, or "read" acquire the `attach_lock` semaphore,
or both in that order.
Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
void comedi_device_detach(struct comedi_device *dev)
{
+ down_write(&dev->attach_lock);
dev->attached = false;
if (dev->driver)
dev->driver->detach(dev);
cleanup_device(dev);
+ up_write(&dev->attach_lock);
}
static int poll_invalid(struct comedi_device *dev, struct comedi_subdevice *s)
ret = __comedi_device_postconfig(dev);
if (ret < 0)
return ret;
- smp_wmb();
+ down_write(&dev->attach_lock);
dev->attached = true;
+ up_write(&dev->attach_lock);
return 0;
}