Commit 91270162bf8a86bee756da7e931591d9953cb5a8
Committed by
Greg Kroah-Hartman
1 parent
13c589d5b0
Exists in
smarc-imx_3.14.28_1.0.0_ga
and in
1 other branch
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>
Showing 1 changed file with 8 additions and 13 deletions Side-by-side Diff
fs/sysfs/bin.c
... | ... | @@ -72,7 +72,7 @@ |
72 | 72 | int size = file_inode(file)->i_size; |
73 | 73 | loff_t offs = *off; |
74 | 74 | int count = min_t(size_t, bytes, PAGE_SIZE); |
75 | - char *temp; | |
75 | + char *buf; | |
76 | 76 | |
77 | 77 | if (!bytes) |
78 | 78 | return 0; |
79 | 79 | |
80 | 80 | |
81 | 81 | |
82 | 82 | |
... | ... | @@ -84,23 +84,18 @@ |
84 | 84 | count = size - offs; |
85 | 85 | } |
86 | 86 | |
87 | - temp = kmalloc(count, GFP_KERNEL); | |
88 | - if (!temp) | |
87 | + buf = kmalloc(count, GFP_KERNEL); | |
88 | + if (!buf) | |
89 | 89 | return -ENOMEM; |
90 | 90 | |
91 | 91 | mutex_lock(&bb->mutex); |
92 | + count = fill_read(file, buf, offs, count); | |
93 | + mutex_unlock(&bb->mutex); | |
92 | 94 | |
93 | - count = fill_read(file, bb->buffer, offs, count); | |
94 | - if (count < 0) { | |
95 | - mutex_unlock(&bb->mutex); | |
95 | + if (count < 0) | |
96 | 96 | goto out_free; |
97 | - } | |
98 | 97 | |
99 | - memcpy(temp, bb->buffer, count); | |
100 | - | |
101 | - mutex_unlock(&bb->mutex); | |
102 | - | |
103 | - if (copy_to_user(userbuf, temp, count)) { | |
98 | + if (copy_to_user(userbuf, buf, count)) { | |
104 | 99 | count = -EFAULT; |
105 | 100 | goto out_free; |
106 | 101 | } |
... | ... | @@ -110,7 +105,7 @@ |
110 | 105 | *off = offs + count; |
111 | 106 | |
112 | 107 | out_free: |
113 | - kfree(temp); | |
108 | + kfree(buf); | |
114 | 109 | return count; |
115 | 110 | } |
116 | 111 |