From: Chi Zhiling Date: Fri, 3 Apr 2026 08:05:38 +0000 (+0800) Subject: exfat: use exfat_chain_advance helper X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08cf4a8181b4378a0a50ea370391f30032c4e4ec;p=thirdparty%2Fkernel%2Flinux.git exfat: use exfat_chain_advance helper 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 Reviewed-by: Sungjong Seo Reviewed-by: Yuezhang Mo Signed-off-by: Namjae Jeon --- diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index ca5827046a1f9..ac008ccaa97de 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -93,25 +93,19 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent clu_offset = EXFAT_DEN_TO_CLU(dentry, sbi); exfat_chain_dup(&clu, &dir); - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - clu.dir += clu_offset; - clu.size -= clu_offset; - } else { + if (clu.flags == ALLOC_FAT_CHAIN) { /* hint_information */ if (clu_offset > 0 && ei->hint_bmap.off != EXFAT_EOF_CLUSTER && ei->hint_bmap.off > 0 && clu_offset >= ei->hint_bmap.off) { clu_offset -= ei->hint_bmap.off; clu.dir = ei->hint_bmap.clu; - } - - while (clu_offset > 0 && clu.dir != EXFAT_EOF_CLUSTER) { - if (exfat_get_next_cluster(sb, &(clu.dir))) - return -EIO; - - clu_offset--; + clu.size -= ei->hint_bmap.off; } } + if (exfat_chain_advance(sb, &clu, clu_offset)) + return -EIO; + while (clu.dir != EXFAT_EOF_CLUSTER && dentry < max_dentries) { i = dentry & (dentries_per_clu - 1); @@ -160,15 +154,8 @@ static int exfat_readdir(struct inode *inode, loff_t *cpos, struct exfat_dir_ent return 0; } - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &(clu.dir))) - return -EIO; - } + if (exfat_chain_advance(sb, &clu, 1)) + return -EIO; } out: @@ -1085,19 +1072,12 @@ rewind: step = DIRENT_STEP_FILE; } - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = 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; - } + /* break if the cluster chain includes a loop */ + if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) + goto not_found; } not_found: @@ -1132,14 +1112,7 @@ found: if (!((dentry + 1) & (dentries_per_clu - 1))) { int ret = 0; - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = EXFAT_EOF_CLUSTER; - } else { - ret = exfat_get_next_cluster(sb, &clu.dir); - } + ret = exfat_chain_advance(sb, &clu, 1); if (ret || clu.dir == EXFAT_EOF_CLUSTER) { /* just initialized hint_stat */ @@ -1184,20 +1157,12 @@ int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir) count++; } - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = 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; + if (unlikely(++clu_count > sbi->used_clusters)) { + exfat_fs_error(sb, "FAT or bitmap is corrupted"); + return -EIO; } } diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index d0ea1ff81c090..2c5636634b4a4 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -246,15 +246,8 @@ static int exfat_search_empty_slot(struct super_block *sb, i += ret; while (i >= dentries_per_clu) { - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &clu.dir)) - return -EIO; - } + if (exfat_chain_advance(sb, &clu, 1)) + return -EIO; i -= dentries_per_clu; } @@ -925,19 +918,12 @@ static int exfat_check_dir_empty(struct super_block *sb, return -ENOTEMPTY; } - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = 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))) - break; - } + /* break if the cluster chain includes a loop */ + if (unlikely(++clu_count > EXFAT_DATA_CLUSTER_COUNT(sbi))) + break; } return 0;