Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp402320img; Wed, 20 Mar 2019 03:08:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFrNQbHiRvScDn11a4JnnOCeoX03Jfm0G9B/4LxvXDsZ7GlZvwbQu/34l6qXQUY05Van4E X-Received: by 2002:a63:4750:: with SMTP id w16mr7073522pgk.256.1553076509582; Wed, 20 Mar 2019 03:08:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553076509; cv=none; d=google.com; s=arc-20160816; b=jwEi5o4CValPAEuJgw1g095SBc/T6w5AIHQr7JTJJOEaWosVMVRN1gSl370FU/yPzr hjHrbZHe54QIjfwYXA224swYeKuYFx0ArOyUdzttjVruPnRM3VrowxE6V0nipCPGDbXm aNH05lIM6iwXWXr9btjhd7k8+sfpZWhUBqpkkOwt3MaRHXE1cXRJ8ZFSLmgr9JRgxgzP W3biGHxOskuyazlkfKCJQgYsy3db3bA9JKiMCiTksgrtLhU6uephE0yH89itbW0OSSgi NVo7yLKhm6oWTnOANf4m9scEl07mJYKV53OV+T9UU7zmzWeeb/LwnH6eG3nZ7UMvATi+ lOnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:references :in-reply-to:message-id:dkim-signature; bh=WJ7TCgPivsGBDKY9DLw8e4vCOBbhMBoUDuExbw1LynI=; b=YFa+ZpOlO1lsaZslgI2CPiXY3w6uQV0fFUC56lA0govdIBhYNsOVihDzaJ8Z/11wtD 3K2J5S64zTNbxsXyiVvU5cAM5VQnMdvZjc/YjuZi6pdXxrwtKLpFU0+VX+U0uz7DSUHc ACI4lvEDaLWp4RD/h58+843pk2mo7xLfOaVyDytXEkwcfjneQuAsS0KPUeSSj3hyckJr Fo4y9EvG4M875wuwP+Gp+N1PsbGrwh3rJn0AZUEiT1cYjvcNbbdzRdQlXsvHKRlXTA9F epWBXsuyn3/oQszeyOlb8dHsRGOO9nH7SXRAlPqq6bZwocSxLGUM1SPUDjwEGMc2C3zg SDcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@c-s.fr header.s=mail header.b=nZO1F+Wl; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d11si1319492pgh.447.2019.03.20.03.08.13; Wed, 20 Mar 2019 03:08:29 -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; dkim=pass header.i=@c-s.fr header.s=mail header.b=nZO1F+Wl; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727931AbfCTKHG (ORCPT + 99 others); Wed, 20 Mar 2019 06:07:06 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:62188 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725905AbfCTKHE (ORCPT ); Wed, 20 Mar 2019 06:07:04 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 44PQZF305Mz9vC0C; Wed, 20 Mar 2019 11:07:01 +0100 (CET) Authentication-Results: localhost; dkim=pass reason="1024-bit key; insecure key" header.d=c-s.fr header.i=@c-s.fr header.b=nZO1F+Wl; dkim-adsp=pass; dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id ub_0466ghx69; Wed, 20 Mar 2019 11:07:01 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 44PQZF1CqLz9vByx; Wed, 20 Mar 2019 11:07:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=c-s.fr; s=mail; t=1553076421; bh=WJ7TCgPivsGBDKY9DLw8e4vCOBbhMBoUDuExbw1LynI=; h=In-Reply-To:References:From:Subject:To:Cc:Date:From; b=nZO1F+WlAYNt95mU+MPvPjQMwVmLLwHK6D3EbtY9EQ1BfebpD2xzQbrC7b+dKDCzD UH2o71BjSoae/rUKJc2U+31X5BgONXXJPMYL6Qo+oSZwLLCtqZl3stVTVrK5REdcCe 9xCZa24U0D1gpMJbijEeFal4s08E3gLHu9SfyBrM= Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 4550D8B918; Wed, 20 Mar 2019 11:07:02 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id XWGiWzpgMPuU; Wed, 20 Mar 2019 11:07:02 +0100 (CET) Received: from po16846vm.idsi0.si.c-s.fr (unknown [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 21A188B911; Wed, 20 Mar 2019 11:07:02 +0100 (CET) Received: by po16846vm.idsi0.si.c-s.fr (Postfix, from userid 0) id DB96763AEF; Wed, 20 Mar 2019 10:07:01 +0000 (UTC) Message-Id: <91d2bdbcf0f02f689405ad7eb760ca5c6cb91ca5.1553076180.git.christophe.leroy@c-s.fr> In-Reply-To: References: From: Christophe Leroy Subject: [PATCH v1 25/27] powerpc/mm: flatten function __find_linux_pte() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , aneesh.kumar@linux.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Wed, 20 Mar 2019 10:07:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __find_linux_pte() is full of if/else which is hard to follow allthough the handling is pretty simple. This patch flattens the function by getting rid of as much if/else as possible. In order to ease the review, this is done in two steps. Signed-off-by: Christophe Leroy --- arch/powerpc/mm/pgtable.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c index 9f4ccd15849f..d332abeedf0a 100644 --- a/arch/powerpc/mm/pgtable.c +++ b/arch/powerpc/mm/pgtable.c @@ -339,12 +339,16 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea, */ if (pgd_none(pgd)) return NULL; - else if (pgd_huge(pgd)) { - ret_pte = (pte_t *) pgdp; + + if (pgd_huge(pgd)) { + ret_pte = (pte_t *)pgdp; goto out; - } else if (is_hugepd(__hugepd(pgd_val(pgd)))) + } + if (is_hugepd(__hugepd(pgd_val(pgd)))) { hpdp = (hugepd_t *)&pgd; - else { + goto out_huge; + } + { /* * Even if we end up with an unmap, the pgtable will not * be freed, because we do an rcu free and here we are @@ -356,12 +360,16 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea, if (pud_none(pud)) return NULL; - else if (pud_huge(pud)) { + + if (pud_huge(pud)) { ret_pte = (pte_t *) pudp; goto out; - } else if (is_hugepd(__hugepd(pud_val(pud)))) + } + if (is_hugepd(__hugepd(pud_val(pud)))) { hpdp = (hugepd_t *)&pud; - else { + goto out_huge; + } + { pdshift = PMD_SHIFT; pmdp = pmd_offset(&pud, ea); pmd = READ_ONCE(*pmdp); @@ -386,12 +394,16 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea, if (pmd_huge(pmd) || pmd_large(pmd)) { ret_pte = (pte_t *) pmdp; goto out; - } else if (is_hugepd(__hugepd(pmd_val(pmd)))) + } + if (is_hugepd(__hugepd(pmd_val(pmd)))) { hpdp = (hugepd_t *)&pmd; - else - return pte_offset_kernel(&pmd, ea); + goto out_huge; + } + + return pte_offset_kernel(&pmd, ea); } } +out_huge: if (!hpdp) return NULL; -- 2.13.3