Skip to content

Commit da4382a

Browse files
Linus Walleijarndb
authored andcommitted
ARC: mm: 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. In order to do this we move the virt_to_phys() and below the definition 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: Arnd Bergmann <arnd@arndb.de>
1 parent 235a59c commit da4382a

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

arch/arc/include/asm/page.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,6 @@ typedef struct {
8484

8585
typedef struct page *pgtable_t;
8686

87-
/*
88-
* Use virt_to_pfn with caution:
89-
* If used in pte or paddr related macros, it could cause truncation
90-
* in PAE40 builds
91-
* As a rule of thumb, only use it in helpers starting with virt_
92-
* You have been warned !
93-
*/
94-
#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
95-
9687
/*
9788
* When HIGHMEM is enabled we have holes in the memory map so we need
9889
* pfn_valid() that takes into account the actual extents of the physical
@@ -122,6 +113,18 @@ extern int pfn_valid(unsigned long pfn);
122113
#define __pa(vaddr) ((unsigned long)(vaddr))
123114
#define __va(paddr) ((void *)((unsigned long)(paddr)))
124115

116+
/*
117+
* Use virt_to_pfn with caution:
118+
* If used in pte or paddr related macros, it could cause truncation
119+
* in PAE40 builds
120+
* As a rule of thumb, only use it in helpers starting with virt_
121+
* You have been warned !
122+
*/
123+
static inline unsigned long virt_to_pfn(const void *kaddr)
124+
{
125+
return __pa(kaddr) >> PAGE_SHIFT;
126+
}
127+
125128
#define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr))
126129
#define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr))
127130

arch/arc/include/asm/pgtable-levels.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
#define pmd_clear(xp) do { pmd_val(*(xp)) = 0; } while (0)
160160
#define pmd_page_vaddr(pmd) (pmd_val(pmd) & PAGE_MASK)
161161
#define pmd_pfn(pmd) ((pmd_val(pmd) & PAGE_MASK) >> PAGE_SHIFT)
162-
#define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd))
162+
#define pmd_page(pmd) virt_to_page((void *)pmd_page_vaddr(pmd))
163163
#define set_pmd(pmdp, pmd) (*(pmdp) = pmd)
164164
#define pmd_pgtable(pmd) ((pgtable_t) pmd_page(pmd))
165165

0 commit comments

Comments
 (0)