From df01d54097f6e901c45eca81e9120e57be76979f Mon Sep 17 00:00:00 2001 From: Simon Guo Date: Sat, 10 Sep 2016 20:34:12 +1000 Subject: [PATCH] mm: mlock: correct a typo in count_mm_mlocked_page_nr() for caculate VMLOCKED pages There is a typo/bug in count_mm_mlocked_page_nr() for "&" which is mistakenly used with "&&". Also add more checks and some minor change based on Kirill's previous comment. Link: http://lkml.kernel.org/r/1473325970-11393-2-git-send-email-wei.guo.simon@gmail.com Signed-off-by: Simon Guo Suggested-by: Kirill A. Shutemov Signed-off-by: Andrew Morton --- mm/mlock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index e144f75a9e59..b1fec89bd1c5 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -638,9 +638,11 @@ static int count_mm_mlocked_page_nr(struct mm_struct *mm, vma = mm->mmap; for (; vma ; vma = vma->vm_next) { + if (start >= vma->vm_end) + continue; if (start + len <= vma->vm_start) break; - if (vma->vm_flags && VM_LOCKED) { + if (vma->vm_flags & VM_LOCKED) { if (start > vma->vm_start) count -= (start - vma->vm_start); if (start + len < vma->vm_end) { @@ -651,7 +653,7 @@ static int count_mm_mlocked_page_nr(struct mm_struct *mm, } } - return (PAGE_ALIGN(count) >> PAGE_SHIFT); + return count >> PAGE_SHIFT; } static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t flags) -- 2.34.1