cpu: cpufreq: avoid division by zero by initializing cpu_top_perf to 1
diff mbox series

Message ID 20190610102146.27721-1-colin.king@canonical.com
State Accepted
Headers show
Series
  • cpu: cpufreq: avoid division by zero by initializing cpu_top_perf to 1
Related show

Commit Message

Colin Ian King June 10, 2019, 10:21 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

There is a potential division by zero if no cpu frequencies are found
when cpu_top_perf is initialized as zero.  A simple fix is to initialize
it to 1.

Addresses-Coverity: ("Division or modulo by zero")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/cpu/cpufreq/cpufreq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alex Hung June 10, 2019, 8:30 p.m. UTC | #1
On 2019-06-10 3:21 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> There is a potential division by zero if no cpu frequencies are found
> when cpu_top_perf is initialized as zero.  A simple fix is to initialize
> it to 1.
> 
> Addresses-Coverity: ("Division or modulo by zero")
> Signed-off-by: Colin Ian King <colin.king@canonical.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 60101f29..8c8870c0 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -279,7 +279,7 @@ static uint64_t get_bios_limit(struct cpu *cpu)
>  static int test_one_cpu_performance(fwts_framework *fw, struct cpu *cpu,
>  		int cpu_idx, int n_online_cpus)
>  {
> -	uint64_t cpu_top_perf = 0;
> +	uint64_t cpu_top_perf = 1;
>  	int i;
>  
>  	for (i = 0; i < cpu->n_freqs; i++) {
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan June 11, 2019, 5:43 a.m. UTC | #2
On 6/10/19 6:21 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> There is a potential division by zero if no cpu frequencies are found
> when cpu_top_perf is initialized as zero.  A simple fix is to initialize
> it to 1.
>
> Addresses-Coverity: ("Division or modulo by zero")
> Signed-off-by: Colin Ian King <colin.king@canonical.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 60101f29..8c8870c0 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -279,7 +279,7 @@ static uint64_t get_bios_limit(struct cpu *cpu)
>  static int test_one_cpu_performance(fwts_framework *fw, struct cpu *cpu,
>  		int cpu_idx, int n_online_cpus)
>  {
> -	uint64_t cpu_top_perf = 0;
> +	uint64_t cpu_top_perf = 1;
>  	int i;
>  
>  	for (i = 0; i < cpu->n_freqs; i++) {


Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch
diff mbox series

diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
index 60101f29..8c8870c0 100644
--- a/src/cpu/cpufreq/cpufreq.c
+++ b/src/cpu/cpufreq/cpufreq.c
@@ -279,7 +279,7 @@  static uint64_t get_bios_limit(struct cpu *cpu)
 static int test_one_cpu_performance(fwts_framework *fw, struct cpu *cpu,
 		int cpu_idx, int n_online_cpus)
 {
-	uint64_t cpu_top_perf = 0;
+	uint64_t cpu_top_perf = 1;
 	int i;
 
 	for (i = 0; i < cpu->n_freqs; i++) {