mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linke Li <lilinke99@foxmail.com>
To: linux-mips@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, tsbogend@alpha.franken.de,
	Linke Li <lilinke99@gmail.com>
Subject: [PATCH] MIPS: Fix undefined behavior in PAGE_MASK calculation
Date: Sun,  9 Jul 2023 14:49:12 +0800	[thread overview]
Message-ID: <tencent_54C2A2746A83BA29EE92248CE9683F0C6509@qq.com> (raw)

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(-)

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


             reply	other threads:[~2023-07-09  6:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09  6:49 Linke Li [this message]
     [not found] ` <f7fab4fc-a8db-d2f7-52e9-3522f7c298b8@web.de>
2023-07-10  6:08   ` linke li
     [not found]   ` <CAKdjhyAOfbsxthU38=vSPJ080YxQvbGpbc5pupbz1gUQ=USwrQ@mail.gmail.com>
2023-07-25  8:48     ` Thomas Bogendoerfer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_54C2A2746A83BA29EE92248CE9683F0C6509@qq.com \
    --to=lilinke99@foxmail.com \
    --cc=lilinke99@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®