From nobody Sat Jul 25 00:11:03 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 1AD893563E1 for ; Wed, 22 Jul 2026 00:54:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784681700; cv=none; b=TC0xIeG05kZUAGIZixwx/xEeRrHYrPTHWEEZzxuMkxtEpVBqN2dWdNsRMPWXfmGXc9YE9dBcWIUo5MGDdXuxYy3F6MuX47X75MO5HFEG5s+eXcU7d7/fiVEmZq+xAwxs8V3gq8CMtJjL5KeDcbnZSrnaxjocNtSQEDLja7uwVzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784681700; c=relaxed/simple; bh=qprkFEGq8bTX9CYl5vqlSfQtnArVF7SkE0r/HHKeNQE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=ID98GkBd7dn/jTnkU5w27FlXmZN0AhbcCyU1Ny1cfBCaLxXp6E8MhLpBiULVRAPY7gKLuw0ZTvm188K7Sce86OLVk/l3R+N9aZ+H/aRQpOUtlINBKU9pZJvJTIqe3+zejpCZ5YWEAiGTM1dnxI4gEvYSyFdZ9bD10xpKND0npz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: f28a4d00856711f1aa26b74ffac11d73-20260722 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:fa676e52-8cbf-44ef-849a-eadec202f042,IP:0,U RL:0,TC:0,Content:0,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:25 X-CID-META: VersionHash:e7bac3a,CLOUDID:086a5fbaddc75e940f4da3fa71058bbd,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:102|136|850|865|898,TC:nil,Content:0|15| 50,EDM:5,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0, OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: f28a4d00856711f1aa26b74ffac11d73-20260722 X-User: chenchangcheng@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1583758589; Wed, 22 Jul 2026 08:54:52 +0800 From: Chen Changcheng To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, ccc194101@163.com, Chen Changcheng Subject: [PATCH] f2fs: fix valid block count leak on data block allocation failure Date: Wed, 22 Jul 2026 08:54:47 +0800 Message-Id: <20260722005447.10885-1-chenchangcheng@kylinos.cn> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In __allocate_data_block(), when allocating a new data block (dn->data_blkaddr =3D=3D 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 =3D=3D NULL_ADDR precisely identifies the case where inc_valid_block_count() was called. Signed-off-by: Chen Changcheng --- 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_dat= a *dn, int seg_type) old_blkaddr =3D dn->data_blkaddr; err =3D f2fs_allocate_data_block(sbi, NULL, old_blkaddr, &dn->data_blkaddr, &sum, seg_type, NULL); - if (err) + if (err) { + if (old_blkaddr =3D=3D NULL_ADDR) + dec_valid_block_count(sbi, dn->inode, count); return err; + } =20 if (GET_SEGNO(sbi, old_blkaddr) !=3D NULL_SEGNO) f2fs_invalidate_internal_cache(sbi, old_blkaddr, 1); --=20 2.25.1