[PATCH v3] arm: fix clang build warning in include/asm/memory.h

Yipeng Zou zouyipeng at huawei.com
Fri Apr 12 19:28:43 PDT 2024


There is a build error has been founded with build in clang-15.0.4:

./arch/arm/include/asm/memory.h:358:12: error: result of comparison "phys addr_t’ (aka 'unsigned int’) > 4294967295 is always false [-Werror, -Wtautological-type-limit-compare]
                             if (addr > (u32)~0)
                                 ~~~~ ^ ~~~~~~~

It will be always goes fail without CONFIG_PHYS_ADDR_T_64BIT.

Directly silence it by Use CONFIG_PHYS_ADDR_T_64BIT.

Fixes: 981b6714dbd2 ("ARM: provide improved virt_to_idmap() functionality")
Signed-off-by: Yipeng Zou <zouyipeng at huawei.com>
Reviewed-by: Nathan Chancellor <nathan at kernel.org>
---
 arch/arm/include/asm/memory.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index ef2aa79ece5a..a7973eb8cbc7 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -19,6 +19,7 @@
 #include <linux/const.h>
 #include <linux/types.h>
 #include <linux/sizes.h>
+#include <linux/limits.h>
 
 #ifdef CONFIG_NEED_MACH_MEMORY_H
 #include <mach/memory.h>
@@ -353,8 +354,10 @@ static inline unsigned long phys_to_idmap(phys_addr_t addr)
 {
 	if (IS_ENABLED(CONFIG_MMU) && arch_phys_to_idmap_offset) {
 		addr += arch_phys_to_idmap_offset;
-		if (addr > (u32)~0)
+#ifdef CONFIG_PHYS_ADDR_T_64BIT
+		if (addr > U32_MAX)
 			addr = IDMAP_INVALID_ADDR;
+#endif
 	}
 	return addr;
 }
-- 
2.34.1




More information about the linux-arm-kernel mailing list