]> Pileus Git - ~andy/linux/blobdiff - drivers/thermal/cpu_cooling.c
Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[~andy/linux] / drivers / thermal / cpu_cooling.c
index a6cb5531403fe38f75be28269c8d714f7008aa6f..4246262c4bd249f5ee0d3cec5f3712d1fdd9bbc6 100644 (file)
@@ -174,6 +174,13 @@ static int get_property(unsigned int cpu, unsigned long input,
                max_level++;
        }
 
+       /* No valid cpu frequency entry */
+       if (max_level == 0)
+               return -EINVAL;
+
+       /* max_level is an index, not a counter */
+       max_level--;
+
        /* get max level */
        if (property == GET_MAXL) {
                *output = (unsigned int)max_level;
@@ -181,7 +188,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 +204,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) {