Skip to content

Commit 3ea3217

Browse files
vireshkzhang-rui
authored andcommitted
thermal: cpu_cooling: Check OPP for errors
It is possible for dev_pm_opp_find_freq_exact() to return errors. It was all fine earlier as dev_pm_opp_get_voltage() had a check within it to check for invalid OPPs, but dev_pm_opp_put() doesn't have any similar checks and the callers need to make sure OPP is valid before calling them. Also update the later dev_warn_ratelimited() to not print the error message as the OPP is guaranteed to be valid now. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Viresh Kumar <[email protected]> Signed-off-by: Zhang Rui <[email protected]>
1 parent 9aec908 commit 3ea3217

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/thermal/cpu_cooling.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,20 @@ static int get_static_power(struct cpufreq_cooling_device *cpufreq_device,
393393

394394
opp = dev_pm_opp_find_freq_exact(cpufreq_device->cpu_dev, freq_hz,
395395
true);
396+
if (IS_ERR(opp)) {
397+
dev_warn_ratelimited(cpufreq_device->cpu_dev,
398+
"Failed to find OPP for frequency %lu: %ld\n",
399+
freq_hz, PTR_ERR(opp));
400+
return -EINVAL;
401+
}
402+
396403
voltage = dev_pm_opp_get_voltage(opp);
397404
dev_pm_opp_put(opp);
398405

399406
if (voltage == 0) {
400407
dev_err_ratelimited(cpufreq_device->cpu_dev,
401-
"Failed to get voltage for frequency %lu: %ld\n",
402-
freq_hz, IS_ERR(opp) ? PTR_ERR(opp) : 0);
408+
"Failed to get voltage for frequency %lu\n",
409+
freq_hz);
403410
return -EINVAL;
404411
}
405412

0 commit comments

Comments
 (0)