]> git.itanic.dy.fi Git - linux-stable/commitdiff
ARC: mm: Make virt_to_pfn() a static inline
authorLinus Walleij <linus.walleij@linaro.org>
Wed, 15 Nov 2023 13:28:14 +0000 (14:28 +0100)
committerArnd Bergmann <arnd@arndb.de>
Tue, 5 Dec 2023 12:11:37 +0000 (13:11 +0100)
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>
arch/arc/include/asm/page.h
arch/arc/include/asm/pgtable-levels.h

index 02b53ad811fb607951bf941a264864e347665253..def0dfb95b4369710fa1aac67aa920893fcd92c8 100644 (file)
@@ -84,15 +84,6 @@ typedef struct {
 
 typedef struct page *pgtable_t;
 
-/*
- * Use virt_to_pfn with caution:
- * If used in pte or paddr related macros, it could cause truncation
- * in PAE40 builds
- * As a rule of thumb, only use it in helpers starting with virt_
- * You have been warned !
- */
-#define virt_to_pfn(kaddr)     (__pa(kaddr) >> PAGE_SHIFT)
-
 /*
  * When HIGHMEM is enabled we have holes in the memory map so we need
  * pfn_valid() that takes into account the actual extents of the physical
@@ -122,6 +113,18 @@ extern int pfn_valid(unsigned long pfn);
 #define __pa(vaddr)            ((unsigned long)(vaddr))
 #define __va(paddr)            ((void *)((unsigned long)(paddr)))
 
+/*
+ * Use virt_to_pfn with caution:
+ * If used in pte or paddr related macros, it could cause truncation
+ * in PAE40 builds
+ * As a rule of thumb, only use it in helpers starting with virt_
+ * You have been warned !
+ */
+static inline unsigned long virt_to_pfn(const void *kaddr)
+{
+       return __pa(kaddr) >> PAGE_SHIFT;
+}
+
 #define virt_to_page(kaddr)    pfn_to_page(virt_to_pfn(kaddr))
 #define virt_addr_valid(kaddr)  pfn_valid(virt_to_pfn(kaddr))
 
index fc417c75c24db3cbaa0a27125908809947a4ee54..86e148226463017d9891f9ea721b2f330b1b0f77 100644 (file)
 #define pmd_clear(xp)          do { pmd_val(*(xp)) = 0; } while (0)
 #define pmd_page_vaddr(pmd)    (pmd_val(pmd) & PAGE_MASK)
 #define pmd_pfn(pmd)           ((pmd_val(pmd) & PAGE_MASK) >> PAGE_SHIFT)
-#define pmd_page(pmd)          virt_to_page(pmd_page_vaddr(pmd))
+#define pmd_page(pmd)          virt_to_page((void *)pmd_page_vaddr(pmd))
 #define set_pmd(pmdp, pmd)     (*(pmdp) = pmd)
 #define pmd_pgtable(pmd)       ((pgtable_t) pmd_page(pmd))