x86_energy_perf_policy: Harden against potential ratio overflow

Prevent integer overflow in ratio_2_msr_perf() by using 64-bit
arithmetic for the intermediate multiplication calculation.

Assisted-by: GitHub-Copilot:Claude-Sonnet-4.6
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Len Brown 2026-05-06 10:00:00 -04:00
parent 0177067d19
commit 128c6fd2af

View File

@ -141,11 +141,13 @@ void usage(void)
int ratio_2_msr_perf(int ratio)
{
int msr_perf;
unsigned long long temp;
if (!bdx_highest_ratio)
return ratio;
msr_perf = ratio * 255 / bdx_highest_ratio;
temp = (unsigned long long)ratio * 255;
msr_perf = temp / bdx_highest_ratio;
if (debug)
fprintf(stderr, "%d = ratio_to_msr_perf(%d)\n", msr_perf, ratio);