Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2003720pxb; Mon, 18 Jan 2021 05:56:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIj+K63Ih19eXb4aGdpO3t+CdJqL+dt0a+GLf+RMjMqEBZ+D5JzN7wymSeNj+V0CJErnPI X-Received: by 2002:a05:6402:22d6:: with SMTP id dm22mr18957154edb.255.1610978203134; Mon, 18 Jan 2021 05:56:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610978203; cv=none; d=google.com; s=arc-20160816; b=Oxuz+57NUm7fEbLv7c3xG/CsR3k8z7IeIXf4vqUGJoolc2Vg4C9rGe4iaFU6HT2SjU bprygib+kmbtR4k74kzYyw3Z8/SrVAPesEZvZdJZqw4RarSEts5VEKOHBIZNHcuMs7og o82KO7oe+19mcLAk8ShMPewEQYpDEFhvmRUS51cFHwWC3gCMOfUlbR+a3tvb86szaF4/ f6fwm7VZMm/PadcPMiDLrFL+FkrUI8Q3Np+Md4Yizfs+RwUDnlCPQ50Ym7wfuqrzJWGc d895DgGTSwnsIs7CQ94ex6dBs3DQnUUTuPqyt4SjeXrMsIa1UlfRn4IJEkvk39ALceA8 n4pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=3nohCVTRvUPu+AUs+uIv7vbKAA4VmgKfW01NNBIPV70=; b=glA5aJtHHdzSoECqITruMUPAqEqDnmP2xrD/if42fHEYIVRVUzzx2H+FjdJputpJHS yrIzwtAdZFwRUaGeZxwIJPZygmyeEHFox/tovQH/x+0KlKMmTVCldVRMpNPkyPnaNo7m NGsTWshbOOCdVYZpf0+23RpztkDHU6JOzjqPN95z+DG3XXE3YS1lsP/LiqAnmIqJa0XY X0yHDkwOUREOLpyxyBIs3U4wxsFPbLE6Oo3d0QradGLeYrAE/QuKx8uqQLuoNGNHjT3f R4rkdtfR2ETgpuNzKdHkohN+eJ/2yPLrjXKiI5H+Jny0PvNQX+elH/xGIZOwhNeMNge6 c0rA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n18si6839624ejk.69.2021.01.18.05.56.20; Mon, 18 Jan 2021 05:56:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392492AbhARNxR (ORCPT + 99 others); Mon, 18 Jan 2021 08:53:17 -0500 Received: from out30-130.freemail.mail.aliyun.com ([115.124.30.130]:40318 "EHLO out30-130.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392291AbhARNeH (ORCPT ); Mon, 18 Jan 2021 08:34:07 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---0UM8540F_1610976790; Received: from localhost(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0UM8540F_1610976790) by smtp.aliyun-inc.com(127.0.0.1); Mon, 18 Jan 2021 21:33:10 +0800 From: Tianjia Zhang To: Jarkko Sakkinen , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Andrew Morton , Shuah Khan , haitao.huang@intel.com, Kai Huang , x86@kernel.org, linux-sgx@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Jia Zhang Cc: Tianjia Zhang Subject: [PATCH] mm: Optimizing error condition detection in do_mprotect_pkey() Date: Mon, 18 Jan 2021 21:33:10 +0800 Message-Id: <20210118133310.98375-1-tianjia.zhang@linux.alibaba.com> X-Mailer: git-send-email 2.19.1.3.ge56e4f7 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Obviously, the error variable detection of the if statement is for the mprotect callback function, so it is also put into the scope of calling callbck. Reported-by: Jia Zhang Signed-off-by: Tianjia Zhang --- mm/mprotect.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/mprotect.c b/mm/mprotect.c index ab709023e9aa..94188df1ee55 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -617,10 +617,11 @@ static int do_mprotect_pkey(unsigned long start, size_t len, if (tmp > end) tmp = end; - if (vma->vm_ops && vma->vm_ops->mprotect) + if (vma->vm_ops && vma->vm_ops->mprotect) { error = vma->vm_ops->mprotect(vma, nstart, tmp, newflags); - if (error) - goto out; + if (error) + goto out; + } error = mprotect_fixup(vma, &prev, nstart, tmp, newflags); if (error) -- 2.19.1.3.ge56e4f7