Skip to content

Commit

Permalink
thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power()
Browse files Browse the repository at this point in the history
The frequency table shouldn't have any zero frequency entries and so
such a check isn't required. Though it would be better to make sure
'state' is within limits.

Signed-off-by: Viresh Kumar <[email protected]>
Reviewed-by: Lukasz Luba <[email protected]>
Tested-by: Lukasz Luba <[email protected]>
Signed-off-by: Eduardo Valentin <[email protected]>
  • Loading branch information
vireshk authored and Eduardo Valentin committed May 28, 2017
1 parent 53ca1ec commit cb1b631
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions drivers/thermal/cpu_cooling.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,13 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
int ret;
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;

/* Request state should be less than max_level */
if (WARN_ON(state > cpufreq_cdev->max_level))
return -EINVAL;

num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus);

freq = cpufreq_cdev->freq_table[state].frequency;
if (!freq)
return -EINVAL;

dynamic_power = cpu_freq_to_power(cpufreq_cdev, freq) * num_cpus;
ret = get_static_power(cpufreq_cdev, tz, freq, &static_power);
if (ret)
Expand Down

0 comments on commit cb1b631

Please sign in to comment.