device/dram/ddr3.c: Check SPD byte before using as a divisor
The Medium Time Base (MTB) value is calculated by dividing one SPD byte by another. Return an error if the divisor is zero before using the value for division. Found-by: Coverity Scan #1469303 Signed-off-by: Martin Roth <gaumless@gmail.com> Change-Id: Ic0a70291c42b5c2d21d65de92487b2dd88609983 Reviewed-on: https://review.coreboot.org/c/coreboot/+/78613 Reviewed-by: Patrick Rudolph <patrick.rudolph@9elements.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Singer <service+coreboot-gerrit@felixsinger.de>
This commit is contained in:
parent
58964ff02c
commit
a41abea65d
|
@ -422,6 +422,8 @@ int spd_xmp_decode_ddr3(struct dimm_attr_ddr3_st *dimm, spd_raw_data spd,
|
||||||
/* Medium Timebase =
|
/* Medium Timebase =
|
||||||
* Medium Timebase (MTB) Dividend /
|
* Medium Timebase (MTB) Dividend /
|
||||||
* Medium Timebase (MTB) Divisor */
|
* Medium Timebase (MTB) Divisor */
|
||||||
|
if (spd[181] == 0) // Avoid dividing by zero.
|
||||||
|
return SPD_STATUS_INVALID;
|
||||||
mtb = (((u32)spd[180]) << 8) / spd[181];
|
mtb = (((u32)spd[180]) << 8) / spd[181];
|
||||||
|
|
||||||
dimm->dimms_per_channel = ((spd[178] >> 2) & 0x3) + 1;
|
dimm->dimms_per_channel = ((spd[178] >> 2) & 0x3) + 1;
|
||||||
|
@ -437,6 +439,8 @@ int spd_xmp_decode_ddr3(struct dimm_attr_ddr3_st *dimm, spd_raw_data spd,
|
||||||
/* Medium Timebase =
|
/* Medium Timebase =
|
||||||
* Medium Timebase (MTB) Dividend /
|
* Medium Timebase (MTB) Dividend /
|
||||||
* Medium Timebase (MTB) Divisor */
|
* Medium Timebase (MTB) Divisor */
|
||||||
|
if (spd[183] == 0) // Avoid dividing by zero.
|
||||||
|
return SPD_STATUS_INVALID;
|
||||||
mtb = (((u32)spd[182]) << 8) / spd[183];
|
mtb = (((u32)spd[182]) << 8) / spd[183];
|
||||||
|
|
||||||
dimm->dimms_per_channel = ((spd[178] >> 4) & 0x3) + 1;
|
dimm->dimms_per_channel = ((spd[178] >> 4) & 0x3) + 1;
|
||||||
|
|
Loading…
Reference in New Issue