Re: [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning

From: Andrew Morton

Date: Fri Feb 13 2026 - 11:58:50 EST


On Fri, 13 Feb 2026 13:38:56 +0100 Arnd Bergmann <arnd@xxxxxxxxxx> wrote:

> From: Arnd Bergmann <arnd@xxxxxxxx>
>
> When the -fsanitize=bounds sanitizer is enabled,

Is this an option in current kernels?

> gcc-16 sometimes runs
> into a corner case in the read_ctrl_pos() pos function, where it sees
> possible undefined behavior from the 'tier' index overflowing, presumably
> in the case that this was called with a negative tier:
>
> In function 'get_tier_idx',
> inlined from 'isolate_folios' at mm/vmscan.c:4671:14:
> mm/vmscan.c: In function 'isolate_folios':
> mm/vmscan.c:4645:29: error: 'pv.refaulted' is used uninitialized [-Werror=uninitialized]
>
> Part of the problem seems to be that read_ctrl_pos() has unusual calling
> conventions since commit 37a260870f2c ("mm/mglru: rework type selection")
> where passing MAX_NR_TIERS makes it accumulate all tiers but passing a
> smaller positive number makes it read a single tier instead.
>
> Avoid this case by splitting read_ctrl_pos() into two separate helpers
> that each only do one of the two cases. This avoids the warning as far
> as I can tell, and seems a bit easier to understand to me.
>
> Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>
> ---
> This is currently the only such warning I get from gcc-16.0.1, and
> none from any other version.
>
> I'm not overly happy about having to work around it with a random
> code chance, but hopefully the version I ended up with makes
> sense regardless.

Seems a large change just to squish a compiler warning. People might
prefer a simple

- struct ctrl_pos sp, pv;
+ struct ctrl_pos sp, pv = {};

?