Patchwork cpu: cpufreq: avoid division by zero

login
register
mail settings
Submitter Colin King
Date May 6, 2013, 11:41 p.m.
Message ID <1367883678-22498-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241836/
State Accepted
Headers show

Comments

Colin King - May 6, 2013, 11:41 p.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997299, Division or modulo by zero (DIVIDE_BY_ZERO)

Avoid the very slim chance of a division by zero error.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/cpu/cpufreq/cpufreq.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Alex Hung - May 9, 2013, 6:09 a.m.
On 05/07/2013 07:41 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997299, Division or modulo by zero (DIVIDE_BY_ZERO)
>
> Avoid the very slim chance of a division by zero error.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/cpufreq/cpufreq.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index df52100..e115bbb 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -169,7 +169,10 @@ static int get_performance_repeat(
>   		*retval = min;
>   		break;
>   	case GET_PERFORMANCE_AVG:
> -		*retval = cumulative / real_count;
> +		if (real_count)
> +			*retval = cumulative / real_count;
> +		else
> +			*retval = 0;
>   		break;
>   	default:
>   		*retval = 0;
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 16, 2013, 3:36 a.m.
On 05/07/2013 07:41 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997299, Division or modulo by zero (DIVIDE_BY_ZERO)
>
> Avoid the very slim chance of a division by zero error.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/cpu/cpufreq/cpufreq.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
> index df52100..e115bbb 100644
> --- a/src/cpu/cpufreq/cpufreq.c
> +++ b/src/cpu/cpufreq/cpufreq.c
> @@ -169,7 +169,10 @@ static int get_performance_repeat(
>   		*retval = min;
>   		break;
>   	case GET_PERFORMANCE_AVG:
> -		*retval = cumulative / real_count;
> +		if (real_count)
> +			*retval = cumulative / real_count;
> +		else
> +			*retval = 0;
>   		break;
>   	default:
>   		*retval = 0;
>

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

Patch

diff --git a/src/cpu/cpufreq/cpufreq.c b/src/cpu/cpufreq/cpufreq.c
index df52100..e115bbb 100644
--- a/src/cpu/cpufreq/cpufreq.c
+++ b/src/cpu/cpufreq/cpufreq.c
@@ -169,7 +169,10 @@  static int get_performance_repeat(
 		*retval = min;
 		break;
 	case GET_PERFORMANCE_AVG:
-		*retval = cumulative / real_count;
+		if (real_count)
+			*retval = cumulative / real_count;
+		else
+			*retval = 0;
 		break;
 	default:
 		*retval = 0;