Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1085710ybl; Wed, 14 Aug 2019 10:27:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqywmWDqR6NKFj0NVlNZxx6cfcc+Bkrna8okxe8c6ch358t4jjwF9ltWnyDPHiVOGhIs4jg1 X-Received: by 2002:a17:902:a606:: with SMTP id u6mr491434plq.224.1565803673870; Wed, 14 Aug 2019 10:27:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803673; cv=none; d=google.com; s=arc-20160816; b=kyLLdwP72kO6Cg/GoL7cxVaiCNM4kSG1/bDxeBPutcf2QBI9Wrkf78fyKQaEyXij0O OcyN3cl3Av4FtixowVXfPKCNX50+DI4rxahB4Qnara9pGeng/kMs/hBoNroOGtDIRzoM I1nv9H8lBzr+azMSTJj0Zj9VDK/nkGbL3s/crIyg/RL8zZt89jq+HPVPiIAkhuc4iqCc n9pD5D4Fwsy6nkqMqytCDNT6ZpC1SNxnbCjafzDj19MvNGEVf9+8k8F6ocWud99mTZDP +WL5iBOXT8zCr8Ru0zA+lrYlrAH/lQqARyrTMRZezWXlNlU4OryNdAQ3M2zR4D9owPx5 gtKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JxhNGYopeU+7A0bL8WaFd8lMwPD5Ni3DhpKLvdNtvrc=; b=evgSM4Sh8ZlUNqO3Pg6bayMgvokxqGphSym7uG49V710XMUzrC3Cb1CTjBVT2cgeSJ gtQyI7t08032BpE7RQfrU8LHdzuLRnqJeRJRod+I4PVbR5YXlSCabMk3Ozw36ypsUk7Z fu9nr0EcS2xlN/q8Eil/SSaBNTsApOEzqEXCeO5ZmJm1qet5N/UoAatBLWJtt99/1+XM fPqLtFzEw1Sbi6eKAs28LyKOvW83gg1sDjhiUBG5zd96fr7DU2SNdCfgGHPb14B5AFde fvxyQXovIl7ejWI66qvC+eqYEc7hIhAdNn2jHC2lHfeX6DLzNZI3vVEq9hqrd5Mid1DI GUrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0KEpdsLh; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si197469pgr.277.2019.08.14.10.27.38; Wed, 14 Aug 2019 10:27:53 -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=@kernel.org header.s=default header.b=0KEpdsLh; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729781AbfHNRZv (ORCPT + 99 others); Wed, 14 Aug 2019 13:25:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:54256 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728882AbfHNRFU (ORCPT ); Wed, 14 Aug 2019 13:05:20 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 649C3208C2; Wed, 14 Aug 2019 17:05:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565802319; bh=JLGDd8bsW7iM4fXbpOOdEbG+zT1Q3Zdh9IXZ5jbNYuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0KEpdsLhkO7dRQGFPBn3mJ8bUqZlzfpb2oOH7R3naHn4cPP/s+uQ5cs15fIoWFLLW gNAmnVlGix6DGhMbSB/54LMt0vdk8CSWel/ZYSfIGnx8FxKtTZrQSiX1ZzNKJa3mjo L2+BUhyGYNqh+AOn+qt1XyjE0z4JzkhLEG7G2aaQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lei YU , Eddie James , Guenter Roeck , Sasha Levin Subject: [PATCH 5.2 079/144] hwmon: (occ) Fix division by zero issue Date: Wed, 14 Aug 2019 19:00:35 +0200 Message-Id: <20190814165803.163212709@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190814165759.466811854@linuxfoundation.org> References: <20190814165759.466811854@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 211186cae14de09573b062e478eb9fe215aed8d9 ] 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. Fixes: c10e753d43eb ("hwmon (occ): Add sensor types and versions") Signed-off-by: Lei YU Reviewed-by: Eddie James Link: https://lore.kernel.org/r/1562813088-23708-1-git-send-email-mine260309@gmail.com Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- 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 13a6290c8d254..f02aa403332c2 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.20.1