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>
This commit is contained in:
committed by
Yu-Ping Wu
parent
4a0e5e4741
commit
2cf2bd8197
@@ -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++) {
|
for (i = 0; i < info->num_entries; i++) {
|
||||||
const struct mem_chip_entry *e = &info->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;
|
return bytes;
|
||||||
|
Reference in New Issue
Block a user