[PATCH v2] erofs: simplify the code using for_each_set_bit

Gao Xiang hsiangkao at linux.alibaba.com
Thu Dec 18 14:02:52 AEDT 2025



On 2025/12/18 10:57, Yuwen Chen wrote:
> 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 at foxmail.com>
> ---
> 
> v1 -> v2:
>      - revert the modifications to the fs/erofs/internal.h
> 
>   fs/erofs/decompressor.c | 11 ++++-------
>   1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
> index 2ec9b2bb628d6..be1e19b620523 100644
> --- a/fs/erofs/decompressor.c
> +++ b/fs/erofs/decompressor.c
> @@ -405,7 +405,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;
>   
> @@ -423,13 +423,10 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
>   
>   	erofs_init_metabuf(&buf, sb);
>   	offset = EROFS_SUPER_OFFSET + sbi->sb_size;
> -	alg = 0;
> -	for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) {
> +	algs = sbi->available_compr_algs;

Can you update as what I suggested?

Assign `algs` first, and then assign sbi->available_compr_algs.

Thanks,
Gao Xiang


More information about the Linux-erofs mailing list