Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9911811ybi; Wed, 10 Jul 2019 19:47:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwpnlhXVrXsnIqT5Y0KexGhlvUNI8McRVo62KFFCVC81/zNVcmS1BPXB49LNHCSlnV1LNlf X-Received: by 2002:a63:df46:: with SMTP id h6mr1692826pgj.181.1562813229313; Wed, 10 Jul 2019 19:47:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562813229; cv=none; d=google.com; s=arc-20160816; b=Fyz3cYjGYqy/QbNcE/klE7wQbq2jTd7LbnUnDNe/OBs0N7JDuGE4TZlLx6n7HhRJ3R jbffkhyCoyhjaAFTZcBxTsSjPk89Bf1+F1OJQ1FXFLNjmmkYBC22/L++kgVYfRK0UOqN satPzvrA7RcqhHMI0vLHBopttcym4bvAQR2aBFz2ZHzuBsNAq0I8rPD/tF7scwbmIcO6 czt7pS9XfUlXshVu8j4y+O0v3uChjec3x3W26uDB49x6ExRfRo3nIkF+QstBlC84KxhE Ox/NUb50cdPBLuxxPuFkmpzrcerq1lG+XYtTx7F1EpmnDssy3R6gKImymFLtfWpbcBeo 1m1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from :dkim-signature; bh=Qbv2ajCJoybKSCHk6U34S4w3N5YXbwdABLrNyMIOFjU=; b=GMmB5gsdtPrndyqd5TtCLsh/Vua1m/Un/UAVLXb247pHoqhS5FC3/+2PXPhGqmcMBK ysysXvZFhIbg7UWc7jXvy1+mSNlcChamu7ltEGtTUs0n3izSSUEY2M0BJmzICxeuayAh 18DcSCG+GIE//RtbdRvJtr15rAfmGUOxtSxm6SqwnE8xQfqw7tcU/ANKdWXgkg+0VHg/ enc6WbBLdnoEy22nBuIaDW56amq6Fv+lyKAVaik87hdKJCj2wyud0I7wgcrapxKEbwhI KLqDa8bAk7uqMMwBOYffHEisT5qrpNtW+tkAUt0l9sSy5Q0hn7mqGQ6DShrympoA9EFW 0GMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="OmKI/1OY"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si4007647pgi.257.2019.07.10.19.46.53; Wed, 10 Jul 2019 19:47:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="OmKI/1OY"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727016AbfGKCpS (ORCPT + 99 others); Wed, 10 Jul 2019 22:45:18 -0400 Received: from mail-ot1-f68.google.com ([209.85.210.68]:42501 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725977AbfGKCpR (ORCPT ); Wed, 10 Jul 2019 22:45:17 -0400 Received: by mail-ot1-f68.google.com with SMTP id l15so4311782otn.9; Wed, 10 Jul 2019 19:45:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=Qbv2ajCJoybKSCHk6U34S4w3N5YXbwdABLrNyMIOFjU=; b=OmKI/1OYqrb+UnpZfqjLqOfdc/u9TGckIXOgROvKJxlQGt2A1Kx6qHJtEphheqRMfY 76AEcQ9Q/eeMFGaVSM2n4B6b7pOrtVAZEZekEPdYWpVrsHilu9raJQMROtOniHxmcpVK VolYLvRFmskpXHA5KGsOILvPBTWQvSTK7f5zzpjHW+IoKkGDhNIjkEUhO/R64Zpx0T07 kX41HG/EPmTpT6KTVeegZB1crm1C3TFq+TFprVuzsqB0buNcWVEFwIb0ugcWSnVQxcvQ v1VohMm9Nkh4av+aWhd/Cjr4cAtIFgOdH+5S7FDZ7JQ0HAmOy2HK6OQsscNBo4GzR6zy +Tpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Qbv2ajCJoybKSCHk6U34S4w3N5YXbwdABLrNyMIOFjU=; b=ik5cycMTRjT/kgb9XGlS5bL6jdF3RN6VYr5+mxrDuZcCNgqIE5ppjb69C0ZJ2YEiC/ Fo8KAN5ZYhAY2ZoVtpdz/3DZ4hsK2d4spLSqkmXCBVTDCy/5bYATvLi7eCu/HY1cQztF EERnjvpMHYilHL+e+COzP6nUjFSoIKWdZC0EkAp9TCHaA7bTnNprSsBHfZv8jEMgO8GR QaIKI3nHnrtyZdeK5qedrVK3yP5nIo0yaxaEEBWmO8bC5XQrkMUDzVNakjFJVwhkT1l9 D2TG+sIOkac3c0nyMFkmzhsHtYH+oHM4sYwvs1+ftha2NYq7/P2+c8Gq2pLmr00gU0oM +zJQ== X-Gm-Message-State: APjAAAX5LOi99a6+pOC+3wDAwgiqyxKK/hLNMtEqwXKUAZDSRFZIzGdD 0VgGuvfXl9PN4PeTVwMRewI= X-Received: by 2002:a9d:6659:: with SMTP id q25mr1354219otm.272.1562813116651; Wed, 10 Jul 2019 19:45:16 -0700 (PDT) Received: from localhost ([76.224.107.173]) by smtp.gmail.com with ESMTPSA id j5sm1426216oih.52.2019.07.10.19.45.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Jul 2019 19:45:15 -0700 (PDT) From: Lei YU To: Jean Delvare , Guenter Roeck , Eddie James , "Gustavo A . R . Silva" , Lei YU , linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] hwmon (occ): Fix division by zero issue Date: Thu, 11 Jul 2019 10:44:48 +0800 Message-Id: <1562813088-23708-1-git-send-email-mine260309@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Eddie James --- 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, -- 2.7.4