Return-Path: Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=eajames@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45j8GY71FqzDqRL for ; Tue, 9 Jul 2019 01:18:13 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x68FGMmw146754 for ; Mon, 8 Jul 2019 11:18:09 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2tm7ynh41j-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 08 Jul 2019 11:18:09 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 8 Jul 2019 16:18:08 +0100 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 8 Jul 2019 16:18:06 +0100 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x68FI5BQ30605656 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 8 Jul 2019 15:18:06 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2C0F7805C; Mon, 8 Jul 2019 15:18:05 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A7B257805E; Mon, 8 Jul 2019 15:18:05 +0000 (GMT) Received: from [9.41.179.222] (unknown [9.41.179.222]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Mon, 8 Jul 2019 15:18:05 +0000 (GMT) Subject: Re: [PATCH linux dev-5.1] hwmon (occ): Fix division by zero issue To: Lei YU , openbmc@lists.ozlabs.org References: <1562574721-125584-1-git-send-email-mine260309@gmail.com> From: Eddie James Date: Mon, 8 Jul 2019 10:18:05 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1562574721-125584-1-git-send-email-mine260309@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 19070815-0016-0000-0000-000009CBBA18 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00011397; HX=3.00000242; KW=3.00000007; PH=3.00000004; SC=3.00000286; SDB=6.01229255; UDB=6.00647379; IPR=6.01010515; MB=3.00027634; MTD=3.00000008; XFM=3.00000015; UTC=2019-07-08 15:18:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19070815-0017-0000-0000-000043F04770 Message-Id: <2a9ffe98-e190-fe7b-b6d0-2123dadcf551@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-07-08_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1907080190 X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jul 2019 15:18:15 -0000 On 7/8/19 3:32 AM, 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. Thanks! Reviewed-by: Eddie James > > Signed-off-by: Lei YU > --- > 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 e9d7167..15c5d43 100644 > --- a/drivers/hwmon/occ/common.c > +++ b/drivers/hwmon/occ/common.c > @@ -406,8 +406,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,