summaryrefslogtreecommitdiffstats
path: root/drivers/staging/comedi/comedi_fops.c
diff options
context:
space:
mode:
authorIan Abbott2013-11-08 16:03:24 +0100
committerGreg Kroah-Hartman2013-11-12 01:16:43 +0100
commit2f3fdcd7ce935f6f2899ceab57dc8fe5286db3e1 (patch)
treee76f74a1dbd8f00650298df96cc0b5679d7e5db8 /drivers/staging/comedi/comedi_fops.c
parentstaging: comedi: add a couple of #includes to comedidev.h (diff)
downloadkernel-qcow2-linux-2f3fdcd7ce935f6f2899ceab57dc8fe5286db3e1.tar.gz
kernel-qcow2-linux-2f3fdcd7ce935f6f2899ceab57dc8fe5286db3e1.tar.xz
kernel-qcow2-linux-2f3fdcd7ce935f6f2899ceab57dc8fe5286db3e1.zip
staging: comedi: add rw_semaphore to protect against device detachment
The 'read' and 'write' file operations on comedi devices do not use the main mutex in the `struct comedi_device` to avoid contention with ioctls that may take a while to complete. However, it is necessary to protect against the device being detached while the operation is in progress. Add member `struct rw_semaphore attach_lock` to `struct comedi_device` for this purpose and initialize it on creation. The actual locking and unlocking will be implemented by subsequent patches. Tasks that are attaching or detaching comedi devices will write-acquire the new semaphore whilst also holding the main mutex in the `struct comedi_device`. Tasks that wish to protect against the comedi device being detached need to acquire either the main mutex, or read-acquire the new semaphore, or both in that order. Signed-off-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/comedi/comedi_fops.c')
-rw-r--r--drivers/staging/comedi/comedi_fops.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/drivers/staging/comedi/comedi_fops.c b/drivers/staging/comedi/comedi_fops.c
index 0d8565428abb..a1705ed0b844 100644
--- a/drivers/staging/comedi/comedi_fops.c
+++ b/drivers/staging/comedi/comedi_fops.c
@@ -91,6 +91,7 @@ static void comedi_device_init(struct comedi_device *dev)
{
spin_lock_init(&dev->spinlock);
mutex_init(&dev->mutex);
+ init_rwsem(&dev->attach_lock);
dev->minor = -1;
}