]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/mmap: Introduce unlock_range() for code cleanup
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 21 Sep 2020 19:37:14 +0000 (15:37 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 18 Jan 2021 15:40:26 +0000 (10:40 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
mm/mmap.c

index c8d297111da5d508a056c4e2c8ae6198f666331d..bf1793c44928b9d0f00adbd20dbbe21142a62b89 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -3009,6 +3009,20 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
        return __split_vma(mm, vma, addr, new_below);
 }
 
+static inline void unlock_range(struct vm_area_struct *start, unsigned long limit)
+{
+       struct mm_struct *mm = start->vm_mm;
+       struct vm_area_struct *tmp = start;
+
+       while (tmp && tmp->vm_start < limit) {
+               if (tmp->vm_flags & VM_LOCKED) {
+                       mm->locked_vm -= vma_pages(tmp);
+                       munlock_vma_pages_all(tmp);
+               }
+
+               tmp = tmp->vm_next;
+       }
+}
 /* Munmap is split into 2 main parts -- this part which finds
  * what needs doing, and the areas themselves, which do the
  * work.  This now handles partial unmappings.
@@ -3097,17 +3111,8 @@ int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len,
        /*
         * unlock any mlock()ed ranges before detaching vmas
         */
-       if (mm->locked_vm) {
-               struct vm_area_struct *tmp = vma;
-               while (tmp && tmp->vm_start < end) {
-                       if (tmp->vm_flags & VM_LOCKED) {
-                               mm->locked_vm -= vma_pages(tmp);
-                               munlock_vma_pages_all(tmp);
-                       }
-
-                       tmp = tmp->vm_next;
-               }
-       }
+       if (mm->locked_vm)
+               unlock_range(vma, end);
 
        /* Detach vmas from rbtree */
        if (!detach_vmas_to_be_unmapped(mm, vma, prev, end))
@@ -3410,14 +3415,8 @@ void exit_mmap(struct mm_struct *mm)
                mmap_write_unlock(mm);
        }
 
-       if (mm->locked_vm) {
-               vma = mm->mmap;
-               while (vma) {
-                       if (vma->vm_flags & VM_LOCKED)
-                               munlock_vma_pages_all(vma);
-                       vma = vma->vm_next;
-               }
-       }
+       if (mm->locked_vm)
+               unlock_range(mm->mmap, ULONG_MAX);
 
        arch_exit_mmap(mm);