mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: Xinping Zhang <zhangxp1998@gmail.com>,
	linux-f2fs-devel@lists.sourceforge.net
Cc: chao@kernel.org, jaegeuk@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] f2fs: avoid underflow when counting free NIDs
Date: Tue, 1 Sep 2026 07:22:46 +0800	[thread overview]
Message-ID: <9134210e-8ce6-4b74-bc25-af024aabeb75@kernel.org> (raw)
In-Reply-To: <CAH=xXfG2Hzc-kNAPqEUsTJ4hwrQ-gYEnFrXHGxL7qpYpggkLUQ@mail.gmail.com>

Kelvin,

This patch was wrapped, please resend it as well.

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.
> 
> Signed-off-by: Kelvin Zhang <zhangxp1998@gmail.com>
> ---
>   fs/f2fs/shrinker.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c
> index 4f6bf5926de4..1fd0ee4f89a9 100644
> --- a/fs/f2fs/shrinker.c
> +++ b/fs/f2fs/shrinker.c
> @@ -23,9 +23,10 @@ static unsigned long __count_nat_entries(struct
> f2fs_sb_info *sbi)
> 
>   static unsigned long __count_free_nids(struct f2fs_sb_info *sbi)
>   {
> -	long count = NM_I(sbi)->nid_cnt[FREE_NID] - MAX_FREE_NIDS;
> +	unsigned long count = NM_I(sbi)->nid_cnt[FREE_NID];
> +	unsigned long max = MAX_FREE_NIDS;
> 
> -	return count > 0 ? count : 0;
> +	return count > max ? count - max : 0;
>   }
> 
>   static unsigned long __count_extent_cache(struct f2fs_sb_info *sbi,


  parent reply	other threads:[~2026-08-31 23:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-26 21:39 [PATCH 0/5] f2fs: prepare metadata layouts for runtime block sizes Xinping Zhang
2026-08-26 21:39 ` [PATCH 1/5] f2fs: avoid underflow when counting free NIDs Xinping Zhang
2026-08-27  3:39   ` Chao Yu
2026-08-31 23:22   ` Chao Yu [this message]
2026-09-01  1:21     ` [PATCH v2] " Kelvin Zhang
2026-08-26 21:39 ` [PATCH 2/5] f2fs: describe SIT block layout dynamically Xinping Zhang
2026-08-26 21:39 ` [PATCH 3/5] f2fs: describe orphan " Xinping Zhang
2026-08-26 21:39 ` [PATCH 4/5] f2fs: describe dentry " Xinping Zhang
2026-08-26 21:39 ` [PATCH 5/5] f2fs: describe inode node " Xinping Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9134210e-8ce6-4b74-bc25-af024aabeb75@kernel.org \
    --to=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhangxp1998@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®