[U-Boot] [PATCH] fastboot: sparse: fix sparse blocks calculation

Jeffy Chen jeffy.chen at rock-chips.com
Wed Feb 3 11:13:55 CET 2016


It may overflow in sparse_block_size_to_storage, use uint64_t instead in
the calculation.

Signed-off-by: Jeffy Chen <jeffy.chen at rock-chips.com>

---

 common/image-sparse.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/image-sparse.c b/common/image-sparse.c
index 542a8c4..0c07976 100644
--- a/common/image-sparse.c
+++ b/common/image-sparse.c
@@ -62,7 +62,8 @@ static unsigned int sparse_block_size_to_storage(unsigned int size,
 						 sparse_storage_t *storage,
 						 sparse_header_t *sparse)
 {
-	return size * sparse->blk_sz / storage->block_sz;
+	return (unsigned int)lldiv((uint64_t)size * sparse->blk_sz,
+				   storage->block_sz);
 }
 
 static bool sparse_chunk_has_buffer(chunk_header_t *chunk)
-- 
2.1.4




More information about the U-Boot mailing list