Skip to content

Commit c94b1a0

Browse files
committed
arm64: memory: Make virt_to_pfn() a static inline
Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long) as arguments without warnings. Since arm64 is using <asm-generic/memory_model.h> to provide __phys_to_pfn() we need to move the inclusion of that header up, so we can resolve the static inline at compile time. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent a9ff696 commit c94b1a0

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

arch/arm64/include/asm/memory.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ static inline void *phys_to_virt(phys_addr_t x)
331331
return (void *)(__phys_to_virt(x));
332332
}
333333

334+
/* Needed already here for resolving __phys_to_pfn() in virt_to_pfn() */
335+
#include <asm-generic/memory_model.h>
336+
337+
static inline unsigned long virt_to_pfn(const void *kaddr)
338+
{
339+
return __phys_to_pfn(virt_to_phys(kaddr));
340+
}
341+
334342
/*
335343
* Drivers should NOT use these either.
336344
*/
@@ -339,7 +347,6 @@ static inline void *phys_to_virt(phys_addr_t x)
339347
#define __pa_nodebug(x) __virt_to_phys_nodebug((unsigned long)(x))
340348
#define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x)))
341349
#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
342-
#define virt_to_pfn(x) __phys_to_pfn(__virt_to_phys((unsigned long)(x)))
343350
#define sym_to_pfn(x) __phys_to_pfn(__pa_symbol(x))
344351

345352
/*

0 commit comments

Comments
 (0)