untangling process_vm_..., part 3
[pandora-kernel.git] / mm / process_vm_access.c
index fd26d04..40dfb39 100644 (file)
@@ -45,7 +45,7 @@ static int process_vm_rw_pages(struct task_struct *task,
                               unsigned long pa,
                               unsigned long start_offset,
                               unsigned long len,
-                              const struct iovec *lvec,
+                              const struct iovec **iovp,
                               unsigned long lvec_cnt,
                               unsigned long *lvec_current,
                               size_t *lvec_offset,
@@ -60,6 +60,7 @@ static int process_vm_rw_pages(struct task_struct *task,
        int ret;
        ssize_t bytes_to_copy;
        ssize_t rc = 0;
+       const struct iovec *iov = *iovp;
 
        *bytes_copied = 0;
 
@@ -81,8 +82,10 @@ static int process_vm_rw_pages(struct task_struct *task,
             pgs_copied++) {
                /* Make sure we have a non zero length iovec */
                while (*lvec_current < lvec_cnt
-                      && lvec[*lvec_current].iov_len == 0)
+                      && iov->iov_len == 0) {
+                       iov++;
                        (*lvec_current)++;
+               }
                if (*lvec_current == lvec_cnt)
                        break;
 
@@ -94,18 +97,18 @@ static int process_vm_rw_pages(struct task_struct *task,
                bytes_to_copy = min_t(ssize_t, PAGE_SIZE - start_offset,
                                      len - *bytes_copied);
                bytes_to_copy = min_t(ssize_t, bytes_to_copy,
-                                     lvec[*lvec_current].iov_len
+                                     iov->iov_len
                                      - *lvec_offset);
 
                target_kaddr = kmap(process_pages[pgs_copied]) + start_offset;
 
                if (vm_write)
                        ret = copy_from_user(target_kaddr,
-                                            lvec[*lvec_current].iov_base
+                                            iov->iov_base
                                             + *lvec_offset,
                                             bytes_to_copy);
                else
-                       ret = copy_to_user(lvec[*lvec_current].iov_base
+                       ret = copy_to_user(iov->iov_base
                                           + *lvec_offset,
                                           target_kaddr, bytes_to_copy);
                kunmap(process_pages[pgs_copied]);
@@ -117,12 +120,13 @@ static int process_vm_rw_pages(struct task_struct *task,
                }
                *bytes_copied += bytes_to_copy;
                *lvec_offset += bytes_to_copy;
-               if (*lvec_offset == lvec[*lvec_current].iov_len) {
+               if (*lvec_offset == iov->iov_len) {
                        /*
                         * Need to copy remaining part of page into the
                         * next iovec if there are any bytes left in page
                         */
                        (*lvec_current)++;
+                       iov++;
                        *lvec_offset = 0;
                        start_offset = (start_offset + bytes_to_copy)
                                % PAGE_SIZE;
@@ -145,6 +149,7 @@ end:
                        put_page(process_pages[j]);
        }
 
+       *iovp = iov;
        return rc;
 }
 
@@ -169,7 +174,7 @@ end:
  */
 static int process_vm_rw_single_vec(unsigned long addr,
                                    unsigned long len,
-                                   const struct iovec *lvec,
+                                   const struct iovec **iovp,
                                    unsigned long lvec_cnt,
                                    unsigned long *lvec_current,
                                    size_t *lvec_offset,
@@ -202,7 +207,7 @@ static int process_vm_rw_single_vec(unsigned long addr,
 
                rc = process_vm_rw_pages(task, mm, process_pages, pa,
                                         start_offset, len,
-                                        lvec, lvec_cnt,
+                                        iovp, lvec_cnt,
                                         lvec_current, lvec_offset,
                                         vm_write, nr_pages_to_copy,
                                         &bytes_copied_loop);
@@ -313,7 +318,7 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
        for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
                rc = process_vm_rw_single_vec(
                        (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
-                       lvec, liovcnt, &iov_l_curr_idx, &iov_l_curr_offset,
+                       &lvec, liovcnt, &iov_l_curr_idx, &iov_l_curr_offset,
                        process_pages, mm, task, vm_write, &bytes_copied_loop);
                bytes_copied += bytes_copied_loop;
                if (rc != 0) {