[PATCH] MIPS: Fix undefined behavior in PAGE_MASK calculation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Linke Li <lilinke99@xxxxxxxxx>

Make PAGE_MASK an unsigned long, like it is on x86, to avoid:

../arch/mips/include/asm/ginvt.h:44:20: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
        addr &= PAGE_MASK << 1;

In the MIPS architecture, the PAGE_MASK definition in arch/mips/include/asm/page.h leads to
shifting a negative signed value, which is undefined according to the language specification.
To address this issue, the PAGE_MASK definition is modified to be unsigned long and ensure
well-defined behavior.

Signed-off-by: Linke Li <lilinke99@xxxxxxxxx>
---
 arch/mips/include/asm/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
index 5978a8dfb917..3061a5586954 100644
--- a/arch/mips/include/asm/page.h
+++ b/arch/mips/include/asm/page.h
@@ -33,7 +33,7 @@
 #define PAGE_SHIFT	16
 #endif
 #define PAGE_SIZE	(_AC(1,UL) << PAGE_SHIFT)
-#define PAGE_MASK	(~((1 << PAGE_SHIFT) - 1))
+#define PAGE_MASK	(~(PAGE_SIZE - 1))
 
 /*
  * This is used for calculating the real page sizes
-- 
2.25.1




[Index of Archives]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux