]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
erofs: simplify the code using for_each_set_bit
authorYuwen Chen <ywen.chen@foxmail.com>
Thu, 18 Dec 2025 04:19:52 +0000 (12:19 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 22 Jan 2026 16:00:36 +0000 (00:00 +0800)
When mounting the EROFS file system, it is necessary to check the
available compression algorithms. At this time, the for_each_set_bit
function can be used to simplify the code logic.

Signed-off-by: Yuwen Chen <ywen.chen@foxmail.com>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fs/erofs/decompressor.c

index d5d0902763917b447186bc5a0b18727510559c0a..15b464a589939d46769d405774e554931612740b 100644 (file)
@@ -452,7 +452,7 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
 {
        struct erofs_sb_info *sbi = EROFS_SB(sb);
        struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
-       unsigned int algs, alg;
+       unsigned long algs, alg;
        erofs_off_t offset;
        int size, ret = 0;
 
@@ -461,33 +461,30 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
                return z_erofs_load_lz4_config(sb, dsb, NULL, 0);
        }
 
-       sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs);
-       if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) {
-               erofs_err(sb, "unidentified algorithms %x, please upgrade kernel",
-                         sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS);
+       algs = le16_to_cpu(dsb->u1.available_compr_algs);
+       sbi->available_compr_algs = algs;
+       if (algs & ~Z_EROFS_ALL_COMPR_ALGS) {
+               erofs_err(sb, "unidentified algorithms %lx, please upgrade kernel",
+                         algs & ~Z_EROFS_ALL_COMPR_ALGS);
                return -EOPNOTSUPP;
        }
 
        (void)erofs_init_metabuf(&buf, sb, false);
        offset = EROFS_SUPER_OFFSET + sbi->sb_size;
-       alg = 0;
-       for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) {
+       for_each_set_bit(alg, &algs, Z_EROFS_COMPRESSION_MAX) {
                const struct z_erofs_decompressor *dec = z_erofs_decomp[alg];
                void *data;
 
-               if (!(algs & 1))
-                       continue;
-
                data = erofs_read_metadata(sb, &buf, &offset, &size);
                if (IS_ERR(data)) {
                        ret = PTR_ERR(data);
                        break;
                }
 
-               if (alg < Z_EROFS_COMPRESSION_MAX && dec && dec->config) {
+               if (dec && dec->config) {
                        ret = dec->config(sb, dsb, data, size);
                } else {
-                       erofs_err(sb, "algorithm %d isn't enabled on this kernel",
+                       erofs_err(sb, "algorithm %ld isn't enabled on this kernel",
                                  alg);
                        ret = -EOPNOTSUPP;
                }