diff options
-rw-r--r-- | drivers/mtd/mtdchar.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 6f044584bdc6..6b83aee8abb8 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -170,16 +170,22 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t | |||
170 | 170 | ||
171 | /* FIXME: Use kiovec in 2.5 to lock down the user's buffers | 171 | /* FIXME: Use kiovec in 2.5 to lock down the user's buffers |
172 | and pass them directly to the MTD functions */ | 172 | and pass them directly to the MTD functions */ |
173 | |||
174 | if (count > MAX_KMALLOC_SIZE) | ||
175 | kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL); | ||
176 | else | ||
177 | kbuf=kmalloc(count, GFP_KERNEL); | ||
178 | |||
179 | if (!kbuf) | ||
180 | return -ENOMEM; | ||
181 | |||
173 | while (count) { | 182 | while (count) { |
183 | |||
174 | if (count > MAX_KMALLOC_SIZE) | 184 | if (count > MAX_KMALLOC_SIZE) |
175 | len = MAX_KMALLOC_SIZE; | 185 | len = MAX_KMALLOC_SIZE; |
176 | else | 186 | else |
177 | len = count; | 187 | len = count; |
178 | 188 | ||
179 | kbuf=kmalloc(len,GFP_KERNEL); | ||
180 | if (!kbuf) | ||
181 | return -ENOMEM; | ||
182 | |||
183 | switch (MTD_MODE(file)) { | 189 | switch (MTD_MODE(file)) { |
184 | case MTD_MODE_OTP_FACT: | 190 | case MTD_MODE_OTP_FACT: |
185 | ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf); | 191 | ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf); |
@@ -215,9 +221,9 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t | |||
215 | return ret; | 221 | return ret; |
216 | } | 222 | } |
217 | 223 | ||
218 | kfree(kbuf); | ||
219 | } | 224 | } |
220 | 225 | ||
226 | kfree(kbuf); | ||
221 | return total_retlen; | 227 | return total_retlen; |
222 | } /* mtd_read */ | 228 | } /* mtd_read */ |
223 | 229 | ||
@@ -241,18 +247,21 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count | |||
241 | if (!count) | 247 | if (!count) |
242 | return 0; | 248 | return 0; |
243 | 249 | ||
250 | if (count > MAX_KMALLOC_SIZE) | ||
251 | kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL); | ||
252 | else | ||
253 | kbuf=kmalloc(count, GFP_KERNEL); | ||
254 | |||
255 | if (!kbuf) | ||
256 | return -ENOMEM; | ||
257 | |||
244 | while (count) { | 258 | while (count) { |
259 | |||
245 | if (count > MAX_KMALLOC_SIZE) | 260 | if (count > MAX_KMALLOC_SIZE) |
246 | len = MAX_KMALLOC_SIZE; | 261 | len = MAX_KMALLOC_SIZE; |
247 | else | 262 | else |
248 | len = count; | 263 | len = count; |
249 | 264 | ||
250 | kbuf=kmalloc(len,GFP_KERNEL); | ||
251 | if (!kbuf) { | ||
252 | printk("kmalloc is null\n"); | ||
253 | return -ENOMEM; | ||
254 | } | ||
255 | |||
256 | if (copy_from_user(kbuf, buf, len)) { | 265 | if (copy_from_user(kbuf, buf, len)) { |
257 | kfree(kbuf); | 266 | kfree(kbuf); |
258 | return -EFAULT; | 267 | return -EFAULT; |
@@ -282,10 +291,9 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count | |||
282 | kfree(kbuf); | 291 | kfree(kbuf); |
283 | return ret; | 292 | return ret; |
284 | } | 293 | } |
285 | |||
286 | kfree(kbuf); | ||
287 | } | 294 | } |
288 | 295 | ||
296 | kfree(kbuf); | ||
289 | return total_retlen; | 297 | return total_retlen; |
290 | } /* mtd_write */ | 298 | } /* mtd_write */ |
291 | 299 | ||