[PATCH v2 3/4] tools: use __pa() in virt_to_phys()
From: Tianyi Chen
Date: Tue Sep 22 2026 - 22:32:26 EST
With 32-bit pointers and a 64-bit phys_addr_t, GCC warns about the
pointer-to-integer cast in virt_to_phys(). It can also sign-extend
pointers whose top bit is set, turning 0x80000000 into 0xffffffff80000000.
Use __pa() to convert through unsigned long before widening the result.
This preserves the unsigned pointer value and matches the other address
conversion helpers.
Reported-by: Mike Rapoport <rppt@xxxxxxxxxx>
Link: https://lore.kernel.org/r/179007180279.508753.4595268983388589280.b4-review@b4
Assisted-by: LLM
Signed-off-by: Tianyi Chen <hi@xxxxxxxxx>
---
tools/include/linux/mm.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/include/linux/mm.h b/tools/include/linux/mm.h
index 84b5954f66c3..480526de8d65 100644
--- a/tools/include/linux/mm.h
+++ b/tools/include/linux/mm.h
@@ -30,7 +30,7 @@ static inline void *phys_to_virt(unsigned long address)
#define virt_to_phys virt_to_phys
static inline phys_addr_t virt_to_phys(volatile void *address)
{
- return (phys_addr_t)address;
+ return __pa(address);
}
static inline void totalram_pages_inc(void)
--
2.55.0