From nobody Wed Apr 1 12:38:01 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.2]) (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 09AE13DDDA3; Tue, 31 Mar 2026 09:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948350; cv=none; b=qEXkr8p7Ui0nqBijOexqe07m7YLDPT4Bu1yvA/J1pE8CGnmoUl2oYej55ZWc68hTRQZ56Y2MX5WG9FXHPbsS5uXupwjbEo4PaMvJl8qpH6Xv6f7HBBuZqThqWzQmDfCi7ogERpYIEjImQdgOqrJFO4nRHWwI9WfU/ID4lGNqp20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948350; c=relaxed/simple; bh=F/CDL8VyW0CX692DhFTu9Yr6yXj1cBGRo9UaLvxTghQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eeaZy7TDLifz8FlB+IVA4vyeVDhKow9vmxcOLJVFon2PQAKmTPyvz+fEKjWpLXd8MFBanwtOnVrlMSPb+9r0f83ne47gVsrmBa1Lnlx+tOnBLiAHltCEGAMi1Tikmt3hcmaYTztM6qNN3KXgwd4lMzjxNIumrzaTojyYLNeGz/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ZRlH9eFL; arc=none smtp.client-ip=220.197.31.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ZRlH9eFL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=x0 ZM9XluUnOwhkGJ9K+nXa5Rb6HeAXFfDwK1fCdCig0=; b=ZRlH9eFL5rXsamFQBQ /fBySuGRKVsB/YHK2+PTsZk3Qcx1OLC/Kq1PDuUz+hogtZjEW8Eu1q/0QkUqdWUA 1Op8qy1O+Uvgp1sbO3+GZiPT9cqPiW8nFN78Vf60z4rtXKiHwpIhMbJtsjwJc+XC 96AcEP1XhvHLGDxwE0BmDIHj4= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDXetTUj8tpdt0MCg--.18595S3; Tue, 31 Mar 2026 17:11:55 +0800 (CST) From: Chi Zhiling To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chi Zhiling Subject: [PATCH v1 1/6] exfat: fix incorrect directory checksum after rename to shorter name Date: Tue, 31 Mar 2026 17:11:08 +0800 Message-ID: <20260331091113.20882-2-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260331091113.20882-1-chizhiling@163.com> References: <20260331091113.20882-1-chizhiling@163.com> 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 X-CM-TRANSID: _____wDXetTUj8tpdt0MCg--.18595S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xr1DKF15uF15Ww13CF47twb_yoWkurX_ua yrtr1DKryYyFn8JwsxKF1rGr1Sga18ur15JrnYvFnxWas3tF9xXw1DCrnFv3W7tw4rKr98 CrykWr1qka1rtjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8EtC7UUUUU== X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+BtnBWnLj9vSXwAA36 Content-Type: text/plain; charset="utf-8" From: Chi Zhiling When renaming a file in-place to a shorter name, exfat_remove_entries marks excess entries as DELETED, but es->num_entries is not updated accordingly. As a result, exfat_update_dir_chksum iterates over the deleted entries and computes an incorrect checksum. This does not lead to persistent corruption because mark_inode_dirty() is called afterward, and __exfat_write_inode later recomputes the checksum using the correct num_entries value. Fix by setting es->num_entries =3D num_entries in exfat_init_ext_entry. Signed-off-by: Chi Zhiling --- fs/exfat/dir.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index a2c2b998808c..7619410d668e 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -490,6 +490,7 @@ void exfat_init_ext_entry(struct exfat_entry_set_cache = *es, int num_entries, unsigned short *uniname =3D p_uniname->name; struct exfat_dentry *ep; =20 + es->num_entries =3D num_entries; ep =3D exfat_get_dentry_cached(es, ES_IDX_FILE); ep->dentry.file.num_ext =3D (unsigned char)(num_entries - 1); =20 --=20 2.43.0 From nobody Wed Apr 1 12:38:01 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 871373EC2C7; Tue, 31 Mar 2026 09:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948349; cv=none; b=lqdppoud8Ib3U0EKGUQD0tXcViwIkUm+jjPIlhCYe9D8iM05vM74iheAFgncZz8BzoYmlqDLBB7OmEIBiMsc4ICTuA11Y9F6bhwrB/+tUuQeyEJa6d49EoXAQyfnJ98qYAt47bN889FGIbgttM031ZAU+/bJYQxaQPtRvv2FkYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948349; c=relaxed/simple; bh=m6L1EZDojc4EimSxu0sg9rOKnRQPzE6DXm5qmVqC7mg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=L1IGsve72BRrgUdHWvfx834Ca3Z55U4P1M8bdmPlKyTX0bjHKIVDgtv8ixDoi40cEI1a9mhMHxQIR9OareNXR7hoyDHzbKe2U5JJdnAfacKLGOpcxitzD5aSAtbz4LDVlTE5ZTjL2qqmS/kFnFXCGTNRrB314RpDMPFW80D8kjk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ndwtD1Mb; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ndwtD1Mb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=d7 gqt0VpacPWl4qG2W1JkG9/jpFuq9OVSqtAKhxyWmE=; b=ndwtD1Mb6qBOlAqklE yokqb0ua/8k1dfti8MvT7sBGOZzNisgiFW31T0pkbeTc3BlrB887vxs/KyE5XA+w hrie+yQSXuO1WO9IsFa85GPJv4MX8iKPPJWSB5mDSDfcGfGVAHRBa6UWdmNYwGUT j1k490I6hUC8pIJ8+Pye1u+eA= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDXetTUj8tpdt0MCg--.18595S4; Tue, 31 Mar 2026 17:11:56 +0800 (CST) From: Chi Zhiling To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chi Zhiling Subject: [PATCH v1 2/6] exfat: introduce exfat_fat_walk helper Date: Tue, 31 Mar 2026 17:11:09 +0800 Message-ID: <20260331091113.20882-3-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260331091113.20882-1-chizhiling@163.com> References: <20260331091113.20882-1-chizhiling@163.com> 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 X-CM-TRANSID: _____wDXetTUj8tpdt0MCg--.18595S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cr4xZrW8ArW5JF1fGry8Krg_yoW8ArW8pF 4UGw4rJrW5Wa47u3W3JFs3u3Wa9ws7GFyDArWxu3s0yrWDtF95uF98KryayF1Iqw40g3W5 KF1Ygr18urnxGrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jwGYLUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+BxoBmnLj9zSYgAA3L Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Introduce exfat_fat_walk() to walk the FAT chain by a given step, handling both ALLOC_NO_FAT_CHAIN and ALLOC_FAT_CHAIN modes. Also redefine exfat_get_next_cluster as a thin wrapper around it for backward compatibility. Signed-off-by: Chi Zhiling --- fs/exfat/exfat_fs.h | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 9fed9fb33cae..530459ab9acc 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -437,7 +437,8 @@ int exfat_set_volume_dirty(struct super_block *sb); int exfat_clear_volume_dirty(struct super_block *sb); =20 /* fatent.c */ -#define exfat_get_next_cluster(sb, pclu) exfat_ent_get(sb, *(pclu), pclu, = NULL) +#define exfat_get_next_cluster(sb, pclu) \ + exfat_fat_walk(sb, (pclu), 1, ALLOC_FAT_CHAIN) =20 int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc, struct exfat_chain *p_chain, bool sync_bmap); @@ -456,6 +457,26 @@ int exfat_count_num_clusters(struct super_block *sb, int exfat_blk_readahead(struct super_block *sb, sector_t sec, sector_t *ra, blkcnt_t *ra_cnt, sector_t end); =20 +static inline int +exfat_fat_walk(struct super_block *sb, unsigned int *clu, + unsigned int step, int flags) +{ + struct buffer_head *bh =3D NULL; + + if (flags =3D=3D ALLOC_NO_FAT_CHAIN) { + (*clu) +=3D step; + return 0; + } + + while (step--) { + if (exfat_ent_get(sb, *clu, clu, &bh)) + return -EIO; + } + brelse(bh); + + return 0; +} + /* balloc.c */ int exfat_load_bitmap(struct super_block *sb); void exfat_free_bitmap(struct exfat_sb_info *sbi); --=20 2.43.0 From nobody Wed Apr 1 12:38:01 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.3]) (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 4BA6E3EBF1C; Tue, 31 Mar 2026 09:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948347; cv=none; b=CUMHuxaO0d9HbOYEb9B1LZJbcbLiHRErenEVr06MNi1B/rLr13Fhafk+GgqiD/KCvzkvCWHXGxbkwcacwfPSMfcxr0s6eIUu8AvSd24//L7XIP5+tR1sUPq83PHtnlZ6Cg52WMEAA77ks2H6fUApTJSnxgFPXK+tYFXX7xF0Saw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948347; c=relaxed/simple; bh=6NPbxzP+60lU2cyx5Y9tpVIwa87KJGwCEt9OLXBVYRA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tDbAWe7H+nVyJw+3201MbRLGQcadxMBVd/NbuwksC2opU2OXFO93gwv0Q9GaC/va5is5twYydYxJU6fdsLet/4m8SbkCAajOVUIBTIvwgK60Sjq1vzxVIrsLHwIN2kRjgGlRaIYVPa43M35vvOobmfCXBJfzn4zNcbOagPyHE5M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=L0VwMwMD; arc=none smtp.client-ip=117.135.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="L0VwMwMD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=gr hLE04HdrhwK72nGwd5gy4sLrCuu7fBKaFItQ4mwrc=; b=L0VwMwMDl0N78IiXQT LmyvmBqben13QkqbkNXjr3HMF/Bqeh+2NDB3WvOttV/GCQZp7xv4v5mHCveTT7JC cJ+Gn9mSpx+d4q6QiWJBAIWwH1UR9mpx41dfGvxw/FwpgyDLw9gU8It3dcD8lC95 J62c3+sBBK/eTKD8T8N2OXVIM= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDXetTUj8tpdt0MCg--.18595S5; Tue, 31 Mar 2026 17:11:56 +0800 (CST) From: Chi Zhiling To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chi Zhiling Subject: [PATCH v1 3/6] exfat: use exfat_fat_walk helper to simplify fat entry walking Date: Tue, 31 Mar 2026 17:11:10 +0800 Message-ID: <20260331091113.20882-4-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260331091113.20882-1-chizhiling@163.com> References: <20260331091113.20882-1-chizhiling@163.com> 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 X-CM-TRANSID: _____wDXetTUj8tpdt0MCg--.18595S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxCr1xKF15JFWDGF4xCF1DGFg_yoW5AFWUpr 43Ga93tryrXa1DGF4rta1ku3WS9w4kKFW8GrWxGw18tF90yr10ka4DtryxJ34kG3y09F45 tr15Kr1UurnxGFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jl9a9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3BxoBmnLj9w0uwAA3Q Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Replace the custom exfat_walk_fat_chain() function and open-coded FAT chain walking logic with the exfat_fat_walk() helper across exfat_find_location, __exfat_get_dentry_set, and exfat_map_cluster. Signed-off-by: Chi Zhiling --- fs/exfat/dir.c | 39 +++------------------------------------ fs/exfat/inode.c | 11 ++--------- 2 files changed, 5 insertions(+), 45 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 7619410d668e..cfc6f16a5fb2 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -562,38 +562,6 @@ int exfat_put_dentry_set(struct exfat_entry_set_cache = *es, int sync) return err; } =20 -static int exfat_walk_fat_chain(struct super_block *sb, - struct exfat_chain *p_dir, unsigned int byte_offset, - unsigned int *clu) -{ - struct exfat_sb_info *sbi =3D EXFAT_SB(sb); - unsigned int clu_offset; - unsigned int cur_clu; - - clu_offset =3D EXFAT_B_TO_CLU(byte_offset, sbi); - cur_clu =3D p_dir->dir; - - if (p_dir->flags =3D=3D ALLOC_NO_FAT_CHAIN) { - cur_clu +=3D clu_offset; - } else { - while (clu_offset > 0) { - if (exfat_get_next_cluster(sb, &cur_clu)) - return -EIO; - if (cur_clu =3D=3D EXFAT_EOF_CLUSTER) { - exfat_fs_error(sb, - "invalid dentry access beyond EOF (clu : %u, eidx : %d)", - p_dir->dir, - EXFAT_B_TO_DEN(byte_offset)); - return -EIO; - } - clu_offset--; - } - } - - *clu =3D cur_clu; - return 0; -} - static int exfat_find_location(struct super_block *sb, struct exfat_chain = *p_dir, int entry, sector_t *sector, int *offset) { @@ -603,7 +571,8 @@ static int exfat_find_location(struct super_block *sb, = struct exfat_chain *p_dir =20 off =3D EXFAT_DEN_TO_B(entry); =20 - ret =3D exfat_walk_fat_chain(sb, p_dir, off, &clu); + clu =3D p_dir->dir; + ret =3D exfat_fat_walk(sb, &clu, EXFAT_B_TO_CLU(off, sbi), p_dir->flags); if (ret) return ret; =20 @@ -792,9 +761,7 @@ static int __exfat_get_dentry_set(struct exfat_entry_se= t_cache *es, if (exfat_is_last_sector_in_cluster(sbi, sec)) { unsigned int clu =3D exfat_sector_to_cluster(sbi, sec); =20 - if (p_dir->flags =3D=3D ALLOC_NO_FAT_CHAIN) - clu++; - else if (exfat_get_next_cluster(sb, &clu)) + if (exfat_fat_walk(sb, &clu, 1, p_dir->flags)) goto put_es; sec =3D exfat_cluster_to_sector(sbi, clu); } else { diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index beb9ea7cca9f..817d9a135bb6 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -225,15 +225,8 @@ static int exfat_map_cluster(struct inode *inode, unsi= gned int clu_offset, * *clu =3D (the first cluster of the allocated chain) =3D> * (the last cluster of ...) */ - if (ei->flags =3D=3D ALLOC_NO_FAT_CHAIN) { - *clu +=3D num_to_be_allocated - 1; - } else { - while (num_to_be_allocated > 1) { - if (exfat_get_next_cluster(sb, clu)) - return -EIO; - num_to_be_allocated--; - } - } + if (exfat_fat_walk(sb, clu, num_to_be_allocated - 1, ei->flags)) + return -EIO; *count =3D 1; } =20 --=20 2.43.0 From nobody Wed Apr 1 12:38:01 2026 Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) (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 ECB453ECBF3; Tue, 31 Mar 2026 09:12:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948348; cv=none; b=FmjFOiBx6udajv7OaOXhnbvcZeAv4hsls0QIBWQp3iHGdwkEzIxwPLRDINhu9Yx1idXMAmBOFYymYCrbvjUISvqSptOT0QYxgs3jTxcL77UV+qT/SmGG1wSi0QYE18+Mg8J8UgwL/4/lCG4px/j6igFWkVPgA+iunh8W6LWcPBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948348; c=relaxed/simple; bh=Hzi7QI0MjFR+00hDT1WJfqj2/XOv4/m9Z99ISdI3jp0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NCRxL8HiIeZuQJsABuZzuukBAgykf9o2UfY0Ss/ZAOc3GNqRmUSnkqJ0oyCyci+pcmag+5L8Kn7Ob/osMjeGjmApDWwYSdWmvNIVz7grCb4j6JYHIhVTtJkmtuwOVUSI6YxOc1p4K/TePG2fbI/I+qzJ/z/gl89U206eNDpL74Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=COQ4Qnd1; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="COQ4Qnd1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=n6 bPhhXb8I2/V20ZXRI8m7mImL5UZIwvzwNnhJkmkM8=; b=COQ4Qnd1rg53XZyFn9 JQ2KLXUU9Ordwc6Nv8KdeTmZCiz0gs06YUIwH0lm9Zb7MWzCkBwgkm/GBaVfL026 lfFmkQV9KybVBPuo+jXsYdA6VkhxQOUMJzF52ICI6WgJ+pfHNf/q3ryxIo1Ahtiy UoiYK9BvhhBfTswR/Li+bi6Cc= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDXetTUj8tpdt0MCg--.18595S6; Tue, 31 Mar 2026 17:11:56 +0800 (CST) From: Chi Zhiling To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chi Zhiling Subject: [PATCH v1 4/6] exfat: remove NULL cache pointer case in exfat_ent_get Date: Tue, 31 Mar 2026 17:11:11 +0800 Message-ID: <20260331091113.20882-5-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260331091113.20882-1-chizhiling@163.com> References: <20260331091113.20882-1-chizhiling@163.com> 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 X-CM-TRANSID: _____wDXetTUj8tpdt0MCg--.18595S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww4kCw43tw17trWrKr47twb_yoW8KFWDpr ZIka97tr4Ut3ZF93ZFyrs3Z3WfC397JFykGa1rCF93Ar1UtFn5XFyxtFyFyF48Ca97uFWY vF4UKF15C3srWaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2ZXOUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2xxoBmnLj9w4SAAA3o Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Since exfat_get_next_cluster has been updated, no callers pass a NULL pointer to exfat_ent_get, so remove the handling logic for this case. Signed-off-by: Chi Zhiling --- fs/exfat/fatent.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/fs/exfat/fatent.c b/fs/exfat/fatent.c index f2e5d5dde393..dce0955e689a 100644 --- a/fs/exfat/fatent.c +++ b/fs/exfat/fatent.c @@ -44,11 +44,11 @@ static int exfat_end_bh(struct super_block *sb, struct = buffer_head *bh) } =20 static int __exfat_ent_get(struct super_block *sb, unsigned int loc, - unsigned int *content, struct buffer_head **last) + unsigned int *content, struct buffer_head **cache) { unsigned int off; sector_t sec; - struct buffer_head *bh =3D last ? *last : NULL; + struct buffer_head *bh =3D *cache; =20 sec =3D FAT_ENT_OFFSET_SECTOR(sb, loc); off =3D FAT_ENT_OFFSET_BYTE_IN_SECTOR(sb, loc); @@ -56,8 +56,7 @@ static int __exfat_ent_get(struct super_block *sb, unsign= ed int loc, if (!bh || bh->b_blocknr !=3D sec || !buffer_uptodate(bh)) { brelse(bh); bh =3D sb_bread(sb, sec); - if (last) - *last =3D bh; + *cache =3D bh; if (unlikely(!bh)) return -EIO; } @@ -68,8 +67,6 @@ static int __exfat_ent_get(struct super_block *sb, unsign= ed int loc, if (*content > EXFAT_BAD_CLUSTER) *content =3D EXFAT_EOF_CLUSTER; =20 - if (!last) - brelse(bh); return 0; } =20 @@ -111,7 +108,7 @@ int exfat_ent_set(struct super_block *sb, unsigned int = loc, * Caller must release the buffer_head if no error return. */ int exfat_ent_get(struct super_block *sb, unsigned int loc, - unsigned int *content, struct buffer_head **last) + unsigned int *content, struct buffer_head **cache) { struct exfat_sb_info *sbi =3D EXFAT_SB(sb); =20 @@ -122,7 +119,7 @@ int exfat_ent_get(struct super_block *sb, unsigned int = loc, goto err; } =20 - if (unlikely(__exfat_ent_get(sb, loc, content, last))) { + if (unlikely(__exfat_ent_get(sb, loc, content, cache))) { exfat_fs_error_ratelimit(sb, "failed to access to FAT (entry 0x%08x)", loc); @@ -151,13 +148,11 @@ int exfat_ent_get(struct super_block *sb, unsigned in= t loc, } =20 return 0; -err: - if (last) { - brelse(*last); =20 - /* Avoid double release */ - *last =3D NULL; - } +err: + /* Avoid double release */ + brelse(*cache); + *cache =3D NULL; return -EIO; } =20 --=20 2.43.0 From nobody Wed Apr 1 12:38:01 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (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 775D33D4114; Tue, 31 Mar 2026 09:12:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948348; cv=none; b=Zd+8n5A3VJv9eIuKCqn7nwYHuwQ4OD0rlwWihyFtrUYilnWpxjFjJwLu04Vez1CQYcuSZjP6kTSrCvY+EyEAF+vcM0wIeZ49LaCMIXlINCax9thylkXEB69kQbXMKSKfynzNcRjRKuU7LfRQzHQOh7Vk/2DhFqYu71cJP31jycE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948348; c=relaxed/simple; bh=QKKo27ZmgmLu5jnNNTZnZdUMEXscxJeDRMykZoctq/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hmkdFKCoxdCzRvuDllT+/G+UxaCRaN6JW9ht+VN44KQjv9ayZDnbljVN/k7j0x4JKJaTsFy5rD0CTzmMVBMr5wYR0aKhy5gw4dFt8wmnvvj0tP8Z9OcNefiuw4ZLc9KCJX7rgtZP2dWKR8xWbCLYMTSVmtGNPyPkIZWeWvQ2ToE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=BQPIOPkO; arc=none smtp.client-ip=117.135.210.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="BQPIOPkO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=FP +Ida2roPJagNqHaJVzBkQt9/HGb12AMTnzKtErRe0=; b=BQPIOPkOGDgul6YY9k EGvziHdRQ9x7CNPNGVWoHUb7X/zw1PmREyfVAQVqNh2OvenThmjBYiB4Qzz4eWXA VJsxCksL9ED4Sv7+SNXi5gS4Q0dzQ7qg7uz9YjU1Lk7pLqvymPjAhIt3jdP9b01B Ct/8Ap82nh2rHBEk8mrkv3uC4= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDXetTUj8tpdt0MCg--.18595S7; Tue, 31 Mar 2026 17:11:56 +0800 (CST) From: Chi Zhiling To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chi Zhiling Subject: [PATCH v1 5/6] exfat: introduce exfat_chain_advance helper Date: Tue, 31 Mar 2026 17:11:12 +0800 Message-ID: <20260331091113.20882-6-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260331091113.20882-1-chizhiling@163.com> References: <20260331091113.20882-1-chizhiling@163.com> 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 X-CM-TRANSID: _____wDXetTUj8tpdt0MCg--.18595S7 X-Coremail-Antispam: 1Uf129KBjvJXoW7WryxXw1Duw17JryxtrW5KFg_yoW8XF47pF 47Gw45J3ykXayfu3WfJw4rXa4Y9rs2gFW8JrWxAw1Yyrn0qrn5uFyrK347tFyrJ348K3W2 vwn0gr1YgrsxGF7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07URVb9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC9xxoBmnLj9zKaAAA3W Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Introduce exfat_chain_advance() to walk a exfat_chain structure by a given step, updating both ->dir and ->size fields atomically. This helper handles both ALLOC_NO_FAT_CHAIN and ALLOC_FAT_CHAIN modes with proper boundary checking. Signed-off-by: Chi Zhiling --- fs/exfat/exfat_fs.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 530459ab9acc..d7f88a326cf0 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -552,6 +552,32 @@ int exfat_read_volume_label(struct super_block *sb, int exfat_write_volume_label(struct super_block *sb, struct exfat_uni_name *label); =20 +static inline int exfat_chain_advance(struct super_block *sb, + struct exfat_chain *chain, unsigned int step) +{ + if (chain->flags =3D=3D ALLOC_NO_FAT_CHAIN) { + if (chain->size > step) { + chain->dir +=3D step; + chain->size -=3D step; + } else if (chain->size =3D=3D step) { + chain->dir =3D EXFAT_EOF_CLUSTER; + chain->size =3D 0; + } else { + return -EIO; + } + } else { + if (exfat_fat_walk(sb, &chain->dir, step, ALLOC_FAT_CHAIN)) + return -EIO; + if (chain->size > step) { + chain->size -=3D step; + } else { + chain->size =3D 0; + WARN_ON_ONCE(chain->dir !=3D EXFAT_EOF_CLUSTER); + } + } + return 0; +} + /* inode.c */ extern const struct inode_operations exfat_file_inode_operations; void exfat_sync_inode(struct inode *inode); --=20 2.43.0 From nobody Wed Apr 1 12:38:01 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.2]) (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 822B43E557F; Tue, 31 Mar 2026 09:12:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.2 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948346; cv=none; b=c5s/MPG9dhA2qNFbU4RwFhM/4sGStv2JC6CTApDlxHlVDBScLsqLqkTmyWixfhj9wHsZbazN87LzaWsuRgPpyHDV4lBaGx4ydl/N/nxMuC14siWBHp98mXC2LcvMuYzs/Pai8SLz0TBvcA68SHJdp79Ejd1oQxakrqYKQMx3e9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774948346; c=relaxed/simple; bh=wY4RepqqA0PUj9D9ra1ftFhqkd/133OqL5vLBXSP0Gc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AYPQ577TVgyW76TBB+kVpDD99guX4Ves+HnuorPeQLSKeeI0HcaAtXQc/WHgU0htuEAsXZlHrkBMSyH5fGCYDK0rOChZEhkocweYD7KuWNel02C0WfY4Q9XTuIIPyA/KmjmJnxRwb/NQj+FogdVfZe/qsHq9B5J5XythF9GGIwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=ixOeoKgF; arc=none smtp.client-ip=117.135.210.2 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="ixOeoKgF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=1b 14gpqkQaUFHH+X4hvQ18dL25nM1Ljqk9oIiQg+64c=; b=ixOeoKgF3vT5n2/YOJ H7PgYsBGHnHa6r+x28hvrFOD3ltekAI93hx9kXAABw8lvIbYk7lR1FR+rxrKL3JB Zg9X5oXt2f8faAKyxCFZkKTH1jzTnxzwAz+cGHsS3VDlqWkS91nmhbP7AyM10Wiq dcgP4ZgdQiiNizkWZeZllllas= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wDXetTUj8tpdt0MCg--.18595S8; Tue, 31 Mar 2026 17:11:56 +0800 (CST) From: Chi Zhiling To: Namjae Jeon , Sungjong Seo , Yuezhang Mo Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chi Zhiling Subject: [PATCH v1 6/6] exfat: use exfat_chain_advance helper Date: Tue, 31 Mar 2026 17:11:13 +0800 Message-ID: <20260331091113.20882-7-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260331091113.20882-1-chizhiling@163.com> References: <20260331091113.20882-1-chizhiling@163.com> 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 X-CM-TRANSID: _____wDXetTUj8tpdt0MCg--.18595S8 X-Coremail-Antispam: 1Uf129KBjvJXoWxCry8CrWrZw47Wr47CFyxGrg_yoW7Jr1fpF 47Ga93JFyDJayqk3W8t3ZrZa4a9ws3GFyUXFn7uw1F9rZFyr15C3s2krySqF95C3yrZw12 qw15tr1jgFsxWFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07URq2iUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2x1oBmnLj904UAAA3w Content-Type: text/plain; charset="utf-8" From: Chi Zhiling Replace open-coded cluster chain walking logic with exfat_chain_advance() across exfat_readdir, exfat_find_dir_entry, exfat_count_dir_entries, exfat_search_empty_slot and exfat_check_dir_empty. Signed-off-by: Chi Zhiling --- fs/exfat/dir.c | 71 ++++++++++++------------------------------------ fs/exfat/namei.c | 29 +++++--------------- 2 files changed, 25 insertions(+), 75 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index cfc6f16a5fb2..adc79694373a 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -93,25 +93,19 @@ static int exfat_readdir(struct inode *inode, loff_t *c= pos, struct exfat_dir_ent clu_offset =3D EXFAT_DEN_TO_CLU(dentry, sbi); exfat_chain_dup(&clu, &dir); =20 - if (clu.flags =3D=3D ALLOC_NO_FAT_CHAIN) { - clu.dir +=3D clu_offset; - clu.size -=3D clu_offset; - } else { + if (clu.flags =3D=3D ALLOC_FAT_CHAIN) { /* hint_information */ if (clu_offset > 0 && ei->hint_bmap.off !=3D EXFAT_EOF_CLUSTER && ei->hint_bmap.off > 0 && clu_offset >=3D ei->hint_bmap.off) { clu_offset -=3D ei->hint_bmap.off; clu.dir =3D ei->hint_bmap.clu; - } - - while (clu_offset > 0 && clu.dir !=3D EXFAT_EOF_CLUSTER) { - if (exfat_get_next_cluster(sb, &(clu.dir))) - return -EIO; - - clu_offset--; + clu.size -=3D ei->hint_bmap.off; } } =20 + if (exfat_chain_advance(sb, &clu, clu_offset)) + return -EIO; + while (clu.dir !=3D EXFAT_EOF_CLUSTER && dentry < max_dentries) { i =3D dentry & (dentries_per_clu - 1); =20 @@ -160,15 +154,8 @@ static int exfat_readdir(struct inode *inode, loff_t *= cpos, struct exfat_dir_ent return 0; } =20 - if (clu.flags =3D=3D ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir =3D EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &(clu.dir))) - return -EIO; - } + if (exfat_chain_advance(sb, &clu, 1)) + return -EIO; } =20 out: @@ -1077,19 +1064,12 @@ int exfat_find_dir_entry(struct super_block *sb, st= ruct exfat_inode_info *ei, step =3D DIRENT_STEP_FILE; } =20 - if (clu.flags =3D=3D ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir =3D EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &clu.dir)) - return -EIO; + if (exfat_chain_advance(sb, &clu, 1)) + return -EIO; + /* break if the cluster chain includes a loop */ + if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) + goto not_found; =20 - /* break if the cluster chain includes a loop */ - if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) - goto not_found; - } } =20 not_found: @@ -1124,14 +1104,7 @@ int exfat_find_dir_entry(struct super_block *sb, str= uct exfat_inode_info *ei, if (!((dentry + 1) & (dentries_per_clu - 1))) { int ret =3D 0; =20 - if (clu.flags =3D=3D ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir =3D EXFAT_EOF_CLUSTER; - } else { - ret =3D exfat_get_next_cluster(sb, &clu.dir); - } + ret =3D exfat_chain_advance(sb, &clu, 1); =20 if (ret || clu.dir =3D=3D EXFAT_EOF_CLUSTER) { /* just initialized hint_stat */ @@ -1176,20 +1149,12 @@ int exfat_count_dir_entries(struct super_block *sb,= struct exfat_chain *p_dir) count++; } =20 - if (clu.flags =3D=3D ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir =3D EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &(clu.dir))) - return -EIO; - - if (unlikely(++clu_count > sbi->used_clusters)) { - exfat_fs_error(sb, "FAT or bitmap is corrupted"); - return -EIO; - } + if (exfat_chain_advance(sb, &clu, 1)) + return -EIO; =20 + if (unlikely(++clu_count > sbi->used_clusters)) { + exfat_fs_error(sb, "FAT or bitmap is corrupted"); + return -EIO; } } =20 diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index ef2a3488c1b3..e0d1c3bf5555 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -246,16 +246,8 @@ static int exfat_search_empty_slot(struct super_block = *sb, i +=3D ret; =20 while (i >=3D dentries_per_clu) { - if (clu.flags =3D=3D ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir =3D EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &clu.dir)) - return -EIO; - } - + if (exfat_chain_advance(sb, &clu, 1)) + return -EIO; i -=3D dentries_per_clu; } } @@ -924,19 +916,12 @@ static int exfat_check_dir_empty(struct super_block *= sb, return -ENOTEMPTY; } =20 - if (clu.flags =3D=3D ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir =3D EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &(clu.dir))) - return -EIO; + if (exfat_chain_advance(sb, &clu, 1)) + return -EIO; =20 - /* break if the cluster chain includes a loop */ - if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) - break; - } + /* break if the cluster chain includes a loop */ + if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) + break; } =20 return 0; --=20 2.43.0