[PATCH v2] erofs-utils: fix bitops fls_long

Hongzhen Luo hongzhen at linux.alibaba.com
Tue Jul 9 15:07:00 AEST 2024


The __builtin_clz is for unsigned int, while it is applied
to unsigned long. This fixes it by using __builtin_clzl.

The parameter types for the calls referencing fls_long have
been adjusted (e.g., roundup_pow_of_two in erofs_init_devices).

Signed-off-by: Hongzhen Luo <hongzhen at linux.alibaba.com>
---
v2: The parameter types for the function calls affected by this fix have been updated.
v1: https://lore.kernel.org/all/20240709022031.2752872-1-hongzhen@linux.alibaba.com/
---
 include/erofs/defs.h | 2 +-
 lib/super.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/erofs/defs.h b/include/erofs/defs.h
index e0798c8..310a6ab 100644
--- a/include/erofs/defs.h
+++ b/include/erofs/defs.h
@@ -288,7 +288,7 @@ static inline u32 get_unaligned_le64(const void *p)
 
 static inline unsigned int fls_long(unsigned long x)
 {
-	return x ? sizeof(x) * 8 - __builtin_clz(x) : 0;
+	return x ? sizeof(x) * 8 - __builtin_clzl(x) : 0;
 }
 
 static inline unsigned long lowbit(unsigned long n)
diff --git a/lib/super.c b/lib/super.c
index 3fbaf66..2d3180e 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -27,7 +27,7 @@ static bool check_layout_compatibility(struct erofs_sb_info *sbi,
 static int erofs_init_devices(struct erofs_sb_info *sbi,
 			      struct erofs_super_block *dsb)
 {
-	unsigned int ondisk_extradevs, i;
+	unsigned long ondisk_extradevs, i;
 	erofs_off_t pos;
 
 	sbi->total_blocks = sbi->primarydevice_blocks;
-- 
2.43.5



More information about the Linux-erofs mailing list