aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-10-09 18:25:36 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-10-09 22:25:49 -0400
commit0c255321f879c36bd74f58f9c7ed235ea6b919cb (patch)
tree36492e5b8edf09b1afd0f4a898d6acaa2b948ad9 /fs/proc
parentebb6cdde1a50c3cd2a0a4668dfb571ecb3213449 (diff)
fs/proc/task_mmu.c: simplify m_start() to make it readable
Now that m->version is gone we can cleanup m_start(). In particular, - Remove the "unsigned long" typecast, m->index can't be negative or exceed ->map_count. But lets use "unsigned int pos" to make it clear that "pos < map_count" is safe. - Remove the unnecessary "vma != NULL" check in the main loop. It can't be NULL unless we have a vm bug. - This also means that "pos < map_count" case can simply return the valid vma and avoid "goto" and subsequent checks. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Cyrill Gorcunov <gorcunov@openvz.org> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/task_mmu.c34
1 files changed, 10 insertions, 24 deletions
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index e182fc51ec2b..bb16c967eefd 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -138,12 +138,12 @@ static void vma_stop(struct proc_maps_private *priv)
138 mmput(mm); 138 mmput(mm);
139} 139}
140 140
141static void *m_start(struct seq_file *m, loff_t *pos) 141static void *m_start(struct seq_file *m, loff_t *ppos)
142{ 142{
143 struct proc_maps_private *priv = m->private; 143 struct proc_maps_private *priv = m->private;
144 struct mm_struct *mm; 144 struct mm_struct *mm;
145 struct vm_area_struct *vma, *tail_vma = NULL; 145 struct vm_area_struct *vma;
146 loff_t l = *pos; 146 unsigned int pos = *ppos;
147 147
148 priv->task = get_pid_task(priv->pid, PIDTYPE_PID); 148 priv->task = get_pid_task(priv->pid, PIDTYPE_PID);
149 if (!priv->task) 149 if (!priv->task)
@@ -152,33 +152,19 @@ static void *m_start(struct seq_file *m, loff_t *pos)
152 mm = priv->mm; 152 mm = priv->mm;
153 if (!mm || !atomic_inc_not_zero(&mm->mm_users)) 153 if (!mm || !atomic_inc_not_zero(&mm->mm_users))
154 return NULL; 154 return NULL;
155 down_read(&mm->mmap_sem);
156 155
157 tail_vma = get_gate_vma(mm); 156 down_read(&mm->mmap_sem);
158 priv->tail_vma = tail_vma;
159 hold_task_mempolicy(priv); 157 hold_task_mempolicy(priv);
158 priv->tail_vma = get_gate_vma(mm);
160 159
161 /* 160 if (pos < mm->map_count) {
162 * Check the vma index is within the range and do 161 for (vma = mm->mmap; pos; pos--)
163 * sequential scan until m_index.
164 */
165 vma = NULL;
166 if ((unsigned long)l < mm->map_count) {
167 vma = mm->mmap;
168 while (l-- && vma)
169 vma = vma->vm_next; 162 vma = vma->vm_next;
170 goto out;
171 }
172
173 if (l != mm->map_count)
174 tail_vma = NULL; /* After gate vma */
175
176out:
177 if (vma)
178 return vma; 163 return vma;
164 }
179 165
180 if (tail_vma) 166 if (pos == mm->map_count && priv->tail_vma)
181 return tail_vma; 167 return priv->tail_vma;
182 168
183 vma_stop(priv); 169 vma_stop(priv);
184 return NULL; 170 return NULL;