]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
exfat: use exfat_chain_advance helper
authorChi Zhiling <chizhiling@kylinos.cn>
Fri, 3 Apr 2026 08:05:38 +0000 (16:05 +0800)
committerNamjae Jeon <linkinjeon@kernel.org>
Fri, 3 Apr 2026 13:41:10 +0000 (22:41 +0900)
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 <chizhiling@kylinos.cn>
Reviewed-by: Sungjong Seo <sj1557.seo@samsung.com>
Reviewed-by: Yuezhang Mo <Yuezhang.Mo@sony.com>
Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
fs/exfat/dir.c
fs/exfat/namei.c

index ca5827046a1f90bbd126a1097c681d2326eca3aa..ac008ccaa97de7b4507eaf9e0ee474b10ed88953 100644 (file)
@@ -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;
                }
        }
 
index d0ea1ff81c090206755d47210bde296b48963399..2c5636634b4a4ebd819e4df45872927f99a65e1e 100644 (file)
@@ -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;