diff options
author | Julius Werner <jwerner@chromium.org> | 2022-12-14 03:59:18 -0800 |
---|---|---|
committer | Yu-Ping Wu <yupingso@google.com> | 2022-12-15 02:53:45 +0000 |
commit | 2cf2bd81974722114b74e1880425b9921f38a7f9 (patch) | |
tree | 678737c2b3a9896ea8848d802451057139871373 /src | |
parent | 4a0e5e47418b08a807a3df13a281546e9929a734 (diff) |
mem_chip_info: Fix potential overflow
The calculation for mem_chip_info_total_density_bytes() may already
overflow in the intermediate 32-bit calculations before being assigned
to the 64-bit result variable. Fix that.
Fixes Coverity issue: CID 1501510
BRANCH=corsola
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I73da014c953381974c6ede2b17586b68675bde2d
Reviewed-on: https://review.coreboot.org/c/coreboot/+/70764
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h b/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h index 4ab0c6f289..bcc15a1f8c 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h +++ b/src/commonlib/bsd/include/commonlib/bsd/mem_chip_info.h @@ -101,7 +101,8 @@ static inline uint64_t mem_chip_info_total_density_bytes(const struct mem_chip_i for (i = 0; i < info->num_entries; i++) { const struct mem_chip_entry *e = &info->entries[i]; - bytes += e->density_mbits * (e->channel_io_width / e->io_width) * (MiB / 8); + bytes += (uint64_t)e->density_mbits * (e->channel_io_width / e->io_width) + * (MiB / 8); } return bytes; |