summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam R. Howlett <Liam.Howlett@Oracle.com>2020-09-17 11:57:54 +1000
committerStephen Rothwell <sfr@canb.auug.org.au>2020-09-18 18:01:03 +1000
commitb64ede09fa7f74d00f73da708fca1211bfa09e4a (patch)
treeb9cc31fa2ca107435d38ea22ba562c59894df4a4
parent568f816b49c48b4f6f681e7a56f6f2ace654ba44 (diff)
downloadlinux-b64ede09fa7f74d00f73da708fca1211bfa09e4a.tar.gz
linux-b64ede09fa7f74d00f73da708fca1211bfa09e4a.tar.xz
mm/mmap: add inline vma_next() for readability of mmap code
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. Link: http://lkml.kernel.org/r/20200818154707.2515169-1-Liam.Howlett@Oracle.com Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
-rw-r--r--mm/mmap.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index fc9ad60e603e..3fcbe976c08b 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -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)
{
@@ -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;
@@ -2634,7 +2648,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();
@@ -2833,7 +2847,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)) {
/*