diff mbox

cpu/cpufreq: Iterate over the correct number of CPUs in _test_sw_any

Message ID 1437696348-2347-1-git-send-email-ricardo.neri-calderon@linux.intel.com
State Accepted
Headers show

Commit Message

Ricardo Neri July 24, 2015, 12:05 a.m. UTC
cpu_test_sw_any goes into a loop to set the frequency of all the
available CPUs. However, the loop iterates beyond the limits of the
CPUs array. Given that functions such as cpu_set_lowest_frequency
derreference members of struct cpu, iterating beyond the limits of the
array might cause segmentation faults.

Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
 src/cpu/cpufreq/cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alex Hung July 24, 2015, 1:56 a.m. UTC | #1
On 07/24/2015 08:05 AM, Ricardo Neri wrote:
> cpu_test_sw_any goes into a loop to set the frequency of all the
> available CPUs. However, the loop iterates beyond the limits of the
> CPUs array. Given that functions such as cpu_set_lowest_frequency
> derreference members of struct cpu, iterating beyond the limits of the
> array might cause segmentation faults.
> 
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> ---
>  src/cpu/cpufreq/cpufreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index 40f6a30..35812f4 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -507,7 +507,7 @@ static int cpufreq_test_sw_any(fwts_framework *fw)
>  
>  	ok = true;
>  
> -	for (i = 0; i <= num_cpus; i++) {
> +	for (i = 0; i < num_cpus; i++) {
>  		struct cpu *cpu = &cpus[i];
>  
>  		if (!cpu->online)
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Colin Ian King July 24, 2015, 8:22 a.m. UTC | #2
On 24/07/15 01:05, Ricardo Neri wrote:
> cpu_test_sw_any goes into a loop to set the frequency of all the
> available CPUs. However, the loop iterates beyond the limits of the
> CPUs array. Given that functions such as cpu_set_lowest_frequency
> derreference members of struct cpu, iterating beyond the limits of the
> array might cause segmentation faults.
> 
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
> ---
>  src/cpu/cpufreq/cpufreq.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index 40f6a30..35812f4 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -507,7 +507,7 @@ static int cpufreq_test_sw_any(fwts_framework *fw)
>  
>  	ok = true;
>  
> -	for (i = 0; i <= num_cpus; i++) {
> +	for (i = 0; i < num_cpus; i++) {
>  		struct cpu *cpu = &cpus[i];
>  
>  		if (!cpu->online)
> 

Thanks Ricardo

Acked-by: Colin Ian King <colin.king@canonical.com>
diff mbox

Patch

diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
index 40f6a30..35812f4 100644
--- a/src/cpu/cpufreq/cpufreq.c
+++ b/src/cpu/cpufreq/cpufreq.c
@@ -507,7 +507,7 @@  static int cpufreq_test_sw_any(fwts_framework *fw)
 
 	ok = true;
 
-	for (i = 0; i <= num_cpus; i++) {
+	for (i = 0; i < num_cpus; i++) {
 		struct cpu *cpu = &cpus[i];
 
 		if (!cpu->online)