Skip to contentSkip to conversation

btrfs: lzo: Mask instead of divide to fix 32-bit build

PATCH In review Geert Uytterhoeven 3 participants 3 messages Oct 5, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: lzo: Mask instead of divide to fix 32-bit build

On 32-bit builds (e.g. m68k):

ERROR: modpost: "__umoddi3" [fs/btrfs/btrfs.ko] undefined!

"cur_in - start" is 64-bit, while sectorsize is u32.

As sectorsize is always a power of two, the 64-by-32 modulo operation can be replaced by a much cheaper bitwise AND with "sectorsize - 1".

Fixes 0078783c7089fc83 ("btrfs: rework lzo_compress_pages() to make it subpage compatible")
Reported-by [email protected]

---
Compile-tested only.

---
 fs/btrfs/lzo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/lzo.c +1 -1
index 47003cec4046f13e..d08f9eba49dab3cd 100644
@@ -211,7 +211,7 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
 	 */
 	cur_out += LZO_LEN;
 	while (cur_in < start + len) {
-		u32 sector_off = (cur_in - start) % sectorsize;
+		u32 sector_off = (cur_in - start) & (sectorsize - 1);
 		u32 in_len;
 		size_t out_len;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Geert Uytterhoeven

On 32-bit builds (e.g. m68k):

ERROR: modpost: "__umoddi3" [fs/btrfs/btrfs.ko] undefined!

Quoted 8 lines

"cur_in - start" is 64-bit, while sectorsize is u32.

As sectorsize is always a power of two, the 64-by-32 modulo operation can be replaced by a much cheaper bitwise AND with "sectorsize - 1".

Fixes 0078783c7089fc83 ("btrfs: rework lzo_compress_pages() to make it subpage compatible")
Reported-by [email protected]

Oh, thanks for catching this.

Thanks,
Qu

Quoted 20 lines

---
Compile-tested only.

---
  fs/btrfs/lzo.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/lzo.c +1 -1
index 47003cec4046f13e..d08f9eba49dab3cd 100644
@@ -211,7 +211,7 @@ int lzo_compress_pages(struct list_head *ws, struct address_space *mapping,
  	 */
  	cur_out += LZO_LEN;
  	while (cur_in < start + len) {
-		u32 sector_off = (cur_in - start) % sectorsize;
+		u32 sector_off = (cur_in - start) & (sectorsize - 1);
  		u32 in_len;
  		size_t out_len;
 
#2 lore raw
In reply to Geert Uytterhoeven
Quoted 4 lines · Geert Uytterhoeven

On 32-bit builds (e.g. m68k):

ERROR: modpost: "__umoddi3" [fs/btrfs/btrfs.ko] undefined!

Quoted 8 lines

"cur_in - start" is 64-bit, while sectorsize is u32.

As sectorsize is always a power of two, the 64-by-32 modulo operation can be replaced by a much cheaper bitwise AND with "sectorsize - 1".

Fixes 0078783c7089fc83 ("btrfs: rework lzo_compress_pages() to make it subpage compatible")
Reported-by [email protected]

Thanks. Folded to the patch as it's still in the devel queue.