aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-10-01 17:42:03 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-05 17:27:40 -0700
commit91270162bf8a86bee756da7e931591d9953cb5a8 (patch)
tree086f17394395fdaadd0ddbc3761a3115c9c032c2 /fs/sysfs
parent13c589d5b0ac654d9da7e490a2dd548e6b86b4a5 (diff)
downloadlinux-91270162bf8a86bee756da7e931591d9953cb5a8.tar.gz
sysfs: skip bin_buffer->buffer while reading
After b31ca3f5dfc ("sysfs: fix deadlock"), bin read() first writes data to bb->buffer and bounces it to a transient kernel buffer which is then copied out to userland. The double bouncing doesn't add anything. Let's just use the transient buffer directly. While at it, rename @temp to @buf for clarity. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/bin.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index d49e6ca3345b9..d2142c0648eb9 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -72,7 +72,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
int size = file_inode(file)->i_size;
loff_t offs = *off;
int count = min_t(size_t, bytes, PAGE_SIZE);
- char *temp;
+ char *buf;
if (!bytes)
return 0;
@@ -84,23 +84,18 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
count = size - offs;
}
- temp = kmalloc(count, GFP_KERNEL);
- if (!temp)
+ buf = kmalloc(count, GFP_KERNEL);
+ if (!buf)
return -ENOMEM;
mutex_lock(&bb->mutex);
+ count = fill_read(file, buf, offs, count);
+ mutex_unlock(&bb->mutex);
- count = fill_read(file, bb->buffer, offs, count);
- if (count < 0) {
- mutex_unlock(&bb->mutex);
+ if (count < 0)
goto out_free;
- }
-
- memcpy(temp, bb->buffer, count);
- mutex_unlock(&bb->mutex);
-
- if (copy_to_user(userbuf, temp, count)) {
+ if (copy_to_user(userbuf, buf, count)) {
count = -EFAULT;
goto out_free;
}
@@ -110,7 +105,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
*off = offs + count;
out_free:
- kfree(temp);
+ kfree(buf);
return count;
}