From patchwork Fri Nov 5 20:39:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 12605531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 906ADC433EF for ; Fri, 5 Nov 2021 20:39:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5F6E760174 for ; Fri, 5 Nov 2021 20:39:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 5F6E760174 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 08D36940050; Fri, 5 Nov 2021 16:39:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 03D70940049; Fri, 5 Nov 2021 16:39:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4727940050; Fri, 5 Nov 2021 16:39:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id D25A4940049 for ; Fri, 5 Nov 2021 16:39:05 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 96A9618232A17 for ; Fri, 5 Nov 2021 20:39:05 +0000 (UTC) X-FDA: 78776041050.16.7043927 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf23.hostedemail.com (Postfix) with ESMTP id DBE4F90000A6 for ; Fri, 5 Nov 2021 20:38:51 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id AE0016056B; Fri, 5 Nov 2021 20:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1636144743; bh=kjdyWl6bfgEGl5f491e/pYQgwifhEzyB6NH8Q0LTYHo=; h=Date:From:To:Subject:In-Reply-To:From; b=H3Fp7F0cggfptGIjCRflLkByF630/2Zs0To0wwU92GG5Uw81sqKWjwemk6pRpuUMf vM0C85M9cBTKXiQqjNgRsVrWUKPXjdkSFUb0wqdE+RtGvnbhdeekjG4QDNZ6wloODB AzjckXuyg0eH3XpJ5dbI6nSP5SFtD57nyhTr1gcs= Date: Fri, 05 Nov 2021 13:39:03 -0700 From: Andrew Morton To: akpm@linux-foundation.org, linux-mm@kvack.org, liu.song11@zte.com.cn, mm-commits@vger.kernel.org, torvalds@linux-foundation.org Subject: [patch 084/262] mm/mprotect.c: avoid repeated assignment in do_mprotect_pkey() Message-ID: <20211105203903.w6-SbZ0O3%akpm@linux-foundation.org> In-Reply-To: <20211105133408.cccbb98b71a77d5e8430aba1@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: DBE4F90000A6 X-Stat-Signature: 8d8dcfk5fmwwdbai56kjxozgf9wnnaaw Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=H3Fp7F0c; dmarc=none; spf=pass (imf23.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-HE-Tag: 1636144731-580430 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Liu Song Subject: 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 --- mm/mprotect.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/mm/mprotect.c~mm-mprotectc-avoid-repeated-assignment-in-do_mprotect_pkey +++ a/mm/mprotect.c @@ -563,7 +563,7 @@ static int do_mprotect_pkey(unsigned lon 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 lon goto out; } } + if (start > vma->vm_start) prev = vma; + else + prev = vma->vm_prev; for (nstart = start ; ; ) { unsigned long mask_off_old_flags;