From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 891FE19A288 for ; Mon, 3 Aug 2026 07:11:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785741088; cv=none; b=Wn8eiWAVmdk4dFRD0fQCYNspJrSuATX4I6ymNTe5qf9JvxEU2PMEuHp0FuNvhhVsjyQAu2kwIUZy6GfcAiYnqhQ5p/VbNveXdeDVahgaQ2qnaQaMBDW2Q5qITYu8xtcWTcvGIhD2jsHk+Bw4zyR8vFuZYuIZWhr9Iv4WtKDxeBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785741088; c=relaxed/simple; bh=Uzy9t38NG2MoL3JM7tEe5Un24n3pnkBj8UtsCT6EISk=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=PpPRrRKDEgQt9XeXYRhBOVplEdUACOd+btoGCirr1H66Mfxc8XrDjMXjjn+h667TIp0LBAWTXsC5avypZ/onPrie37/9Xfa1dwtBU2kikBrgWGR8zxffQHL4GjXZWjlBloQGgWjWDkyzLiHEaWzWGzaX/aQX6Zst/58pUVU0JPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VtqZi1tK; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="VtqZi1tK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D40301F000E9; Mon, 3 Aug 2026 07:11:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785741087; bh=NJ7nl8dcHY8k0ENQaf/dyHcHE+K3mSom6ovue7pM26Y=; h=Date:Cc:Subject:To:References:From:In-Reply-To; b=VtqZi1tK5vwQPRPPU0glFH7m+l1CbHexHPIxPn/bKfOPKYHXbh9utHcAf9c79fcjl N71AtjDn897+J4gIuiBTcOwZkw1s7HPfg4TKivRkgjmeEHeff0IfES5eGV8gwG+LEd CpQl3SnbWsl0/hO8m22SdqbNGkhMCoXXbDLBmtwoi215uYLrhCF8aT9+vPj/4Nqiio cuFY7EUlBMokai2MZNbFYcX9J5kIcqjZ+PvA8CFmxuS7w7VqGdLq3nGea10jHUeARX Ha8XAvNxb9ZFFSfqCaDJ+YZollre7IVOr+fXPwX2SoAiBP12NK1X7FUcn/2Y8lcpsQ 9dVw7lpicZkVA== Message-ID: Date: Mon, 3 Aug 2026 15:11:23 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, ccc194101@163.com Subject: Re: [PATCH] f2fs: fix valid block count leak on data block allocation failure To: Chen Changcheng , jaegeuk@kernel.org References: <20260722005447.10885-1-chenchangcheng@kylinos.cn> Content-Language: en-US From: Chao Yu In-Reply-To: <20260722005447.10885-1-chenchangcheng@kylinos.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/22/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. > Needs fixes and Cc stable line? > Signed-off-by: Chen Changcheng Reviewed-by: Chao Yu Thanks, > --- > fs/f2fs/data.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c > index a765fda71536..819631bb61ae 100644 > --- a/fs/f2fs/data.c > +++ b/fs/f2fs/data.c > @@ -1532,8 +1532,11 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type) > old_blkaddr = dn->data_blkaddr; > err = f2fs_allocate_data_block(sbi, NULL, old_blkaddr, > &dn->data_blkaddr, &sum, seg_type, NULL); > - if (err) > + if (err) { > + if (old_blkaddr == NULL_ADDR) > + dec_valid_block_count(sbi, dn->inode, count); > return err; > + } > > if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) > f2fs_invalidate_internal_cache(sbi, old_blkaddr, 1);