Skip to contentSkip to conversation

erofs-utils: fix bitops fls_long

PATCH Superseded Hongzhen Luo 1 participant 1 message Jul 9, 2024 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 erofs-utils: fix bitops fls_long

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

---
v2: The parameter types for the function calls affected by this fix have been updated.
v1: https://lore.kernel.org/all/[email protected]/

---
 include/erofs/defs.h | 2 +-
 lib/super.c          | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
include/erofs/defs.h +1 -1
index e0798c8..310a6ab 100644
@@ -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)
lib/super.c +1 -1
index 3fbaf66..2d3180e 100644
@@ -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;
Signature · 1 line
2.43.5