ACK: [PATCH] fwts: cpufreq: fix theoretical division by zero (LP: #1466905)

Alex Hung alex.hung at canonical.com
Tue Jun 23 06:09:04 UTC 2015


On 06/19/2015 11:09 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> CoverityScan reports a potential division by zero error:
> 
> 528 performed_tests++;
>    CID 1299399 (#1 of 2): Division or modulo by zero (DIVIDE_BY_ZERO)
> 529 fwts_progress(fw, 100 * performed_tests/n_tests);
> 
> it is noteworthy that n_tests is never zero because it is related
> to the number of CPUs online which is always going to be > 0, but
> Coverity does not know this and also we better ensure we check for
> this division by zero since the CPU online data may be not available
> and there is a theoretical risk of n_tests being zero.
> 
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/cpu/cpufreq/cpufreq.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index c6d6a9d..40f6a30 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -526,7 +526,8 @@ static int cpufreq_test_sw_any(fwts_framework *fw)
>  		high_perf = fwts_cpu_benchmark_best_result(&result);
>  
>  		performed_tests++;
> -		fwts_progress(fw, 100 * performed_tests/n_tests);
> +		if (n_tests)
> +			fwts_progress(fw, 100 * performed_tests / n_tests);
>  		/*
>  		 * now set all the others to low again; sw_any will cause
>  		 * the core in question to now also get the low speed, while
> @@ -550,7 +551,8 @@ static int cpufreq_test_sw_any(fwts_framework *fw)
>  			ok = false;
>  		}
>  		performed_tests++;
> -		fwts_progress(fw, 100 * performed_tests/n_tests);
> +		if (n_tests)
> +			fwts_progress(fw, 100 * performed_tests / n_tests);
>  	}
>  
>  	if (!ok)
> 

Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list