Re: [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again
From: Andrew Morton
Date: Wed Sep 16 2026 - 19:34:09 EST
On Wed, 16 Sep 2026 16:28:16 -0700 Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -3274,8 +3274,10 @@ struct ctrl_pos {
> > int gain;
> > };
> >
> > -static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier_min,
> > - int tier_max, int gain, struct ctrl_pos *pos)
> > +/* __noipa works around gcc-16 warning for uninitizled use of pos->refaulted */
> > +static __noipa void read_ctrl_pos(struct lruvec *lruvec, int type,
> > + int tier_min, int tier_max, int gain,
> > + struct ctrl_pos *pos)
> > {
> > int i;
> > struct lru_gen_folio *lrugen = &lruvec->lrugen;
>
> Current code has changed here somewhat, but I expect the error is still
> there. I fixed that "uninitizled" while in there. Altered patch is
> below.
Then the build blew up in unexpected ways. gcc-15.2.0.
The failure looks like a legit min() signedness thing which has been
there quite a while. I'm thinking that __noipa surfaced this for some
reason?
CC mm/vmscan.o
In file included from <command-line>:
mm/vmscan.c: In function 'read_ctrl_pos':
././include/linux/compiler_types.h:702:45: error: call to '__compiletime_assert_798' declared with attribute error: min(tier, 4U - 1) signedness error
702 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
I'll queue a fix to switch this to min_t (yuck) for now. It would of
course be better to use more appropriate types in this code. Unless
tiers can be negative!
From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Subject: mm/vmscan.c: fix min() signedness mismatch
Date: Wed Sep 16 04:21:22 PM PDT 2026
A __noipa conversion from Arnd [1] somehow revealed a longstanding min()
error in read_ctrl_pos(). Plug it with min_t().
Cc: Arnd Bergmann <arnd@xxxxxxxx>
Cc: Axel Rasmussen <axelrasmussen@xxxxxxxxxx>
Cc: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>
Cc: Baoquan He <baoquan.he@xxxxxxxxx>
Cc: Barry Song <baohua@xxxxxxxxxx>
Cc: David Hildenbrand <david@xxxxxxxxxx>
Cc: Johannes Weiner <hannes@xxxxxxxxxxx>
Cc: Kairui Song <kasong@xxxxxxxxxxx>
Cc: Lorenzo Stoakes <ljs@xxxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxxxxx>
Cc: Shakeel Butt <shakeel.butt@xxxxxxxxx>
Cc: Wei Xu <weixugc@xxxxxxxxxx>
Cc: Yuanchu Xie <yuanchu@xxxxxxxxxx>
Cc: <stable@xxxxxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---
mm/vmscan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/mm/vmscan.c~mm-vmscanc-fix-min-signedness-mismatch
+++ a/mm/vmscan.c
@@ -3205,7 +3205,7 @@ static void read_ctrl_pos(struct lruvec
pos->gain = gain;
pos->refaulted = pos->total = 0;
- for (i = tier % MAX_NR_TIERS; i <= min(tier, MAX_NR_TIERS - 1); i++) {
+ for (i = tier % MAX_NR_TIERS; i <= min_t(unsigned int, tier, MAX_NR_TIERS - 1); i++) {
pos->refaulted += lrugen->avg_refaulted[type][i] +
atomic_long_read(&lrugen->refaulted[hist][type][i]);
pos->total += lrugen->avg_total[type][i] +
_