[PATCH] arm64: kernel: Replace manual computation with macro
Catalin Marinas
catalin.marinas at arm.com
Fri May 17 08:31:12 PDT 2024
On Fri, May 17, 2024 at 06:54:21PM +0530, Dev Jain wrote:
> diff --git a/arch/arm64/kernel/pi/map_range.c b/arch/arm64/kernel/pi/map_range.c
> index 5410b2cac590..4b145be7f846 100644
> --- a/arch/arm64/kernel/pi/map_range.c
> +++ b/arch/arm64/kernel/pi/map_range.c
> @@ -31,14 +31,14 @@ void __init map_range(u64 *pte, u64 start, u64 end, u64 pa, pgprot_t prot,
> {
> u64 cmask = (level == 3) ? CONT_PTE_SIZE - 1 : U64_MAX;
> u64 protval = pgprot_val(prot) & ~PTE_TYPE_MASK;
> - int lshift = (3 - level) * (PAGE_SHIFT - 3);
> - u64 lmask = (PAGE_SIZE << lshift) - 1;
> + int lshift = ARM64_HW_PGTABLE_LEVEL_SHIFT(level);
> + u64 lmask = ((u64)1 << lshift) - 1;
Nitpick: you can use 1UL instead of (u64)1.
>
> start &= PAGE_MASK;
> pa &= PAGE_MASK;
>
> /* Advance tbl to the entry that covers start */
> - tbl += (start >> (lshift + PAGE_SHIFT)) % PTRS_PER_PTE;
> + tbl += (start >> lshift) % PTRS_PER_PTE;
I did the maths as well my own way and the change is correct:
lshift + PAGE_SHIT == ARM64_HW_PGTABLE_LEVEL_SHIFT(level)
It probably is easier to read this way, so:
Reviewed-by: Catalin Marinas <catalin.marinas at arm.com>
More information about the linux-arm-kernel
mailing list