]> 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>
Fri, 30 Aug 2024 04:00:48 +0000 (00:00 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 4 Sep 2024 04:15:50 +0000 (21:15 -0700)
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.

Link: https://lkml.kernel.org/r/20240830040101.822209-9-Liam.Howlett@oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Bert Karwatzki <spasswolf@web.de>
Cc: Jeff Xu <jeffxu@chromium.org>
Cc: Jiri Olsa <olsajiri@gmail.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Sidhartha Kumar <sidhartha.kumar@oracle.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/mmap.c

index dce1cc74ecdbe6c33f846cf5315e6b189ec2baf9..ec72f05b05f227bfd42d523acf9ac2837ee1e0b8 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1388,12 +1388,15 @@ 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 */
+               error = do_vmi_align_munmap(&vmi, vma, mm, addr, end, uf, false);
+               if (error)
+                       return error;
+               vma = NULL;
+       }
 
        /*
         * Private writable mapping: check memory availability