mb/dell/optiplex_9020: Fix UB in package power calculation
Fix potential undefined behaviour in the `get_pkg_power()` function: - If `rapl_power_unit == 0`, `pkg_power_info / rapl_power_unit` is invalid - If `rapl_power_unit > 7`, the result of the shift doesn't fit into a `uint8_t` Signed-off-by: Mate Kukri <km@mkukri.xyz> Change-Id: I48ef59c4fbeb0a55675ac24da31e6e0b194cb58d Reviewed-on: https://review.coreboot.org/c/coreboot/+/83736 Reviewed-by: Angel Pons <th3fanbus@gmail.com> Reviewed-by: Nico Huber <nico.h@gmx.de> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Elyes Haouas <ehaouas@noos.fr>
This commit is contained in:
parent
b256e6303c
commit
ac9ffb9432
@ -303,11 +303,9 @@ static uint8_t get_temp_target(void)
|
|||||||
|
|
||||||
static uint16_t get_pkg_power(void)
|
static uint16_t get_pkg_power(void)
|
||||||
{
|
{
|
||||||
uint8_t rapl_power_unit = rdmsr(0x606).lo & 0xf;
|
const unsigned int pkg_power = rdmsr(0x614).lo & 0x7fff;
|
||||||
if (rapl_power_unit)
|
const unsigned int power_unit = 1 << (rdmsr(0x606).lo & 0xf);
|
||||||
rapl_power_unit = 2 << (rapl_power_unit - 1);
|
if (pkg_power / power_unit > 65)
|
||||||
uint16_t pkg_power_info = rdmsr(0x614).lo & 0x7fff;
|
|
||||||
if (pkg_power_info / rapl_power_unit > 0x41)
|
|
||||||
return 32;
|
return 32;
|
||||||
else
|
else
|
||||||
return 16;
|
return 16;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user