Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp51714ybe; Thu, 12 Sep 2019 15:28:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqwrqNYZ6F8wKZkDcT2QtxGAp/o2Fl99ED2zDJg/ZZME9xj526VIvILa/9hTtuDHVUO/7GsL X-Received: by 2002:a17:906:3659:: with SMTP id r25mr20513090ejb.53.1568327299414; Thu, 12 Sep 2019 15:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568327299; cv=none; d=google.com; s=arc-20160816; b=IZ/LgElUYExiPN14T0pK9NS7o608lWZ4vKAhCJdy30zbjOIRfMO92MXp9FTbZYECiI 5F3UcxB1Y178brJnrbnncx1aoGVS3CAvLl/DfRw2ByO/umOizfKTezCy8V/srf9fKZLq iO8GtViQJfun7JdWq/NA8ERMcpiH3KdJ4lMx+vILbQfwByqas0UTivL+6mSUnwa2mkcq p3iZA5JxReOYqNUnDyCKBpDL7ELq46e6V1fGedPKA3IKR7ikOQap/zI9IPwWnuuYZlUY QH4hMHMYIFhVoxSDY96A4oB3yQyWgu4CsyyPzOwbrfcj2uW1bdDl5h9Z+QSBKPGmeEnD dllQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=LABCS+KOnofi+EQxzpepl6Pwu6yhf4vFGzAx1+fke7E=; b=bYkI9CNmpgsmigcs3wnxKsfr06S2qN6emPXCbC/CqMIJGwvr33IbwrjLkEorRUJINu nxQGFeazqfexmq5zbFC+SopmHNp2JV09YGX3P0kbTl5Cv9VSVtDuaiwrdIqf6SX/1BES N6xaL7GKHDKhaLGydB1MFAOdtdxOgPZElDzF7HfKFa3871oTgebXiBvSWHmXzoH+QiGW dk0U9/ExQb9CUiY/6UcPpYTkMGJaqVfD0u9iFEEwJHgB34JPPEGU+J6Vu5NyWDpZ+OqN PT6t8Kf3EkC1boA7JbNvWvQvjMe7/nA8q6IjLoiUCLxG3f7kly68ntuPjLP4KfNIfaOk bxBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id op27si12861463ejb.163.2019.09.12.15.27.56; Thu, 12 Sep 2019 15:28:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728926AbfILViN (ORCPT + 99 others); Thu, 12 Sep 2019 17:38:13 -0400 Received: from mga18.intel.com ([134.134.136.126]:29755 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728502AbfILViM (ORCPT ); Thu, 12 Sep 2019 17:38:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2019 14:38:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,492,1559545200"; d="scan'208";a="179487176" Received: from richard.sh.intel.com (HELO localhost) ([10.239.159.54]) by orsmga008.jf.intel.com with ESMTP; 12 Sep 2019 14:31:43 -0700 From: Wei Yang To: viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH 2/3] fs/userfaultfd.c: reorder the if check to reduce some computation Date: Fri, 13 Sep 2019 05:31:09 +0800 Message-Id: <20190912213110.3691-2-richardw.yang@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190912213110.3691-1-richardw.yang@linux.intel.com> References: <20190912213110.3691-1-richardw.yang@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When there are several condition check in *if* clause, the check will stop at the first false one. Since the for loop iterates vma list, we are sure only the last vma meets the condition "end <= vm_end". Reorder the check sequence to reduce some computation. Signed-off-by: Wei Yang --- fs/userfaultfd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 9ce09ac619a2..70c0e0ef01d7 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1402,7 +1402,7 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, * If this vma contains ending address, and huge pages * check alignment. */ - if (is_vm_hugetlb_page(cur) && end <= cur->vm_end) { + if (end <= cur->vm_end && is_vm_hugetlb_page(cur)) { unsigned long vma_hpagesize = vma_kernel_pagesize(cur); ret = -EINVAL; -- 2.17.1