Commit 73848a97 authored by Wei Yang's avatar Wei Yang Committed by Linus Torvalds

mm/mmap.c: refine find_vma_prev() with rb_last()

When addr is out of range of the whole rb_tree, pprev will point to the
right-most node.  rb_tree facility already provides a helper function,
rb_last(), to do this task.  We can leverage this instead of
reimplementing it.

This patch refines find_vma_prev() with rb_last() to make it a little
nicer to read.

[akpm@linux-foundation.org: little cleanup, per Vlastimil]
Link: http://lkml.kernel.org/r/20190809001928.4950-1-richardw.yang@linux.intel.comSigned-off-by: default avatarWei Yang <richardw.yang@linux.intel.com>
Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 54c95a11
...@@ -2274,12 +2274,9 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr, ...@@ -2274,12 +2274,9 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
if (vma) { if (vma) {
*pprev = vma->vm_prev; *pprev = vma->vm_prev;
} else { } else {
struct rb_node *rb_node = mm->mm_rb.rb_node; struct rb_node *rb_node = rb_last(&mm->mm_rb);
*pprev = NULL;
while (rb_node) { *pprev = rb_node ? rb_entry(rb_node, struct vm_area_struct, vm_rb) : NULL;
*pprev = rb_entry(rb_node, struct vm_area_struct, vm_rb);
rb_node = rb_node->rb_right;
}
} }
return vma; return vma;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment