Skip to content

Commit ef7d0f5

Browse files
committed
m68k/mm: 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, do the same with pfn_to_virt(). Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent c94b1a0 commit ef7d0f5

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

arch/m68k/include/asm/page_mm.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,15 @@ static inline void *__va(unsigned long x)
121121
* TODO: implement (fast) pfn<->pgdat_idx conversion functions, this makes lots
122122
* of the shifts unnecessary.
123123
*/
124-
#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
125-
#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
124+
static inline unsigned long virt_to_pfn(const void *kaddr)
125+
{
126+
return __pa(kaddr) >> PAGE_SHIFT;
127+
}
128+
129+
static inline void *pfn_to_virt(unsigned long pfn)
130+
{
131+
return __va(pfn << PAGE_SHIFT);
132+
}
126133

127134
extern int m68k_virt_to_node_shift;
128135

arch/m68k/include/asm/page_no.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ extern unsigned long memory_end;
1919
#define __pa(vaddr) ((unsigned long)(vaddr))
2020
#define __va(paddr) ((void *)((unsigned long)(paddr)))
2121

22-
#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
23-
#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT)
22+
static inline unsigned long virt_to_pfn(const void *kaddr)
23+
{
24+
return __pa(kaddr) >> PAGE_SHIFT;
25+
}
26+
27+
static inline void *pfn_to_virt(unsigned long pfn)
28+
{
29+
return __va(pfn << PAGE_SHIFT);
30+
}
2431

2532
#define virt_to_page(addr) (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))
2633
#define page_to_virt(page) __va(((((page) - mem_map) << PAGE_SHIFT) + PAGE_OFFSET))

0 commit comments

Comments
 (0)