Skip to content

Commit f5f94b9

Browse files
pierregondoisvireshk
authored andcommitted
cpufreq: CPPC: Add u64 casts to avoid overflowing
The fields of the _CPC object are unsigned 32-bits values. To avoid overflows while using _CPC's values, add 'u64' casts. Signed-off-by: Pierre Gondois <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent 83749a2 commit f5f94b9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

drivers/cpufreq/cppc_cpufreq.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ static unsigned int get_perf_level_count(struct cpufreq_policy *policy)
487487
cpu_data = policy->driver_data;
488488
perf_caps = &cpu_data->perf_caps;
489489
max_cap = arch_scale_cpu_capacity(cpu);
490-
min_cap = div_u64(max_cap * perf_caps->lowest_perf, perf_caps->highest_perf);
490+
min_cap = div_u64((u64)max_cap * perf_caps->lowest_perf,
491+
perf_caps->highest_perf);
491492
if ((min_cap == 0) || (max_cap < min_cap))
492493
return 0;
493494
return 1 + max_cap / CPPC_EM_CAP_STEP - min_cap / CPPC_EM_CAP_STEP;
@@ -519,10 +520,10 @@ static int cppc_get_cpu_power(struct device *cpu_dev,
519520
cpu_data = policy->driver_data;
520521
perf_caps = &cpu_data->perf_caps;
521522
max_cap = arch_scale_cpu_capacity(cpu_dev->id);
522-
min_cap = div_u64(max_cap * perf_caps->lowest_perf,
523-
perf_caps->highest_perf);
524-
525-
perf_step = CPPC_EM_CAP_STEP * perf_caps->highest_perf / max_cap;
523+
min_cap = div_u64((u64)max_cap * perf_caps->lowest_perf,
524+
perf_caps->highest_perf);
525+
perf_step = div_u64((u64)CPPC_EM_CAP_STEP * perf_caps->highest_perf,
526+
max_cap);
526527
min_step = min_cap / CPPC_EM_CAP_STEP;
527528
max_step = max_cap / CPPC_EM_CAP_STEP;
528529

0 commit comments

Comments
 (0)