diff options
author | Ji Luo <ji.luo@nxp.com> | 2020-10-28 09:12:59 +0800 |
---|---|---|
committer | Ji Luo <ji.luo@nxp.com> | 2020-10-28 13:27:11 +0800 |
commit | 077b448679b9ad2891495c7344ba99a6c10a59fb (patch) | |
tree | 00a773120494a271365c7c35114d7889fe3719e9 /lib | |
parent | 0cdc937f7bdd2de16c9d7161fb46252ba8648e10 (diff) |
MA-18166 Android: Fix mmc multi blk load issue
The 'offset' can be negative number passed from fsl_read_from_partition_multi(),
don't covert 'blksz' to 'uint64_t' as it will cause overflow when the 'offset'
is negative number.
Test: mmc blk read with 'offset < 0'.
Signed-off-by: Ji Luo <ji.luo@nxp.com>
Change-Id: Id1ce8e0c748dd280d70c1722cc7d17cc9646a4bb
Diffstat (limited to 'lib')
-rw-r--r-- | lib/avb/fsl/utils.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/avb/fsl/utils.c b/lib/avb/fsl/utils.c index d3b4254b55..64176a04e3 100644 --- a/lib/avb/fsl/utils.c +++ b/lib/avb/fsl/utils.c @@ -25,9 +25,9 @@ int get_margin_pos(uint64_t part_start, uint64_t part_end, unsigned long blksz, return -1; if (offset < 0) { - margin->blk_start = (offset + 1) / (uint64_t)blksz + part_end; + margin->blk_start = (offset + 1) / (int64_t)blksz + part_end; // offset == -1 means the last byte?, or start need -1 - margin->start = (off = offset % (uint64_t)blksz) == 0 ? + margin->start = (off = offset % (int64_t)blksz) == 0 ? 0 : blksz + off; if (offset + num_bytes - 1 >= 0) { if (!allow_partial) @@ -37,9 +37,9 @@ int get_margin_pos(uint64_t part_start, uint64_t part_end, unsigned long blksz, } else { // which blk the last byte is in margin->blk_end = (num_bytes + offset) / - (uint64_t)blksz + part_end; + (int64_t)blksz + part_end; margin->end = (off = (num_bytes + offset - 1) % - (uint64_t)blksz) == 0 ? + (int64_t)blksz) == 0 ? 0 : blksz + off; // last byte } } else { |