Re: [PATCH 1/1] mm/mm_init: compute hash mask with unsigned arithmetic

Andrew Morton <[email protected]>
Newsgroups org.kvack.linux-mm,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Sun, 9 Aug 2026 22:25:35 +0800 Longlong Xia <[email protected]> wrote:

> 在 2026/8/9 22:03, Mike Rapoport 写道:
> > Hi,
> >
> > On Sun, Aug 09, 2026 at 08:31:19PM +0800, Longlong Xia wrote:
> >> From: Longlong Xia <[email protected]>
> >>
> >> alloc_large_system_hash() allows up to 2^31 buckets, so log2qty can
> >> reach 31. At that limit, the current expression relies on signed
> >> integer wrapping to produce the unsigned hash mask.
> >>
> >> Use an unsigned literal so the mask is computed with unsigned
> >> arithmetic. Supported compiler settings already produce the same
> >> result, so this is a source-level cleanup with no functional change.
> > If complier already takes care of this then why do we want this patch?
> >   
> Fair point. Since supported compilers already produce the intended 
> result and this patch has no functional impact, the benefit is only 
> making the unsigned arithmetic explicit. So please disregard this patch.

It's a very small thing, but I believe the patch improves the code.

I mean, we erroneously compute a large negative number then subtract 1
from it then copy that larger negative number into a signed scalar.

The copied bit pattern happens to be what we'd have got if the code had
been correct, but the code isn't correct!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.