Commit 91270162 authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman

sysfs: skip bin_buffer->buffer while reading

After b31ca3f5 ("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: default avatarTejun Heo <tj@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 13c589d5
...@@ -72,7 +72,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) ...@@ -72,7 +72,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
int size = file_inode(file)->i_size; int size = file_inode(file)->i_size;
loff_t offs = *off; loff_t offs = *off;
int count = min_t(size_t, bytes, PAGE_SIZE); int count = min_t(size_t, bytes, PAGE_SIZE);
char *temp; char *buf;
if (!bytes) if (!bytes)
return 0; return 0;
...@@ -84,23 +84,18 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) ...@@ -84,23 +84,18 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
count = size - offs; count = size - offs;
} }
temp = kmalloc(count, GFP_KERNEL); buf = kmalloc(count, GFP_KERNEL);
if (!temp) if (!buf)
return -ENOMEM; return -ENOMEM;
mutex_lock(&bb->mutex); 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)
if (count < 0) {
mutex_unlock(&bb->mutex);
goto out_free; goto out_free;
}
memcpy(temp, bb->buffer, count);
mutex_unlock(&bb->mutex); if (copy_to_user(userbuf, buf, count)) {
if (copy_to_user(userbuf, temp, count)) {
count = -EFAULT; count = -EFAULT;
goto out_free; goto out_free;
} }
...@@ -110,7 +105,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off) ...@@ -110,7 +105,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
*off = offs + count; *off = offs + count;
out_free: out_free:
kfree(temp); kfree(buf);
return count; return count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment