thermal/drivers/cpufreq_cooling: Update cpufreq_state only if state has changed
authorZhuguangqing <zhuguangqing@xiaomi.com>
Fri, 6 Nov 2020 09:22:43 +0000 (17:22 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Jan 2021 13:48:35 +0000 (14:48 +0100)
commit 236761f19a4f373354f1dcf399b57753f1f4b871 upstream.

If state has not changed successfully and we updated cpufreq_state,
next time when the new state is equal to cpufreq_state (not changed
successfully last time), we will return directly and miss a
freq_qos_update_request() that should have been.

Fixes: 5130802ddbb1 ("thermal: cpu_cooling: Switch to QoS requests for freq limits")
Cc: v5.4+ <stable@vger.kernel.org> # v5.4+
Signed-off-by: Zhuguangqing <zhuguangqing@xiaomi.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20201106092243.15574-1-zhuguangqing83@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/thermal/cpu_cooling.c

index c37886a2671247a4264a4f8e97c1f6698c2995e3..9d24bc05df0da7203e69f2291a492bd82358202c 100644 (file)
@@ -320,6 +320,7 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
                                 unsigned long state)
 {
        struct cpufreq_cooling_device *cpufreq_cdev = cdev->devdata;
+       int ret;
 
        /* Request state should be less than max_level */
        if (WARN_ON(state > cpufreq_cdev->max_level))
@@ -329,10 +330,12 @@ static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
        if (cpufreq_cdev->cpufreq_state == state)
                return 0;
 
-       cpufreq_cdev->cpufreq_state = state;
+       ret = freq_qos_update_request(&cpufreq_cdev->qos_req,
+                       cpufreq_cdev->freq_table[state].frequency);
+       if (ret > 0)
+               cpufreq_cdev->cpufreq_state = state;
 
-       return freq_qos_update_request(&cpufreq_cdev->qos_req,
-                               cpufreq_cdev->freq_table[state].frequency);
+       return ret;
 }
 
 /**