Skip to content

Commit 40ea568

Browse files
committed
thermal/drivers/cpufreq_cooling: Remove abusing WARN_ON
The WARN_ON macros are used at the entry functions state2power() and set_cur_state(). state2power() is called with the max_state retrieved from get_max_state which returns cpufreq_cdev->max_level, then it check if max_state is > cpufreq_cdev->max_level. The test does not really makes sense but let's assume we want to make sure to catch an error if the code evolves. However the WARN_ON is overkill. set_cur_state() is also called from userspace if we write to the sysfs. It is easy to see a stack dumped by just writing to sysfs /sys/class/thermal/cooling_device0/cur_state a value greater than "max_level". A bit scary. Returing -EINVAL is enough. Remove these WARN_ON. Signed-off-by: Daniel Lezcano <[email protected]> Acked-by: Viresh Kumar <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ff44f67 commit 40ea568

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/thermal/cpufreq_cooling.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
273273
struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
274274

275275
/* Request state should be less than max_level */
276-
if (WARN_ON(state > cpufreq_cdev->max_level))
276+
if (state > cpufreq_cdev->max_level)
277277
return -EINVAL;
278278

279279
num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus);
@@ -434,7 +434,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
434434
int ret;
435435

436436
/* Request state should be less than max_level */
437-
if (WARN_ON(state > cpufreq_cdev->max_level))
437+
if (state > cpufreq_cdev->max_level)
438438
return -EINVAL;
439439

440440
/* Check if the old cooling action is same as new cooling action */

0 commit comments

Comments
 (0)