From: Liu Song Date: Fri, 5 Nov 2021 20:39:03 +0000 (-0700) Subject: mm/mprotect.c: avoid repeated assignment in do_mprotect_pkey() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=6af5fa0dc7836ea44bb0659f002b0cd0a2970554;p=linux.git mm/mprotect.c: avoid repeated assignment in do_mprotect_pkey() After adjustment, the repeated assignment of "prev" is avoided, and the readability of the code is improved. Link: https://lkml.kernel.org/r/20211012152444.4127-1-fishland@aliyun.com Reviewed-by: Andrew Morton Signed-off-by: Liu Song Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/mprotect.c b/mm/mprotect.c index 883e2cc85cad8..e552f5e0ccbde 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -563,7 +563,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, error = -ENOMEM; if (!vma) goto out; - prev = vma->vm_prev; + if (unlikely(grows & PROT_GROWSDOWN)) { if (vma->vm_start >= end) goto out; @@ -581,8 +581,11 @@ static int do_mprotect_pkey(unsigned long start, size_t len, goto out; } } + if (start > vma->vm_start) prev = vma; + else + prev = vma->vm_prev; for (nstart = start ; ; ) { unsigned long mask_off_old_flags;