process_vm_access: don't bother with returning the amounts of bytes copied
we can calculate that in the caller just fine, TYVM Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
e21345f9c3
commit
9acc1a0f9a
|
@ -43,13 +43,10 @@ static int process_vm_rw_pages(struct page **pages,
|
||||||
unsigned offset,
|
unsigned offset,
|
||||||
size_t len,
|
size_t len,
|
||||||
struct iov_iter *iter,
|
struct iov_iter *iter,
|
||||||
int vm_write,
|
int vm_write)
|
||||||
ssize_t *bytes_copied)
|
|
||||||
{
|
{
|
||||||
*bytes_copied = 0;
|
|
||||||
|
|
||||||
/* Do the copy for each page */
|
/* Do the copy for each page */
|
||||||
while (iov_iter_count(iter) && len) {
|
while (len && iov_iter_count(iter)) {
|
||||||
struct page *page = *pages++;
|
struct page *page = *pages++;
|
||||||
size_t copy = PAGE_SIZE - offset;
|
size_t copy = PAGE_SIZE - offset;
|
||||||
size_t copied;
|
size_t copied;
|
||||||
|
@ -67,7 +64,6 @@ static int process_vm_rw_pages(struct page **pages,
|
||||||
} else {
|
} else {
|
||||||
copied = copy_page_to_iter(page, offset, copy, iter);
|
copied = copy_page_to_iter(page, offset, copy, iter);
|
||||||
}
|
}
|
||||||
*bytes_copied += copied;
|
|
||||||
len -= copied;
|
len -= copied;
|
||||||
if (copied < copy && iov_iter_count(iter))
|
if (copied < copy && iov_iter_count(iter))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
@ -101,20 +97,16 @@ static int process_vm_rw_single_vec(unsigned long addr,
|
||||||
struct page **process_pages,
|
struct page **process_pages,
|
||||||
struct mm_struct *mm,
|
struct mm_struct *mm,
|
||||||
struct task_struct *task,
|
struct task_struct *task,
|
||||||
int vm_write,
|
int vm_write)
|
||||||
ssize_t *bytes_copied)
|
|
||||||
{
|
{
|
||||||
unsigned long pa = addr & PAGE_MASK;
|
unsigned long pa = addr & PAGE_MASK;
|
||||||
unsigned long start_offset = addr - pa;
|
unsigned long start_offset = addr - pa;
|
||||||
unsigned long nr_pages;
|
unsigned long nr_pages;
|
||||||
ssize_t bytes_copied_loop;
|
|
||||||
ssize_t rc = 0;
|
ssize_t rc = 0;
|
||||||
unsigned long nr_pages_copied = 0;
|
unsigned long nr_pages_copied = 0;
|
||||||
unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
|
unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
|
||||||
/ sizeof(struct pages *);
|
/ sizeof(struct pages *);
|
||||||
|
|
||||||
*bytes_copied = 0;
|
|
||||||
|
|
||||||
/* Work out address and page range required */
|
/* Work out address and page range required */
|
||||||
if (len == 0)
|
if (len == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -143,11 +135,9 @@ static int process_vm_rw_single_vec(unsigned long addr,
|
||||||
|
|
||||||
rc = process_vm_rw_pages(process_pages,
|
rc = process_vm_rw_pages(process_pages,
|
||||||
start_offset, n, iter,
|
start_offset, n, iter,
|
||||||
vm_write,
|
vm_write);
|
||||||
&bytes_copied_loop);
|
|
||||||
len -= n;
|
len -= n;
|
||||||
start_offset = 0;
|
start_offset = 0;
|
||||||
*bytes_copied += bytes_copied_loop;
|
|
||||||
nr_pages_copied += pages_pinned;
|
nr_pages_copied += pages_pinned;
|
||||||
pa += pages_pinned * PAGE_SIZE;
|
pa += pages_pinned * PAGE_SIZE;
|
||||||
while (pages_pinned)
|
while (pages_pinned)
|
||||||
|
@ -187,11 +177,10 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
|
||||||
struct mm_struct *mm;
|
struct mm_struct *mm;
|
||||||
unsigned long i;
|
unsigned long i;
|
||||||
ssize_t rc = 0;
|
ssize_t rc = 0;
|
||||||
ssize_t bytes_copied_loop;
|
|
||||||
ssize_t bytes_copied = 0;
|
|
||||||
unsigned long nr_pages = 0;
|
unsigned long nr_pages = 0;
|
||||||
unsigned long nr_pages_iov;
|
unsigned long nr_pages_iov;
|
||||||
ssize_t iov_len;
|
ssize_t iov_len;
|
||||||
|
size_t total_len = iov_iter_count(iter);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Work out how many pages of struct pages we're going to need
|
* Work out how many pages of struct pages we're going to need
|
||||||
|
@ -245,24 +234,20 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
|
||||||
goto put_task_struct;
|
goto put_task_struct;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < riovcnt && iov_iter_count(iter); i++) {
|
for (i = 0; i < riovcnt && iov_iter_count(iter) && !rc; i++)
|
||||||
rc = process_vm_rw_single_vec(
|
rc = process_vm_rw_single_vec(
|
||||||
(unsigned long)rvec[i].iov_base, rvec[i].iov_len,
|
(unsigned long)rvec[i].iov_base, rvec[i].iov_len,
|
||||||
iter, process_pages, mm, task, vm_write,
|
iter, process_pages, mm, task, vm_write);
|
||||||
&bytes_copied_loop);
|
|
||||||
bytes_copied += bytes_copied_loop;
|
/* copied = space before - space after */
|
||||||
if (rc != 0) {
|
total_len -= iov_iter_count(iter);
|
||||||
/* If we have managed to copy any data at all then
|
|
||||||
we return the number of bytes copied. Otherwise
|
/* If we have managed to copy any data at all then
|
||||||
we return the error code */
|
we return the number of bytes copied. Otherwise
|
||||||
if (bytes_copied)
|
we return the error code */
|
||||||
rc = bytes_copied;
|
if (total_len)
|
||||||
goto put_mm;
|
rc = total_len;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rc = bytes_copied;
|
|
||||||
put_mm:
|
|
||||||
mmput(mm);
|
mmput(mm);
|
||||||
|
|
||||||
put_task_struct:
|
put_task_struct:
|
||||||
|
|
Loading…
Reference in New Issue