[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20190711163548.GA19747@roeck-us.net>
Date: Thu, 11 Jul 2019 09:35:48 -0700
From: Guenter Roeck <linux@...ck-us.net>
To: Lei YU <mine260309@...il.com>
Cc: Jean Delvare <jdelvare@...e.com>,
Eddie James <eajames@...ux.ibm.com>,
"Gustavo A . R . Silva" <gustavo@...eddedor.com>,
linux-hwmon@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] hwmon (occ): Fix division by zero issue
On Thu, Jul 11, 2019 at 10:44:48AM +0800, Lei YU wrote:
> The code in occ_get_powr_avg() invokes div64_u64() without checking the
> divisor. In case the divisor is zero, kernel gets an "Division by zero
> in kernel" error.
>
> Check the divisor and make it return 0 if the divisor is 0.
>
> Signed-off-by: Lei YU <mine260309@...il.com>
> Reviewed-by: Eddie James <eajames@...ux.ibm.com>
Applied.
Thanks,
Guenter
> ---
> drivers/hwmon/occ/common.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
> index 13a6290..f02aa40 100644
> --- a/drivers/hwmon/occ/common.c
> +++ b/drivers/hwmon/occ/common.c
> @@ -402,8 +402,10 @@ static ssize_t occ_show_power_1(struct device *dev,
>
> static u64 occ_get_powr_avg(u64 *accum, u32 *samples)
> {
> - return div64_u64(get_unaligned_be64(accum) * 1000000ULL,
> - get_unaligned_be32(samples));
> + u64 divisor = get_unaligned_be32(samples);
> +
> + return (divisor == 0) ? 0 :
> + div64_u64(get_unaligned_be64(accum) * 1000000ULL, divisor);
> }
>
> static ssize_t occ_show_power_2(struct device *dev,
Powered by blists - more mailing lists