thermal: fix cpu_cooling max_level behavior
PATCH 1/1 thermal: fix cpu_cooling max_level behavior
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.
--- drivers/thermal/cpu_cooling.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/thermal/cpu_cooling.c +4 -2
@@ -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) {
Signature · 1 line
1.8.2.1.342.gfa7285d
Quoted 10 lines · Eduardo Valentin
As per
Documentation/thermal/sysfs-api.txt,max_levelis an index, not a counter. Thus, in case a CPU has
3 valid frequencies,max_levelis expected to be 2, for instance.The current code makes
max_level== number of valid frequencies, which is bogus. This patch fix thecpu_coolingdevice by rangingmax_levelproperly.Reported-by Carlos Hernandez <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>
Rui,
This fix is applicable even on 3.12.
Quoted 36 lines
--- drivers/thermal/cpu_cooling.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/thermal/cpu_cooling.c +4
-2@@ -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) {
Signature · 3 lines
You have got to be excited about what you are doing. (L. Lamport) Eduardo Valentin
Quoted 10 lines · Eduardo Valentin
As per
Documentation/thermal/sysfs-api.txt,max_levelis an index, not a counter. Thus, in case a CPU has
3 valid frequencies,max_levelis expected to be 2, for instance.The current code makes
max_level== number of valid frequencies, which is bogus. This patch fix thecpu_coolingdevice by rangingmax_levelproperly.Reported-by Carlos Hernandez <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>
Rui,
Can you please consider pushing this fix?
Quoted 36 lines
--- drivers/thermal/cpu_cooling.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/thermal/cpu_cooling.c +4
-2@@ -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) {
Signature · 3 lines
You have got to be excited about what you are doing. (L. Lamport) Eduardo Valentin
Quoted 9 lines · Eduardo Valentin
Quoted 8 lines · Eduardo Valentin
As per
Documentation/thermal/sysfs-api.txt,max_levelis an index, not a counter. Thus, in case a CPU has
3 valid frequencies,max_levelis expected to be 2, for instance.The current code makes
max_level== number of valid frequencies, which is bogus. This patch fix thecpu_coolingdevice by rangingmax_levelproperly.
good catch.
Quoted 7 lines
Quoted 2 lines
Reported-by Carlos Hernandez <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>Rui,
Can you please consider pushing this fix?
applied.
Quoted 4 lines
Quoted 4 lines
--- drivers/thermal/cpu_cooling.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Quoted 11 lines
drivers/thermal/cpu_cooling.c static int get_property(unsigned int cpu, unsigned long input, · line 178
Quoted 11 lines
drivers/thermal/cpu_cooling.c +2
-0@@ -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--;
I think we should check the max_level first, like the patch I attached below.
thanks,
rui
Quoted 1 line
From
a116776f7b6052599df0c67db29c30ea9d69d7eeMon Sep 17 00:00:00 2001
From: Zhang Rui <[email protected]>
Date: Thu, 2 Jan 2014 11:57:48 +0800
Subject: [PATCH] Thermal cpu cooling: return error if no valid cpu frequency
entry
--- drivers/thermal/cpu_cooling.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/thermal/cpu_cooling.c +5 -0
@@ -173,6 +173,11 @@ static int get_property(unsigned int cpu, unsigned long input, freq = table[i].frequency; max_level++; } + +/* No valid cpu frequency entry */ +if (max_level ==0 ) +return -EINVAL ; +/* max_level is an index, not a counter */ max_level--;
Signature · 1 line
1.7.9.5
Eduardo Valentin
Acked-byQuoted 57 lines · Zhang Rui
Quoted 9 lines · Eduardo Valentin
Quoted 8 lines · Eduardo Valentin
As per
Documentation/thermal/sysfs-api.txt,max_levelis an index, not a counter. Thus, in case a CPU has
3 valid frequencies,max_levelis expected to be 2, for instance.The current code makes
max_level== number of valid frequencies, which is bogus. This patch fix thecpu_coolingdevice by rangingmax_levelproperly.good catch.
Quoted 7 lines
Quoted 2 lines
Reported-by Carlos Hernandez <[email protected]>Signed-off-by Eduardo Valentin <[email protected]>Rui,
Can you please consider pushing this fix?
applied.
Quoted 4 lines
Quoted 4 lines
--- drivers/thermal/cpu_cooling.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)Quoted 11 lines
drivers/thermal/cpu_cooling.c static int get_property(unsigned int cpu, unsigned long input, · line 178
Quoted 11 lines
drivers/thermal/cpu_cooling.c +2
-0@@ -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--;I think we should check the
max_levelfirst, like the patch I attached below.thanks,
ruiQuoted 1 line
From
a116776f7b6052599df0c67db29c30ea9d69d7eeMon Sep 17 00:00:00 2001From: Zhang Rui <[email protected]>
Date: Thu, 2 Jan 2014 11:57:48 +0800
Subject: [PATCH] Thermal cpu cooling: return error if no valid cpu frequency
entrySigned-off-by Zhang Rui <[email protected]>--- drivers/thermal/cpu_cooling.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/thermal/cpu_cooling.c +0
-0
drivers/thermal/cpu_cooling.c static int get_property(unsigned int cpu, unsigned long input, · line 180
Quoted 8 lines
drivers/thermal/cpu_cooling.c +5
-0@@ -173,6 +173,11 @@ static int get_property(unsigned int cpu, unsigned long input, freq = table[i].frequency; max_level++; } + +/* No valid cpu frequency entry */ +if (max_level ==0 ) +return -EINVAL ; +
Agreed. For the patch above:
Quoted 4 lines
drivers/thermal/cpu_cooling.c +0
-0/* max_level is an index, not a counter */ max_level--;
Signature · 3 lines
You have got to be excited about what you are doing. (L. Lamport) Eduardo Valentin