summaryrefslogtreecommitdiffstats
path: root/drivers/ieee1394
diff options
context:
space:
mode:
authorStefan Richter <stefanr@s5r6.in-berlin.de>2008-08-16 00:15:16 +0200
committerStefan Richter <stefanr@s5r6.in-berlin.de>2008-10-15 22:21:08 +0200
commitf22e52b89e036fd12b9374212da8b5d4a447bd1e (patch)
tree84e8cb2fca80197dc1b2afee85d2c46fd8446af0 /drivers/ieee1394
parentieee1394: raw1394: narrow down the state_mutex protected region (diff)
downloadlinux-f22e52b89e036fd12b9374212da8b5d4a447bd1e.tar.xz
linux-f22e52b89e036fd12b9374212da8b5d4a447bd1e.zip
ieee1394: raw1394: make write() thread-safe
Application programs should use a libraw1394 handle only in a single thread. The raw1394 driver was apparently relying on this, because it did nothing to protect its fi->state variable from corruption due to concurrent accesses. We now serialize the fi->state accesses. This affects the write() path. We re-use the state_mutex which was introduced to protect fi->iso_state accesses in the ioctl() path. These paths and accesses are independent of each other, hence separate mutexes could be used. But I don't see much benefit in that. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers/ieee1394')
-rw-r--r--drivers/ieee1394/raw1394.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index d1594427601f..2cf4ae75beca 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -2268,6 +2268,8 @@ static ssize_t raw1394_write(struct file *file, const char __user * buffer,
return -EFAULT;
}
+ mutex_lock(&fi->state_mutex);
+
switch (fi->state) {
case opened:
retval = state_opened(fi, req);
@@ -2282,6 +2284,8 @@ static ssize_t raw1394_write(struct file *file, const char __user * buffer,
break;
}
+ mutex_unlock(&fi->state_mutex);
+
if (retval < 0) {
free_pending_request(req);
} else {