diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2018-06-07 20:09:55 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-06-07 20:34:38 -0400 |
commit | 6a6b9c4c11f8da5156b72e868baf0c6c392a5014 (patch) | |
tree | a82dc9e7a71e6657c9fba7cf6298b0af6a6c9178 /fs/proc/base.c | |
parent | b42262af5ecfc64f92423dc1e5ef634d9195f4b0 (diff) |
proc: somewhat simpler code for /proc/*/cmdline
"final" variable is OK but we can get away with less lines.
Link: http://lkml.kernel.org/r/20180221192751.GC28548@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc/base.c')
-rw-r--r-- | fs/proc/base.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c index 159abd09b411..4b27e26fc6de 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c | |||
@@ -318,8 +318,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, | |||
318 | p = cmdline[i].p + pos1; | 318 | p = cmdline[i].p + pos1; |
319 | len = cmdline[i].len - pos1; | 319 | len = cmdline[i].len - pos1; |
320 | while (count > 0 && len > 0) { | 320 | while (count > 0 && len > 0) { |
321 | unsigned int nr_read, l; | 321 | unsigned int nr_read, nr_write; |
322 | bool final; | ||
323 | 322 | ||
324 | nr_read = min3(count, len, PAGE_SIZE); | 323 | nr_read = min3(count, len, PAGE_SIZE); |
325 | nr_read = access_remote_vm(mm, p, page, nr_read, FOLL_ANON); | 324 | nr_read = access_remote_vm(mm, p, page, nr_read, FOLL_ANON); |
@@ -330,25 +329,20 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, | |||
330 | * Command line can be shorter than whole ARGV | 329 | * Command line can be shorter than whole ARGV |
331 | * even if last "marker" byte says it is not. | 330 | * even if last "marker" byte says it is not. |
332 | */ | 331 | */ |
333 | final = false; | 332 | nr_write = strnlen(page, nr_read); |
334 | l = strnlen(page, nr_read); | ||
335 | if (l < nr_read) { | ||
336 | nr_read = l; | ||
337 | final = true; | ||
338 | } | ||
339 | 333 | ||
340 | if (copy_to_user(buf, page, nr_read)) { | 334 | if (copy_to_user(buf, page, nr_write)) { |
341 | rv = -EFAULT; | 335 | rv = -EFAULT; |
342 | goto out_free_page; | 336 | goto out_free_page; |
343 | } | 337 | } |
344 | 338 | ||
345 | p += nr_read; | 339 | p += nr_write; |
346 | len -= nr_read; | 340 | len -= nr_write; |
347 | buf += nr_read; | 341 | buf += nr_write; |
348 | count -= nr_read; | 342 | count -= nr_write; |
349 | rv += nr_read; | 343 | rv += nr_write; |
350 | 344 | ||
351 | if (final) | 345 | if (nr_write < nr_read) |
352 | goto out_free_page; | 346 | goto out_free_page; |
353 | } | 347 | } |
354 | 348 | ||