diff mbox series

MIPS: Fix undefined behavior in PAGE_MASK calculation

Message ID tencent_54C2A2746A83BA29EE92248CE9683F0C6509@qq.com (mailing list archive)
State Changes Requested
Headers show
Series MIPS: Fix undefined behavior in PAGE_MASK calculation | expand

Commit Message

Linke Li July 9, 2023, 6:49 a.m. UTC
From: Linke Li <lilinke99@gmail.com>

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@gmail.com>
---
 arch/mips/include/asm/page.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

linke li July 10, 2023, 6:08 a.m. UTC | #1
> How do you think about a wording variant like the following?

What you said is exactly what I want to express.

> Would you like to add the tag “Fixes”?

I agree with that.

Thank you for your feedback and suggestion.
Thomas Bogendoerfer July 25, 2023, 8:48 a.m. UTC | #2
On Mon, Jul 10, 2023 at 02:02:00PM +0800, linke li wrote:
> > How do you think about a wording variant like the following?
> 
> What you said is exactly what I want to express.
> 
> > Would you like to add the tag “Fixes”?
> 
> I agree with that.
> 
> Thank you for your feedback and suggestion.

plesas resend with this changes.

Thomas.
diff mbox series

Patch

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