]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm/vma: Inline munmap operation in mmap_region()
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 12 Aug 2024 22:07:29 +0000 (18:07 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 23 Aug 2024 12:46:02 +0000 (08:46 -0400)
mmap_region is already passed sanitized addr and len, so change the
call to do_vmi_munmap() to do_vmi_align_munmap() and inline the other
checks.

The inlining of the function and checks is an intermediate step in the
series so future patches are easier to follow.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
mm/mmap.c

index 112f2111c4578bdc090a5e330ab52e690c238682..0f5be29d48b6ef5ba1f81dac3942d96d80ad9d0a 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1388,12 +1388,14 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
                        return -ENOMEM;
        }
 
-       /* Unmap any existing mapping in the area */
-       error = do_vmi_munmap(&vmi, mm, addr, len, uf, false);
-       if (error == -EPERM)
-               return error;
-       else if (error)
-               return -ENOMEM;
+       /* Find the first overlapping VMA */
+       vma = vma_find(&vmi, end);
+       if (vma) {
+               /* Unmap any existing mapping in the area */
+               if (do_vmi_align_munmap(&vmi, vma, mm, addr, end, uf, false))
+                       return -ENOMEM;
+               vma = NULL;
+       }
 
        /*
         * Private writable mapping: check memory availability