[PATCH v4 2/7] mm: Implement for_each_valid_pfn() for CONFIG_FLATMEM
David Hildenbrand
david at redhat.com
Thu Apr 24 14:13:17 PDT 2025
On 23.04.25 15:33, David Woodhouse wrote:
> From: David Woodhouse <dwmw at amazon.co.uk>
>
> In the FLATMEM case, the default pfn_valid() just checks that the PFN is
> within the range [ ARCH_PFN_OFFSET .. ARCH_PFN_OFFSET + max_mapnr ).
>
> The for_each_valid_pfn() function can therefore be a simple for() loop
> using those as min/max respectively.
>
> Signed-off-by: David Woodhouse <dwmw at amazon.co.uk>
> Reviewed-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
> ---
> include/asm-generic/memory_model.h | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h
> index a3b5029aebbd..74d0077cc5fa 100644
> --- a/include/asm-generic/memory_model.h
> +++ b/include/asm-generic/memory_model.h
> @@ -30,7 +30,15 @@ static inline int pfn_valid(unsigned long pfn)
> return pfn >= pfn_offset && (pfn - pfn_offset) < max_mapnr;
> }
> #define pfn_valid pfn_valid
> -#endif
> +
> +#ifndef for_each_valid_pfn
> +#define for_each_valid_pfn(pfn, start_pfn, end_pfn) \
> + for ((pfn) = max_t(unsigned long, (start_pfn), ARCH_PFN_OFFSET); \
> + (pfn) < min_t(unsigned long, (end_pfn), \
> + ARCH_PFN_OFFSET + max_mapnr); \
> + (pfn)++)
> +#endif /* for_each_valid_pfn */
> +#endif /* valid_pfn */
"pfn_valid"
>
> #elif defined(CONFIG_SPARSEMEM_VMEMMAP)
>
Acked-by: David Hildenbrand <david at redhat.com>
--
Cheers,
David / dhildenb
More information about the linux-arm-kernel
mailing list