mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
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:
parent
0177067d19
commit
128c6fd2af
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user