Re: [PATCH] mm/gfp: cast GFP_ZONE_TABLE entries to long to avoid shift overflow

From: Yankai Xu

Date: Fri Dec 12 2025 - 02:19:35 EST


Hi Andrew,

Thanks for the review.

> Please quote the compiler warning messages and describe how to
> reproduce this.  Please include this info in the patch changelog and
> maintain it.

I have included them in patch v2. Here's the LKML link for reference:
https://lore.kernel.org/lkml/tencent_DAB2E2BC61A449B6AC4FA9798C4D75BED705@xxxxxx/T/#/u

> >  #define GFP_ZONE_TABLE ( \
> > -    (ZONE_NORMAL << 0 * GFP_ZONES_SHIFT)     \
> > +    ((long)ZONE_NORMAL << 0 * GFP_ZONES_SHIFT)       \
>
> It would be nice to find something nicer than this.  Perhaps a type of
> something was poorly chosen.

ZONE_NORMAL, ZONE_DMA32, etc. are enum values, which has an underlying
type of int. Changing either the underlying type or the enum type
itself is not feasible. Moreover, the shift overflow only occurs inside
GFP_ZONE_TABLE, modifying other code might be unnecessary. Adding
explicit casts seems to be the most straightforward solution here.

Thanks,
Yankai