Re: [PATCH 1/5] f2fs: avoid underflow when counting free NIDs

From: Chao Yu

Date: Wed Aug 26 2026 - 23:39:48 EST


On 8/27/26 05:39, Xinping Zhang wrote:
> __count_free_nids() subtracts the retention threshold before checking
> whether the cached count exceeds it. The operands are unsigned, so a
> smaller cache wraps before the result is assigned to long.
>
> The PAGE_SIZE-derived threshold happens to make this an unsigned long
> subtraction, whose wrapped result becomes negative when converted to
> long by supported toolchains. Do not rely on operand width or
> unsigned-to-signed conversion. Compare values before subtracting.
>

Cc: stable@xxxxxxxxxx
Fixes: 1b38dc8e74a3 ("f2fs: shrink nat_cache entries")
Fixes: 02110a4fd531 ("f2fs: avoid casted negative value as shrink count")

> Signed-off-by: Kelvin Zhang <zhangxp1998@xxxxxxxxx>
Reviewed-by: Chao Yu <chao@xxxxxxxxxx>

Thanks,