Skip to contentSkip to conversation

fs/squashfs: use lldiv function for math

PATCH In review Sean Nyekjaer 3 participants 3 messages May 12, 2022 – May 23, 2022 SquashFS file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fs/squashfs: use lldiv function for math

From: Sean Nyekjaer <[email protected]>

When compling for x86:
ld.bfd: fs/squashfs/sqfs.o: in function `sqfs_read':
u-boot/fs/squashfs/sqfs.c:1443: undefined reference to __udivmoddi4' ld.bfd: u-boot/fs/squashfs/sqfs.c:1521: undefined reference to __udivmoddi4'

---
Changes since v1:
- switched to the correct lldiv() instead of do_div()

 fs/squashfs/sqfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/squashfs/sqfs.c +3 -2
index 5d9c52af80..08414571fc 100644
@@ -8,6 +8,7 @@
  */
 
 #include <asm/unaligned.h>
+#include <div64.h>
 #include <errno.h>
 #include <fs.h>
 #include <linux/types.h>
@@ -1440,7 +1441,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
 	}
 
 	for (j = 0; j < datablk_count; j++) {
-		start = data_offset / ctxt.cur_dev->blksz;
+		start = lldiv(data_offset, ctxt.cur_dev->blksz);
 		table_size = SQFS_BLOCK_SIZE(finfo.blk_sizes[j]);
 		table_offset = data_offset - (start * ctxt.cur_dev->blksz);
 		n_blks = DIV_ROUND_UP(table_size + table_offset,
@@ -1516,7 +1517,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
 		goto out;
 	}
 
-	start = frag_entry.start / ctxt.cur_dev->blksz;
+	start = lldiv(frag_entry.start, ctxt.cur_dev->blksz);
 	table_size = SQFS_BLOCK_SIZE(frag_entry.size);
 	table_offset = frag_entry.start - (start * ctxt.cur_dev->blksz);
 	n_blks = DIV_ROUND_UP(table_size + table_offset, ctxt.cur_dev->blksz);
Signature · 1 line
2.35.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · On Thursday 12 May 2022 20:37:14 Sean Nyekjaer wrote:

From: Sean Nyekjaer <[email protected]>

When compling for x86:
ld.bfd: fs/squashfs/sqfs.o: in function `sqfs_read':
u-boot/fs/squashfs/sqfs.c:1443: undefined reference to __udivmoddi4' ld.bfd: u-boot/fs/squashfs/sqfs.c:1521: undefined reference to __udivmoddi4'

Quoted 40 lines

---
Changes since v1:
- switched to the correct lldiv() instead of do_div()

 fs/squashfs/sqfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/squashfs/sqfs.c +3 -2
index 5d9c52af80..08414571fc 100644
@@ -8,6 +8,7 @@
  */
 
 #include <asm/unaligned.h>
+#include <div64.h>
 #include <errno.h>
 #include <fs.h>
 #include <linux/types.h>
@@ -1440,7 +1441,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
 	}
 
 	for (j = 0; j < datablk_count; j++) {
-		start = data_offset / ctxt.cur_dev->blksz;
+		start = lldiv(data_offset, ctxt.cur_dev->blksz);
 		table_size = SQFS_BLOCK_SIZE(finfo.blk_sizes[j]);
 		table_offset = data_offset - (start * ctxt.cur_dev->blksz);
 		n_blks = DIV_ROUND_UP(table_size + table_offset,
@@ -1516,7 +1517,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
 		goto out;
 	}
 
-	start = frag_entry.start / ctxt.cur_dev->blksz;
+	start = lldiv(frag_entry.start, ctxt.cur_dev->blksz);
 	table_size = SQFS_BLOCK_SIZE(frag_entry.size);
 	table_offset = frag_entry.start - (start * ctxt.cur_dev->blksz);
 	n_blks = DIV_ROUND_UP(table_size + table_offset, ctxt.cur_dev->blksz);
Signature · 1 line
2.35.1
#2 lore raw
In reply to Sean Nyekjaer
Quoted 10 lines · Sean Nyekjaer

From: Sean Nyekjaer <[email protected]>

When compling for x86:
ld.bfd: fs/squashfs/sqfs.o: in function `sqfs_read':
u-boot/fs/squashfs/sqfs.c:1443: undefined reference to __udivmoddi4' ld.bfd: u-boot/fs/squashfs/sqfs.c:1521: undefined reference to __udivmoddi4'

Applied to u-boot/master, thanks!

Signature · 1 line
Tom