thermal: fix cpu_cooling max_level behavior
authorEduardo Valentin <eduardo.valentin@ti.com>
Wed, 13 Nov 2013 18:11:09 +0000 (14:11 -0400)
committerAlex Shi <alex.shi@linaro.org>
Thu, 25 Sep 2014 09:02:15 +0000 (17:02 +0800)
As per Documentation/thermal/sysfs-api.txt, max_level
is an index, not a counter. Thus, in case a CPU has
3 valid frequencies, max_level is expected to be 2, for instance.

The current code makes max_level == number of valid frequencies,
which is bogus. This patch fix the cpu_cooling device by
ranging max_level properly.

Reported-by: Carlos Hernandez <ceh@ti.com>
Signed-off-by: Eduardo Valentin <eduardo.valentin@ti.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
(cherry picked from commit 1c9573a40c1d34494419f32560f28c763c504d79)
Signed-off-by: Alex Shi <alex.shi@linaro.org>
drivers/thermal/cpu_cooling.c

index 6093862ae7ada9af9ebe54b9b37dd8487c3574e1..3331b1a12f8520dbf31d8ce737fa21cf47c7540a 100644 (file)
@@ -173,6 +173,8 @@ static int get_property(unsigned int cpu, unsigned long input,
                freq = table[i].frequency;
                max_level++;
        }
+       /* max_level is an index, not a counter */
+       max_level--;
 
        /* get max level */
        if (property == GET_MAXL) {
@@ -181,7 +183,7 @@ static int get_property(unsigned int cpu, unsigned long input,
        }
 
        if (property == GET_FREQ)
-               level = descend ? input : (max_level - input - 1);
+               level = descend ? input : (max_level - input);
 
        for (i = 0, j = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
                /* ignore invalid entry */
@@ -197,7 +199,7 @@ static int get_property(unsigned int cpu, unsigned long input,
 
                if (property == GET_LEVEL && (unsigned int)input == freq) {
                        /* get level by frequency */
-                       *output = descend ? j : (max_level - j - 1);
+                       *output = descend ? j : (max_level - j);
                        return 0;
                }
                if (property == GET_FREQ && level == j) {