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

From: Andrew Morton

Date: Thu Dec 11 2025 - 15:04:49 EST


On Thu, 11 Dec 2025 18:24:05 +0800 Yankai Xu <815559068@xxxxxx> wrote:

>
> When a new zone is added to enum zone_type in mmzone.h, the existing
> GFP_ZONE_TABLE macro causes a compile-time shift overflow.

Thanks.

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

> This happens
> because enum zone_type is of type int. The shift is logically
> valid because it has been checked by 16 * GFP_ZONES_SHIFT > BITS_PER_LONG previously.
>
> Fixed this by casting each value in GFP_ZONE_TABLE to type long.
>
> ...
>
> #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.