mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] erofs: simplify the code using for_each_set_bit
@ 2025-12-18  4:19 Yuwen Chen
  2025-12-18  9:20 ` Gao Xiang
  2026-01-21  5:27 ` Chao Yu
  0 siblings, 2 replies; 3+ messages in thread
From: Yuwen Chen @ 2025-12-18  4:19 UTC (permalink / raw)
  To: xiang; +Cc: chao, huyue2, jefflexu, linux-erofs, linux-kernel, Yuwen Chen

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>
---

v2 -> v3:
    - rebase the patch
    - remove the unnecessary judgment logic

v1 -> v2:
    - revert the modifications to the fs/erofs/internal.h

 fs/erofs/decompressor.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/fs/erofs/decompressor.c b/fs/erofs/decompressor.c
index d5d0902763917..15b464a589939 100644
--- a/fs/erofs/decompressor.c
+++ b/fs/erofs/decompressor.c
@@ -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;
 		}
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] erofs: simplify the code using for_each_set_bit
  2025-12-18  4:19 [PATCH v3] erofs: simplify the code using for_each_set_bit Yuwen Chen
@ 2025-12-18  9:20 ` Gao Xiang
  2026-01-21  5:27 ` Chao Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2025-12-18  9:20 UTC (permalink / raw)
  To: Yuwen Chen, xiang; +Cc: chao, huyue2, jefflexu, linux-erofs, linux-kernel



On 2025/12/18 12:19, 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@foxmail.com>
> ---
> 
> v2 -> v3:
>      - rebase the patch
>      - remove the unnecessary judgment logic
> 
> v1 -> v2:
>      - revert the modifications to the fs/erofs/internal.h
> 
>   fs/erofs/decompressor.c | 21 +++++++++------------
>   1 file changed, 9 insertions(+), 12 deletions(-)

LGTM,
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>

Thanks,
Gao Xiang

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] erofs: simplify the code using for_each_set_bit
  2025-12-18  4:19 [PATCH v3] erofs: simplify the code using for_each_set_bit Yuwen Chen
  2025-12-18  9:20 ` Gao Xiang
@ 2026-01-21  5:27 ` Chao Yu
  1 sibling, 0 replies; 3+ messages in thread
From: Chao Yu @ 2026-01-21  5:27 UTC (permalink / raw)
  To: Yuwen Chen, xiang; +Cc: chao, huyue2, jefflexu, linux-erofs, linux-kernel

On 2025/12/18 12:19, 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@foxmail.com>

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-21  5:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-18  4:19 [PATCH v3] erofs: simplify the code using for_each_set_bit Yuwen Chen
2025-12-18  9:20 ` Gao Xiang
2026-01-21  5:27 ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®