Skip to content

Commit

Permalink
mm/mmap: add inline vma_next() for readability of mmap code
Browse files Browse the repository at this point in the history
There are three places that the next vma is required which uses the same
block of code.  Replace the block with a function and add comments on what
happens in the case where NULL is encountered.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/20200818154707.2515169-1-Liam.Howlett@Oracle.com
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Liam R. Howlett authored and Linus Torvalds committed Oct 18, 2020
1 parent 4dc200c commit 3903b55
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,23 @@ static int find_vma_links(struct mm_struct *mm, unsigned long addr,
return 0;
}

/*
* vma_next() - Get the next VMA.
* @mm: The mm_struct.
* @vma: The current vma.
*
* If @vma is NULL, return the first vma in the mm.
*
* Returns: The next VMA after @vma.
*/
static inline struct vm_area_struct *vma_next(struct mm_struct *mm,
struct vm_area_struct *vma)
{
if (!vma)
return mm->mmap;

return vma->vm_next;
}
static unsigned long count_vma_pages_range(struct mm_struct *mm,
unsigned long addr, unsigned long end)
{
Expand Down Expand Up @@ -1128,10 +1145,7 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
if (vm_flags & VM_SPECIAL)
return NULL;

if (prev)
next = prev->vm_next;
else
next = mm->mmap;
next = vma_next(mm, prev);
area = next;
if (area && area->vm_end == end) /* cases 6, 7, 8 */
next = next->vm_next;
Expand Down Expand Up @@ -2632,7 +2646,7 @@ static void unmap_region(struct mm_struct *mm,
struct vm_area_struct *vma, struct vm_area_struct *prev,
unsigned long start, unsigned long end)
{
struct vm_area_struct *next = prev ? prev->vm_next : mm->mmap;
struct vm_area_struct *next = vma_next(mm, prev);
struct mmu_gather tlb;

lru_add_drain();
Expand Down Expand Up @@ -2831,7 +2845,7 @@ int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len,
if (error)
return error;
}
vma = prev ? prev->vm_next : mm->mmap;
vma = vma_next(mm, prev);

if (unlikely(uf)) {
/*
Expand Down

0 comments on commit 3903b55

Please sign in to comment.