mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] erofs: simplify the code using for_each_set_bit
@ 2025-12-18  2:57 Yuwen Chen
  2025-12-18  3:02 ` Gao Xiang
  0 siblings, 1 reply; 2+ messages in thread
From: Yuwen Chen @ 2025-12-18  2:57 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>
---

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;
+	for_each_set_bit(alg, &algs, Z_EROFS_COMPRESSION_MAX) {
 		void *data;
 
-		if (!(algs & 1))
-			continue;
-
 		data = erofs_read_metadata(sb, &buf, &offset, &size);
 		if (IS_ERR(data)) {
 			ret = PTR_ERR(data);
@@ -438,7 +435,7 @@ int z_erofs_parse_cfgs(struct super_block *sb, struct erofs_super_block *dsb)
 
 		if (alg >= ARRAY_SIZE(erofs_decompressors) ||
 		    !erofs_decompressors[alg].config) {
-			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;
 		} else {
-- 
2.34.1


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

end of thread, other threads:[~2025-12-18  3:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-18  2:57 [PATCH v2] erofs: simplify the code using for_each_set_bit Yuwen Chen
2025-12-18  3:02 ` Gao Xiang

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®