Commit 4bafbec7bf60ed56ccbb36a96091bdbd162f075d

Authored by Al Viro
1 parent 9acc1a0f9a

process_vm_access: tidy up a bit

saner variable names, update linuxdoc comments, etc.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Showing 1 changed file with 19 additions and 40 deletions Side-by-side Diff

mm/process_vm_access.c
... ... @@ -23,20 +23,11 @@
23 23  
24 24 /**
25 25 * process_vm_rw_pages - read/write pages from task specified
26   - * @task: task to read/write from
27   - * @mm: mm for task
28   - * @process_pages: struct pages area that can store at least
29   - * nr_pages_to_copy struct page pointers
30   - * @pa: address of page in task to start copying from/to
  26 + * @pages: array of pointers to pages we want to copy
31 27 * @start_offset: offset in page to start copying from/to
32 28 * @len: number of bytes to copy
33   - * @lvec: iovec array specifying where to copy to/from
34   - * @lvec_cnt: number of elements in iovec array
35   - * @lvec_current: index in iovec array we are up to
36   - * @lvec_offset: offset in bytes from current iovec iov_base we are up to
  29 + * @iter: where to copy to/from locally
37 30 * @vm_write: 0 means copy from, 1 means copy to
38   - * @nr_pages_to_copy: number of pages to copy
39   - * @bytes_copied: returns number of bytes successfully copied
40 31 * Returns 0 on success, error code otherwise
41 32 */
42 33 static int process_vm_rw_pages(struct page **pages,
43 34  
... ... @@ -79,16 +70,12 @@
79 70 * process_vm_rw_single_vec - read/write pages from task specified
80 71 * @addr: start memory address of target process
81 72 * @len: size of area to copy to/from
82   - * @lvec: iovec array specifying where to copy to/from locally
83   - * @lvec_cnt: number of elements in iovec array
84   - * @lvec_current: index in iovec array we are up to
85   - * @lvec_offset: offset in bytes from current iovec iov_base we are up to
  73 + * @iter: where to copy to/from locally
86 74 * @process_pages: struct pages area that can store at least
87 75 * nr_pages_to_copy struct page pointers
88 76 * @mm: mm for task
89 77 * @task: task to read/write from
90 78 * @vm_write: 0 means copy from, 1 means copy to
91   - * @bytes_copied: returns number of bytes successfully copied
92 79 * Returns 0 on success or on failure error code
93 80 */
94 81 static int process_vm_rw_single_vec(unsigned long addr,
... ... @@ -103,7 +90,6 @@
103 90 unsigned long start_offset = addr - pa;
104 91 unsigned long nr_pages;
105 92 ssize_t rc = 0;
106   - unsigned long nr_pages_copied = 0;
107 93 unsigned long max_pages_per_loop = PVM_MAX_KMALLOC_PAGES
108 94 / sizeof(struct pages *);
109 95  
110 96  
111 97  
112 98  
113 99  
114 100  
115 101  
... ... @@ -112,38 +98,32 @@
112 98 return 0;
113 99 nr_pages = (addr + len - 1) / PAGE_SIZE - addr / PAGE_SIZE + 1;
114 100  
115   - while ((nr_pages_copied < nr_pages) && iov_iter_count(iter)) {
116   - int nr_pages_to_copy;
117   - int pages_pinned;
118   - size_t n;
119   - nr_pages_to_copy = min(nr_pages - nr_pages_copied,
120   - max_pages_per_loop);
  101 + while (!rc && nr_pages && iov_iter_count(iter)) {
  102 + int pages = min(nr_pages, max_pages_per_loop);
  103 + size_t bytes;
121 104  
122 105 /* Get the pages we're interested in */
123 106 down_read(&mm->mmap_sem);
124   - pages_pinned = get_user_pages(task, mm, pa,
125   - nr_pages_to_copy,
126   - vm_write, 0, process_pages, NULL);
  107 + pages = get_user_pages(task, mm, pa, pages,
  108 + vm_write, 0, process_pages, NULL);
127 109 up_read(&mm->mmap_sem);
128 110  
129   - if (pages_pinned <= 0)
  111 + if (pages <= 0)
130 112 return -EFAULT;
131 113  
132   - n = pages_pinned * PAGE_SIZE - start_offset;
133   - if (n > len)
134   - n = len;
  114 + bytes = pages * PAGE_SIZE - start_offset;
  115 + if (bytes > len)
  116 + bytes = len;
135 117  
136 118 rc = process_vm_rw_pages(process_pages,
137   - start_offset, n, iter,
  119 + start_offset, bytes, iter,
138 120 vm_write);
139   - len -= n;
  121 + len -= bytes;
140 122 start_offset = 0;
141   - nr_pages_copied += pages_pinned;
142   - pa += pages_pinned * PAGE_SIZE;
143   - while (pages_pinned)
144   - put_page(process_pages[--pages_pinned]);
145   - if (rc < 0)
146   - break;
  123 + nr_pages -= pages;
  124 + pa += pages * PAGE_SIZE;
  125 + while (pages)
  126 + put_page(process_pages[--pages]);
147 127 }
148 128  
149 129 return rc;
... ... @@ -156,8 +136,7 @@
156 136 /**
157 137 * process_vm_rw_core - core of reading/writing pages from task specified
158 138 * @pid: PID of process to read/write from/to
159   - * @lvec: iovec array specifying where to copy to/from locally
160   - * @liovcnt: size of lvec array
  139 + * @iter: where to copy to/from locally
161 140 * @rvec: iovec array specifying where to copy to/from in the other process
162 141 * @riovcnt: size of rvec array
163 142 * @flags: currently unused