Commit 6a6b9c4c authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

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@avx2Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b42262af
...@@ -318,8 +318,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, ...@@ -318,8 +318,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
p = cmdline[i].p + pos1; p = cmdline[i].p + pos1;
len = cmdline[i].len - pos1; len = cmdline[i].len - pos1;
while (count > 0 && len > 0) { while (count > 0 && len > 0) {
unsigned int nr_read, l; unsigned int nr_read, nr_write;
bool final;
nr_read = min3(count, len, PAGE_SIZE); nr_read = min3(count, len, PAGE_SIZE);
nr_read = access_remote_vm(mm, p, page, nr_read, FOLL_ANON); 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,25 +329,20 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
* Command line can be shorter than whole ARGV * Command line can be shorter than whole ARGV
* even if last "marker" byte says it is not. * even if last "marker" byte says it is not.
*/ */
final = false; nr_write = strnlen(page, nr_read);
l = strnlen(page, nr_read);
if (l < nr_read) {
nr_read = l;
final = true;
}
if (copy_to_user(buf, page, nr_read)) { if (copy_to_user(buf, page, nr_write)) {
rv = -EFAULT; rv = -EFAULT;
goto out_free_page; goto out_free_page;
} }
p += nr_read; p += nr_write;
len -= nr_read; len -= nr_write;
buf += nr_read; buf += nr_write;
count -= nr_read; count -= nr_write;
rv += nr_read; rv += nr_write;
if (final) if (nr_write < nr_read)
goto out_free_page; goto out_free_page;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment