Re: [PATCH v3] f2fs: fix valid block count leak on data block allocation failure

Chao Yu via Linux-f2fs-devel <[email protected]> Tue, 4 Aug 2026 09:08:13 +0800
Newsgroups gmane.linux.file-systems.f2fs,gmane.linux.kernel,gmane.linux.kernel.stable
Message-ID <[email protected]>
On 8/4/26 08:54, Chen Changcheng wrote:
> In __allocate_data_block(), when allocating a new data block
> (dn->data_blkaddr == NULL_ADDR), inc_valid_block_count() is
> called first to increment total_valid_block_count and i_blocks.
> If the subsequent f2fs_allocate_data_block() fails, the function
> returns the error directly without rolling back the
> already-incremented block counts, causing a permanent leak.
> 
> Fix this by calling dec_valid_block_count() to undo the
> increment before returning the error. The condition
> old_blkaddr == NULL_ADDR precisely identifies the case where
> inc_valid_block_count() was called.
> 
> Fixes: 7d009e048d7c ("f2fs: fix to handle segment allocation failure correctly")
> Cc: <[email protected]>
> Reviewed-by: Chao Yu <[email protected]>
> Signed-off-by: Chen Changcheng <[email protected]>

Reviewed-by: Chao Yu <[email protected]>

Thanks,