aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/bin.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index 006fc64227dd..66f6e58a7e4b 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -61,6 +61,7 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
61 int size = dentry->d_inode->i_size; 61 int size = dentry->d_inode->i_size;
62 loff_t offs = *off; 62 loff_t offs = *off;
63 int count = min_t(size_t, bytes, PAGE_SIZE); 63 int count = min_t(size_t, bytes, PAGE_SIZE);
64 char *temp;
64 65
65 if (size) { 66 if (size) {
66 if (offs > size) 67 if (offs > size)
@@ -69,23 +70,33 @@ read(struct file *file, char __user *userbuf, size_t bytes, loff_t *off)
69 count = size - offs; 70 count = size - offs;
70 } 71 }
71 72
73 temp = kmalloc(count, GFP_KERNEL);
74 if (!temp)
75 return -ENOMEM;
76
72 mutex_lock(&bb->mutex); 77 mutex_lock(&bb->mutex);
73 78
74 count = fill_read(dentry, bb->buffer, offs, count); 79 count = fill_read(dentry, bb->buffer, offs, count);
75 if (count < 0) 80 if (count < 0) {
76 goto out_unlock; 81 mutex_unlock(&bb->mutex);
82 goto out_free;
83 }
77 84
78 if (copy_to_user(userbuf, bb->buffer, count)) { 85 memcpy(temp, bb->buffer, count);
86
87 mutex_unlock(&bb->mutex);
88
89 if (copy_to_user(userbuf, temp, count)) {
79 count = -EFAULT; 90 count = -EFAULT;
80 goto out_unlock; 91 goto out_free;
81 } 92 }
82 93
83 pr_debug("offs = %lld, *off = %lld, count = %d\n", offs, *off, count); 94 pr_debug("offs = %lld, *off = %lld, count = %d\n", offs, *off, count);
84 95
85 *off = offs + count; 96 *off = offs + count;
86 97
87 out_unlock: 98 out_free:
88 mutex_unlock(&bb->mutex); 99 kfree(temp);
89 return count; 100 return count;
90} 101}
91 102
@@ -118,6 +129,7 @@ static ssize_t write(struct file *file, const char __user *userbuf,
118 int size = dentry->d_inode->i_size; 129 int size = dentry->d_inode->i_size;
119 loff_t offs = *off; 130 loff_t offs = *off;
120 int count = min_t(size_t, bytes, PAGE_SIZE); 131 int count = min_t(size_t, bytes, PAGE_SIZE);
132 char *temp;
121 133
122 if (size) { 134 if (size) {
123 if (offs > size) 135 if (offs > size)
@@ -126,19 +138,27 @@ static ssize_t write(struct file *file, const char __user *userbuf,
126 count = size - offs; 138 count = size - offs;
127 } 139 }
128 140
129 mutex_lock(&bb->mutex); 141 temp = kmalloc(count, GFP_KERNEL);
142 if (!temp)
143 return -ENOMEM;
130 144
131 if (copy_from_user(bb->buffer, userbuf, count)) { 145 if (copy_from_user(temp, userbuf, count)) {
132 count = -EFAULT; 146 count = -EFAULT;
133 goto out_unlock; 147 goto out_free;
134 } 148 }
135 149
150 mutex_lock(&bb->mutex);
151
152 memcpy(bb->buffer, temp, count);
153
136 count = flush_write(dentry, bb->buffer, offs, count); 154 count = flush_write(dentry, bb->buffer, offs, count);
155 mutex_unlock(&bb->mutex);
156
137 if (count > 0) 157 if (count > 0)
138 *off = offs + count; 158 *off = offs + count;
139 159
140 out_unlock: 160out_free:
141 mutex_unlock(&bb->mutex); 161 kfree(temp);
142 return count; 162 return count;
143} 163}
144 164