Skip to contentSkip to conversation

thermal/drivers/cpufreq_cooling: Remove abusing WARN_ON

PATCH In review Daniel Lezcano 3 participants 3 messages Mar 21, 2020 – Mar 24, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 drivers/thermal/cpufreq_cooling.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/cpufreq_cooling.c +2 -2
index af55ac08e1bd..d66791a71320 100644
@@ -273,7 +273,7 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
 	struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
 
 	/* Request state should be less than max_level */
-	if (WARN_ON(state > cpufreq_cdev->max_level))
+	if (state > cpufreq_cdev->max_level)
 		return -EINVAL;
 
 	num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus);
@@ -434,7 +434,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 	int ret;
 
 	/* Request state should be less than max_level */
-	if (WARN_ON(state > cpufreq_cdev->max_level))
+	if (state > cpufreq_cdev->max_level)
 		return -EINVAL;
 
 	/* Check if the old cooling action is same as new cooling action */
Signature · 1 line
2.17.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 35 lines · Daniel Lezcano

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.

---
 drivers/thermal/cpufreq_cooling.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/cpufreq_cooling.c +1 -1
index af55ac08e1bd..d66791a71320 100644
@@ -273,7 +273,7 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
 	struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
 
 	/* Request state should be less than max_level */
-	if (WARN_ON(state > cpufreq_cdev->max_level))
+	if (state > cpufreq_cdev->max_level)
 		return -EINVAL;
 
 	num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus);

drivers/thermal/cpufreq_cooling.c static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev, · line 440

Quoted 8 lines
drivers/thermal/cpufreq_cooling.c +1 -1
@@ -434,7 +434,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 	int ret;
 
 	/* Request state should be less than max_level */
-	if (WARN_ON(state > cpufreq_cdev->max_level))
+	if (state > cpufreq_cdev->max_level)
 		return -EINVAL;
 
 	/* Check if the old cooling action is same as new cooling action */
Signature · 1 line
viresh
Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniel Lezcano
Quoted 10 lines · Daniel Lezcano

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.

Quoted 8 lines

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.

Quoted 29 lines
---
 drivers/thermal/cpufreq_cooling.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/thermal/cpufreq_cooling.c +2 -3
index af55ac08e1bd..d66791a71320 100644
@@ -273,7 +273,7 @@ static int cpufreq_state2power(struct thermal_cooling_device *cdev,
        struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
 
        /* Request state should be less than max_level */
-       if (WARN_ON(state > cpufreq_cdev->max_level))
+       if (state > cpufreq_cdev->max_level)
                return -EINVAL;
 
        num_cpus = cpumask_weight(cpufreq_cdev->policy->cpus);
@@ -434,7 +434,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
        int ret;
 
        /* Request state should be less than max_level */
-       if (WARN_ON(state > cpufreq_cdev->max_level))
+       if (state > cpufreq_cdev->max_level)
                return -EINVAL;
 
        /* Check if the old cooling action is same as new cooling action */
--

2.17.1