diff mbox

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

Message ID 1454494435-12793-1-git-send-email-jeffy.chen@rock-chips.com
State Accepted
Commit d3bafe32ca47bc3872837c1fe7874f9913de103f
Delegated to: Tom Rini
Headers show

Commit Message

Jeffy Chen Feb. 3, 2016, 10:13 a.m. UTC
It may overflow in sparse_block_size_to_storage, use uint64_t instead in
the calculation.

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

---

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

Comments

Tom Rini April 12, 2016, 2:28 a.m. UTC | #1
On Wed, Feb 03, 2016 at 06:13:55PM +0800, Jeffy Chen wrote:

> It may overflow in sparse_block_size_to_storage, use uint64_t instead in
> the calculation.
> 
> Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>

Applied to u-boot/master, thanks!
diff mbox

Patch

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)