Skip to content

Commit

Permalink
fs/proc/task_mmu.c: cleanup the "tail_vma" horror in m_next()
Browse files Browse the repository at this point in the history
1. Kill the first "vma != NULL" check. Firstly this is not possible,
   m_next() won't be called if ->start() or the previous ->next()
   returns NULL.

   And if it was possible the 2nd "vma != tail_vma" check is buggy,
   we should not wrongly return ->tail_vma.

2. Make this function readable. The logic is very simple, we should
   return check "vma != tail" once and return "vm_next || tail_vma".

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: 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>
  • Loading branch information
Oleg Nesterov authored and Linus Torvalds committed Oct 10, 2014
1 parent 59b4bf1 commit 23d5483
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions fs/proc/task_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,13 @@ static void *m_start(struct seq_file *m, loff_t *pos)
static void *m_next(struct seq_file *m, void *v, loff_t *pos)
{
struct proc_maps_private *priv = m->private;
struct vm_area_struct *vma = v;
struct vm_area_struct *tail_vma = priv->tail_vma;
struct vm_area_struct *next;
struct vm_area_struct *vma = v, *next = NULL;

(*pos)++;
if (vma && (vma != tail_vma) && vma->vm_next)
return vma->vm_next;
if (vma != tail_vma)
next = vma->vm_next ?: tail_vma;

next = (vma != tail_vma) ? tail_vma : NULL;
if (!next)
vma_stop(priv);
return next;
Expand Down

0 comments on commit 23d5483

Please sign in to comment.