diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2015-12-24 00:06:05 -0500 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-01-04 10:26:58 -0500 |
commit | 16e5c1fc36040e592128a164499bc25eb138a80f (patch) | |
tree | a080bd2eea306d5815c5a9eefb46180e2bedffb2 /fs/afs | |
parent | 7e935c7ca1e6c398f11edac5beabfc4348e3b3a4 (diff) |
convert a bunch of open-coded instances of memdup_user_nul()
A _lot_ of ->write() instances were open-coding it; some are
converted to memdup_user_nul(), a lot more remain...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/afs')
-rw-r--r-- | fs/afs/proc.c | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 24a905b076fd..2853b4095344 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c | |||
@@ -230,14 +230,9 @@ static ssize_t afs_proc_cells_write(struct file *file, const char __user *buf, | |||
230 | if (size <= 1 || size >= PAGE_SIZE) | 230 | if (size <= 1 || size >= PAGE_SIZE) |
231 | return -EINVAL; | 231 | return -EINVAL; |
232 | 232 | ||
233 | kbuf = kmalloc(size + 1, GFP_KERNEL); | 233 | kbuf = memdup_user_nul(buf, size); |
234 | if (!kbuf) | 234 | if (IS_ERR(kbuf)) |
235 | return -ENOMEM; | 235 | return PTR_ERR(kbuf); |
236 | |||
237 | ret = -EFAULT; | ||
238 | if (copy_from_user(kbuf, buf, size) != 0) | ||
239 | goto done; | ||
240 | kbuf[size] = 0; | ||
241 | 236 | ||
242 | /* trim to first NL */ | 237 | /* trim to first NL */ |
243 | name = memchr(kbuf, '\n', size); | 238 | name = memchr(kbuf, '\n', size); |
@@ -315,15 +310,9 @@ static ssize_t afs_proc_rootcell_write(struct file *file, | |||
315 | if (size <= 1 || size >= PAGE_SIZE) | 310 | if (size <= 1 || size >= PAGE_SIZE) |
316 | return -EINVAL; | 311 | return -EINVAL; |
317 | 312 | ||
318 | ret = -ENOMEM; | 313 | kbuf = memdup_user_nul(buf, size); |
319 | kbuf = kmalloc(size + 1, GFP_KERNEL); | 314 | if (IS_ERR(kbuf)) |
320 | if (!kbuf) | 315 | return PTR_ERR(kbuf); |
321 | goto nomem; | ||
322 | |||
323 | ret = -EFAULT; | ||
324 | if (copy_from_user(kbuf, buf, size) != 0) | ||
325 | goto infault; | ||
326 | kbuf[size] = 0; | ||
327 | 316 | ||
328 | /* trim to first NL */ | 317 | /* trim to first NL */ |
329 | s = memchr(kbuf, '\n', size); | 318 | s = memchr(kbuf, '\n', size); |
@@ -337,9 +326,7 @@ static ssize_t afs_proc_rootcell_write(struct file *file, | |||
337 | if (ret >= 0) | 326 | if (ret >= 0) |
338 | ret = size; /* consume everything, always */ | 327 | ret = size; /* consume everything, always */ |
339 | 328 | ||
340 | infault: | ||
341 | kfree(kbuf); | 329 | kfree(kbuf); |
342 | nomem: | ||
343 | _leave(" = %d", ret); | 330 | _leave(" = %d", ret); |
344 | return ret; | 331 | return ret; |
345 | } | 332 | } |