2023-07-09 06:56:09

by Linke Li

[permalink] [raw]
Subject: [PATCH] MIPS: Fix undefined behavior in PAGE_MASK calculation

From: Linke Li <[email protected]>

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 <[email protected]>
---
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



2023-07-10 06:28:16

by linke li

[permalink] [raw]
Subject: Re: [PATCH] MIPS: Fix undefined behavior in PAGE_MASK calculation

> 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.

2023-07-25 09:03:35

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH] MIPS: Fix undefined behavior in PAGE_MASK calculation

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.

--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]