Skip to contentSkip to conversation

Fix the data type inconsistency issue of min (tier, MAX_CR_TIERS-1) in read_ctrl_pos

PATCH New Qingshuang Fu 1 participant 1 message Aug 8, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix the data type inconsistency issue of min (tier, MAX_CR_TIERS-1) in read_ctrl_pos

From: Qingshuang Fu <[email protected]>

Due to the fact that the tier data type in min (tier, MAX_CR_TIERS -1) is int,but MAX_CR_TIERS is an unsigned type, directly using the min function for comparison will result in an error:
from mm/vmscan.c:15:
mm/vmscan.c: In function ‘read_ctrl_pos’:
./include/linux/build_bug.h:78:41: error: static assertion failed:
"min(tier, 4U - 1) signedness error, fix types or
consider umin() before min_t()"
And MAX_CR_TIERS is a macro definition defined as 4U,
so min_t can be used to convert it to int type before performing the minimum value operation.

---
 mm/vmscan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c +1 -1
index 7de11524a936..f991196fd8e5 100644
@@ -3194,7 +3194,7 @@ static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier, int gain,
 	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(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] +
Signature · 1 line
2.25.1