Commit fab9a116 authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman
Browse files

powerpc/mm: flatten function __find_linux_pte() step 1



__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 three steps.

Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 4df4b275
Loading
Loading
Loading
Loading
+22 −10
Original line number Original line Diff line number Diff line
@@ -339,12 +339,16 @@ pte_t *__find_linux_pte(pgd_t *pgdir, unsigned long ea,
	 */
	 */
	if (pgd_none(pgd))
	if (pgd_none(pgd))
		return NULL;
		return NULL;
	else if (pgd_huge(pgd)) {

	if (pgd_huge(pgd)) {
		ret_pte = (pte_t *)pgdp;
		ret_pte = (pte_t *)pgdp;
		goto out;
		goto out;
	} else if (is_hugepd(__hugepd(pgd_val(pgd))))
	}
	if (is_hugepd(__hugepd(pgd_val(pgd)))) {
		hpdp = (hugepd_t *)&pgd;
		hpdp = (hugepd_t *)&pgd;
	else {
		goto out_huge;
	}
	{
		/*
		/*
		 * Even if we end up with an unmap, the pgtable will not
		 * Even if we end up with an unmap, the pgtable will not
		 * be freed, because we do an rcu free and here we are
		 * 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))
		if (pud_none(pud))
			return NULL;
			return NULL;
		else if (pud_huge(pud)) {

		if (pud_huge(pud)) {
			ret_pte = (pte_t *) pudp;
			ret_pte = (pte_t *) pudp;
			goto out;
			goto out;
		} else if (is_hugepd(__hugepd(pud_val(pud))))
		}
		if (is_hugepd(__hugepd(pud_val(pud)))) {
			hpdp = (hugepd_t *)&pud;
			hpdp = (hugepd_t *)&pud;
		else {
			goto out_huge;
		}
		{
			pdshift = PMD_SHIFT;
			pdshift = PMD_SHIFT;
			pmdp = pmd_offset(&pud, ea);
			pmdp = pmd_offset(&pud, ea);
			pmd  = READ_ONCE(*pmdp);
			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)) {
			if (pmd_huge(pmd) || pmd_large(pmd)) {
				ret_pte = (pte_t *) pmdp;
				ret_pte = (pte_t *) pmdp;
				goto out;
				goto out;
			} else if (is_hugepd(__hugepd(pmd_val(pmd))))
			}
			if (is_hugepd(__hugepd(pmd_val(pmd)))) {
				hpdp = (hugepd_t *)&pmd;
				hpdp = (hugepd_t *)&pmd;
			else
				goto out_huge;
			}

			return pte_offset_kernel(&pmd, ea);
			return pte_offset_kernel(&pmd, ea);
		}
		}
	}
	}
out_huge:
	if (!hpdp)
	if (!hpdp)
		return NULL;
		return NULL;