mm/ksm: use vma_lookup() in find_mergeable_vma()
authorLiam Howlett <liam.howlett@oracle.com>
Tue, 29 Jun 2021 02:39:41 +0000 (19:39 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 29 Jun 2021 17:53:52 +0000 (10:53 -0700)
Use vma_lookup() to find the VMA at a specific address.  As vma_lookup()
will return NULL if the address is not within any VMA, the start address
no longer needs to be validated.

Link: https://lkml.kernel.org/r/20210521174745.2219620-19-Liam.Howlett@Oracle.com
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Laurent Dufour <ldufour@linux.ibm.com>
Acked-by: David Hildenbrand <david@redhat.com>
Acked-by: Davidlohr Bueso <dbueso@suse.de>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/ksm.c

index 2f3aaeb..3fa9bc8 100644 (file)
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -521,10 +521,8 @@ static struct vm_area_struct *find_mergeable_vma(struct mm_struct *mm,
        struct vm_area_struct *vma;
        if (ksm_test_exit(mm))
                return NULL;
-       vma = find_vma(mm, addr);
-       if (!vma || vma->vm_start > addr)
-               return NULL;
-       if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
+       vma = vma_lookup(mm, addr);
+       if (!vma || !(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
                return NULL;
        return vma;
 }