diff mbox

[U-Boot,RESEND,1/4] fs:ext4:write: Add lldiv and do_div to perform 64-32 bits division

Message ID 1354730801-29898-2-git-send-email-l.majewski@samsung.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Ɓukasz Majewski Dec. 5, 2012, 6:06 p.m. UTC
The ext4write code has been using direct calls to 64-32 division
(/ and %).

Officially supported u-boot toolchains (eldk-5.[12].x) generate calls
to __aeabi_uldivmod(), which is niether defined in the toolchain libs
nor u-boot source tree.

Due to that, when the ext4write command has been executed, "undefined
instruction" execption was generated (since the __aeabi_uldivmod()
is not provided).

To fix this error, lldiv() for division and do_div() for modulo have
been used.

Those two functions are recommended for performing 64-32 bit number
division in u-boot.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
---
 fs/ext4/ext4fs.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/fs/ext4/ext4fs.c b/fs/ext4/ext4fs.c
index 06536ba..80b3b90 100644
--- a/fs/ext4/ext4fs.c
+++ b/fs/ext4/ext4fs.c
@@ -40,6 +40,7 @@ 
 #include <linux/stat.h>
 #include <linux/time.h>
 #include <asm/byteorder.h>
+#include <div64.h>
 #include "ext4_common.h"
 
 int ext4fs_symlinknest;
@@ -1051,8 +1052,8 @@  int ext4fs_write(const char *fname, unsigned char *buffer,
 	}
 	/* calucalate how many blocks required */
 	bytes_reqd_for_file = sizebytes;
-	blks_reqd_for_file = bytes_reqd_for_file / fs->blksz;
-	if (bytes_reqd_for_file % fs->blksz != 0) {
+	blks_reqd_for_file = lldiv(bytes_reqd_for_file, fs->blksz);
+	if (do_div(bytes_reqd_for_file, fs->blksz) != 0) {
 		blks_reqd_for_file++;
 		debug("total bytes for a file %u\n", blks_reqd_for_file);
 	}