Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

csky: Make pfn accessors static inlines

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.

For symmetry to the same thing with pfn_to_virt().

In order to do this we move the virt_to_phys() and
phys_to_virt() below the definitions of the __pa()
and __va() macros so it compiles. The macro version was also
able to do recursive symbol resolution.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>

authored by

Linus Walleij and committed by
Guo Ren
c1884e1e ee12fe28

+10 -3
+10 -3
arch/csky/include/asm/page.h
··· 34 34 35 35 #include <linux/pfn.h> 36 36 37 - #define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) 38 - #define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) 39 - 40 37 #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && \ 41 38 (void *)(kaddr) < high_memory) 42 39 ··· 76 79 #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET - va_pa_offset)) 77 80 78 81 #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0)) 82 + 83 + static inline unsigned long virt_to_pfn(const void *kaddr) 84 + { 85 + return __pa(kaddr) >> PAGE_SHIFT; 86 + } 87 + 88 + static inline void * pfn_to_virt(unsigned long pfn) 89 + { 90 + return (void *)((unsigned long)__va(pfn) << PAGE_SHIFT); 91 + } 79 92 80 93 #define MAP_NR(x) PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \ 81 94 PHYS_OFFSET_OFFSET)