ACK: [PATCH] cpu: cpufreq: avoid division by zero

Alex Hung alex.hung at canonical.com
Thu May 9 06:09:16 UTC 2013


On 05/07/2013 07:41 AM, Colin King wrote:
> From: Colin Ian King <colin.king at 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 at 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 at canonical.com>



More information about the fwts-devel mailing list