From nobody Wed Apr 1 12:36:57 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 9091B37266E; Wed, 1 Apr 2026 07:12:26 +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=1775027549; cv=none; b=Qx3/qRDacpT1XFPRMsCvtm+8rbp6MPrn4yzOc8iJzbXYjxbBYXFAc7Y9NogIA7qkvQ4+U7O/U48t0g/SqLJDtew6unwrsO46fKA/tgC6XBfnzhzRf8uPAAAEbRTwoPjQoac25GEgbU4iApRWGr2gcbjlWT/0qFf4wnKpuH1Dh+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775027549; c=relaxed/simple; bh=F/CDL8VyW0CX692DhFTu9Yr6yXj1cBGRo9UaLvxTghQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VGdc82jEHEfyXBs0kMnWTc2X3DRhT8yo2SFNjyZf+dz0/etXXfRHoVOis0cay2n/f+RfOOseS7TqiH3A2Wwo5GRZpdRnz2sxGIxaVHsAStEgtTARQlddbFqWT5rOcKMPOXqgIsR9EdfLUu3MqPUgl8FUquVjaAilnvkYF4tnrn0= 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=mfjmGBBE; 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="mfjmGBBE" 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=mfjmGBBEQNwFwetpK6 R/16LDt3h8x59yODv5mXIlM8EKu7txpgiD/FLzvsF9EwQa6kS16Yi0DswMT273+l yplGfDLJIaOYN2LbqTP04NiH8WK1HVPNl0Yl877Aiu56FzHtHduKdkU05wjqssmB gHi6PoIdbvWCW6TTgkwACtPeA= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3v9ZFxcxpADvDCg--.24371S3; Wed, 01 Apr 2026 15:12:08 +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 v2 1/6] exfat: fix incorrect directory checksum after rename to shorter name Date: Wed, 1 Apr 2026 15:11:33 +0800 Message-ID: <20260401071138.114836-2-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260401071138.114836-1-chizhiling@163.com> References: <20260401071138.114836-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: _____wD3v9ZFxcxpADvDCg--.24371S3 X-Coremail-Antispam: 1Uf129KBjvdXoW7Xr1DKF15uF15Ww13CF47twb_yoWkurX_ua yrtr1DKryYyFn8JwsxKF1rGr1Sga18ur15JrnYvFnxWas3tF9xXw1DCrnFv3W7tw4rKr98 CrykWr1qka1rtjkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IU8EtC7UUUUU== X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2wgRrmnMxUg0fAAA3M 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:36:57 2026 Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.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 8A7E036998C; Wed, 1 Apr 2026 07:12:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775027554; cv=none; b=QPg2MHOPa7yah2YuYfXCRWWXI3ZeoyjykB5o3fwVujL9M0mR2y/XKAU0wX6ym2D9gd+z5rIelZw7PIexdGd2+oKdkY3fdajcZmQTFZ0CmXSiYqTF5RcUjDoi8t/DhoZNs9SxnAG0J6sEEI6wWG7MMVghXSPPdYCSldpHcbj0yAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775027554; c=relaxed/simple; bh=m6L1EZDojc4EimSxu0sg9rOKnRQPzE6DXm5qmVqC7mg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=McXQKO9QWd7cHvv4CgY0a48X6ULBLVwl/DgiCDMhRMarnsBciI004hu2tU5u7TrBdAy7OIANSXx83NbMOYJkz1Qeu//DU/0yNcj29QHed6zIAUXa4c10+nHXpopBNqVi3pI+5kby8aocQRhuqA8lzC9Nz/cBfqfCrOLPi/T9RIc= 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=eAqIS25V; arc=none smtp.client-ip=117.135.210.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="eAqIS25V" 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=eAqIS25V3mGTASEaw2 4K77mLBkz2jkM5iWHjmW1Y+h1NgqoU99uiU2FrNLjd9K2h0Ef7/bt1s0at852efR /2TsyVSwzlZiDHG8qF4BwdWyRbKtRZLjDqTIcjjeh/ACG+PGf0Y9ZwyNZ7HjUL0Q SrhUrNoBkGNWX+XaYZh1WVNPk= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3v9ZFxcxpADvDCg--.24371S4; Wed, 01 Apr 2026 15:12:08 +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 v2 2/6] exfat: introduce exfat_fat_walk helper Date: Wed, 1 Apr 2026 15:11:34 +0800 Message-ID: <20260401071138.114836-3-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260401071138.114836-1-chizhiling@163.com> References: <20260401071138.114836-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: _____wD3v9ZFxcxpADvDCg--.24371S4 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cr4xZrW8ArW5JF1fGry8Krg_yoW8ArW8pF 4UGw4rJrW5Wa47u3W3JFs3u3Wa9ws7GFyDArWxu3s0yrWDtF95uF98KryayF1Iqw40g3W5 KF1Ygr18urnxGrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jwGYLUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3AgRrmnMxUgw9gAA3F 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:36:57 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 D0E3436897B; Wed, 1 Apr 2026 07:12:26 +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=1775027550; cv=none; b=o1psUD7KN9xDWChVspNzyLJZidE2P1S98pUVqtUSD4o+2kMuRzDvbMhy01PbHHhO+eDACoYzG7UKAivPBOkeNa/6ABjutOgFIOL/LkDK50Xu7enKVz2oWMys90r7uIhgnvkQZxYgDs3uSUUmzHjk17nbtE8UhUTbzYIon19zXD0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775027550; c=relaxed/simple; bh=6NPbxzP+60lU2cyx5Y9tpVIwa87KJGwCEt9OLXBVYRA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DMC+tiJkBavsH0K/V+o8+VUdOaW3V3HyO133CxZ47xOOOvW+/YpnaDKrW/oHLeqbKBydyb9jcUtLU74EA+cjP25yJb/UsU7AhhCetC/U0/2Tww3Xx/l5KRx9HcGhyKtT5MisK49uxSFYb7/2qJZohiiiIwes2FrgaPa1YsR0a48= 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=CjumoghS; 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="CjumoghS" 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=CjumoghSOwz0FVkoZZ rWVzExXkE678IF4hObcGn1RZJFjK5B4ji0aefafPj6j/VETYZ6EUBJBb8HfocMaS n/gF8zCLDayoWzxTLrewNEV/dVWI1o3ZTDNCg271sAOmYvKbVC/OYFJTWlQYOsPx T4KDM6WJ/LQ1/m40OMfnyS/0U= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3v9ZFxcxpADvDCg--.24371S5; Wed, 01 Apr 2026 15:12:08 +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 v2 3/6] exfat: use exfat_fat_walk helper to simplify fat entry walking Date: Wed, 1 Apr 2026 15:11:35 +0800 Message-ID: <20260401071138.114836-4-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260401071138.114836-1-chizhiling@163.com> References: <20260401071138.114836-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: _____wD3v9ZFxcxpADvDCg--.24371S5 X-Coremail-Antispam: 1Uf129KBjvJXoWxCr1xKF15JFWDGF4xCF1DGFg_yoW5AFWUpr 43Ga93tryrXa1DGF4rta1ku3WS9w4kKFW8GrWxGw18tF90yr10ka4DtryxJ34kG3y09F45 tr15Kr1UurnxGFDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jl9a9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC+AgRrmnMxUgGIwAA3C 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:36:57 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 D1E803783CA; Wed, 1 Apr 2026 07:12:30 +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=1775027553; cv=none; b=FpU+NOjFa2EmeaUYogM73teYkKG/iqr/esEZGmpCxKU1eVf4podlJAIBVRMYDTb9gCRsgUO6YLgF4Ik3k0SnA21zuNhKAWgCIXgBpOMNYIORnVX1Mchlc+m2a0n4adFOUmkHIglrlgt2hl6PFhPEIghKFMSBCSwDLWgdOtDPXS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775027553; c=relaxed/simple; bh=Hzi7QI0MjFR+00hDT1WJfqj2/XOv4/m9Z99ISdI3jp0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D0TeUaUd+fGND6YJn1lx3Mx0lW7r/SGPRQtDSV9YUvjCVrswXB+7y3SdmVUkS9A4TA6gruoiqJdvp/vmjhBhMaIbVlK6ZjHFJZ2Cx1Wl/pCSuhfffVPH0tXJ19Em9mvFbnh6jvxyiKhYhRHgvP6dSf074F1E5WpD/eAXOBN7vEw= 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=ACv8gSvs; 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="ACv8gSvs" 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=ACv8gSvsOBot1r+iaE 4/sIzoHEfPjvcrsWYffgejYB/s6x2y7cWYIZXY9nTHFiw7RfFjaIQznhJakvo27B mLFNq0RB/f2+AR1dFeOSr+Mqonxzbfh22A4s3gqH654K+avPBJ1vLZzvP3fabs/F y5D746wpHiQS2nYv71lwv+MEE= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3v9ZFxcxpADvDCg--.24371S6; Wed, 01 Apr 2026 15:12:08 +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 v2 4/6] exfat: remove NULL cache pointer case in exfat_ent_get Date: Wed, 1 Apr 2026 15:11:36 +0800 Message-ID: <20260401071138.114836-5-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260401071138.114836-1-chizhiling@163.com> References: <20260401071138.114836-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: _____wD3v9ZFxcxpADvDCg--.24371S6 X-Coremail-Antispam: 1Uf129KBjvJXoW7Ww4kCw43tw17trWrKr47twb_yoW8KFWDpr ZIka97tr4Ut3ZF93ZFyrs3Z3WfC397JFykGa1rCF93Ar1UtFn5XFyxtFyFyF48Ca97uFWY vF4UKF15C3srWaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07j2ZXOUUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2wgRrmnMxUg0igAA36 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:36:57 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 812DE366DA5; Wed, 1 Apr 2026 07:12:51 +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=1775027573; cv=none; b=EMIjB1LSWSeEL1zgaj1WrtLmORQGXtHcYHF91GVMxZf9OHaGM7vgv6mYLoVo5QS4TeSs/BWzkvYfAWKP9YWTlW09AbRFfjyroAwm5zRi5o780qHVkIbn/tHQcpHyRkA3sNU2dRLmqKhyjU88nkQafnudinzTMR6MO90lS9DZgA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775027573; c=relaxed/simple; bh=yhxzjwKwSBaUZ4FGxUPes9C3AlHWL6XJeneeeIBMtkM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bvEWPmMp6nFYhHy00IvZIdipm8xhKDoZKnnxSuHAtaZpD/arrL+NS8VIP385XHSkmwUr/JavlTrK2U5huVCoaPVoSvEk19GWpXIId+wHJ1+f2ghwtuslonbJS9JbphvD0OVEIVRbvv9ltC1C4WnFF2Psfpu4e5Bcb39yyXOMjxA= 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=g2XLFOOQ; 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="g2XLFOOQ" 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=KD I8bPw2++XDAb25MPconhLJtAP5fqOp0wl4eaVRJMA=; b=g2XLFOOQ/GWAKgzKw1 DVXSgk1+GO+w6iRThg7TQnQpnIWssVyE7fkYO/IY7ldZzlf+DgTksZpM9TOxa9dI va2LbGExgQu3NXbFtB31Rnh8lSxLGX9KJtbI2sZgdNRS/v4PfKg43PdrY5br0J8V l25aWfFN4e6Kw9/k2ddx2odhM= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3v9ZFxcxpADvDCg--.24371S7; Wed, 01 Apr 2026 15:12:09 +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 , syzbot@syzkaller.appspotmail.com Subject: [PATCH v2 5/6] exfat: introduce exfat_chain_advance helper Date: Wed, 1 Apr 2026 15:11:37 +0800 Message-ID: <20260401071138.114836-6-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260401071138.114836-1-chizhiling@163.com> References: <20260401071138.114836-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: _____wD3v9ZFxcxpADvDCg--.24371S7 X-Coremail-Antispam: 1Uf129KBjvJXoW7WryxXw1Duw1rKw1ftr1kXwb_yoW8Gr4DpF 47Ga15J3yjqayxuw1xJr4rXa4Y9ws7WFWkJrWxAw1Yyrn0qryvkF93Kry29Fyrtw18K3W2 va1Ygr1Y9rsxGFJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07URVb9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC2wkRrmnMxUk0jgAA3+ 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 Tested-by: syzbot@syzkaller.appspotmail.com --- fs/exfat/exfat_fs.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 530459ab9acc..1035d20ba563 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -552,6 +552,23 @@ 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->size >=3D step) + chain->size -=3D step; + else + return -EIO; + + if (exfat_fat_walk(sb, &chain->dir, step, chain->flags)) + return -EIO; + + if (chain->size =3D=3D 0 && chain->flags =3D=3D ALLOC_NO_FAT_CHAIN) + 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:36:57 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 3CF8C36DA0C; Wed, 1 Apr 2026 07: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=1775027549; cv=none; b=THs7+/ipPf3RJAWzLL7V66wAcgD837ID6AgnJtM2SNIonp9OGgooKHznnslnl6cNuAe2sjzON8vjIBA38SFzF9kMmc6SWZCEkgFY5qYA+GfkryIpr3hGc+zZXtzrjPRCjyYcLO4aDQJCvYwF6L5lP9Yiz3GASj3LJH3A1hz1aeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775027549; c=relaxed/simple; bh=eVNUxa7INIuzj8OSRHfOVYly/ZwXZqKX6kqeP6jbj2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WYezVNcjHhUnQTcfn+94KRkLN7MBzrWxL5kkBcWBtW5FrB0zCHDupiT8TKQgtMdmRIGKS8M5KXjSgZj0Wt5oARsYumOMNQlW/skGvbd/mD28Kg9enHarKJ2odmuImH745xSbZsYXgn9bi7w3prVGrxKqySa3WVM7ceDJxRyT1oQ= 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=OBi/WuuL; 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="OBi/WuuL" 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=bU sg27IFwodV4q9K5Fu+1D7KJPY2kHNPIDLSG0qHrnY=; b=OBi/WuuLJCnAooYlzB hl1aKwwLi9fGeq6FzeDva4GbpxnwQXdnPRh5iGUYA6sO76kmRtWHn/Lq1/GgLGkD p8oOY2V7gIt0PwvASba8oiLhWZ7JB+oFb2co93ht+CZqJJiRjUtKO2RzqHktDorN KyljL9L1x0bDlBo2GXz0wCwbo= Received: from czl-ubuntu-pc.. (unknown []) by gzga-smtp-mtada-g1-4 (Coremail) with SMTP id _____wD3v9ZFxcxpADvDCg--.24371S8; Wed, 01 Apr 2026 15:12:09 +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 v2 6/6] exfat: use exfat_chain_advance helper Date: Wed, 1 Apr 2026 15:11:38 +0800 Message-ID: <20260401071138.114836-7-chizhiling@163.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260401071138.114836-1-chizhiling@163.com> References: <20260401071138.114836-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: _____wD3v9ZFxcxpADvDCg--.24371S8 X-Coremail-Antispam: 1Uf129KBjvJXoWxCry8CrWrZw47Wr47CFyxGrg_yoW7Jr1fpF 47Ga93JFyDJayqk3W8t3ZrZa4Y9ws3GFyUXFn7Cw1F9rZFyr15C3s2krySqF95C3yruw12 q3W5tr1jgFsxWFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07URVb9UUUUU= X-CM-SenderInfo: hfkl6xxlol0wi6rwjhhfrp/xtbC3AkRrmnMxUkxEAAA3i 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 d0ea1ff81c09..7cfec2adc365 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; } } @@ -925,19 +917,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