From patchwork Tue Sep 18 12:53:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10604347 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 842E36CB for ; Tue, 18 Sep 2018 13:38:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 728122A713 for ; Tue, 18 Sep 2018 13:38:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66D362A727; Tue, 18 Sep 2018 13:38:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11FDC2A713 for ; Tue, 18 Sep 2018 13:38:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729897AbeIRTLW (ORCPT ); Tue, 18 Sep 2018 15:11:22 -0400 Received: from gateway22.websitewelcome.com ([192.185.46.142]:12248 "EHLO gateway22.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729578AbeIRTLW (ORCPT ); Tue, 18 Sep 2018 15:11:22 -0400 X-Greylist: delayed 1506 seconds by postgrey-1.27 at vger.kernel.org; Tue, 18 Sep 2018 15:11:22 EDT Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway22.websitewelcome.com (Postfix) with ESMTP id D0D8D16BC6 for ; Tue, 18 Sep 2018 07:53:17 -0500 (CDT) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id 2FVFgdgguPvAd2FVFgXInW; Tue, 18 Sep 2018 07:53:17 -0500 X-Authority-Reason: nr=8 Received: from [189.250.49.176] (port=37470 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.91) (envelope-from ) id 1g2FVF-000ba4-8I; Tue, 18 Sep 2018 07:53:17 -0500 Date: Tue, 18 Sep 2018 07:53:14 -0500 From: "Gustavo A. R. Silva" To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] iio: adc: Fix potential integer overflow Message-ID: <20180918125314.GA12752@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.250.49.176 X-Source-L: No X-Exim-ID: 1g2FVF-000ba4-8I X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.250.49.176]:37470 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 5 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Cast factor to s64 in order to give the compiler complete information about the proper arithmetic to use and avoid a potential integer overflow. Notice that such variable is being used in a context that expects an expression of type s64 (64 bits, signed). Addresses-Coverity-ID: 1324146 ("Unintentional integer overflow") Fixes: e13d757279bb ("iio: adc: Add QCOM SPMI PMIC5 ADC driver") Signed-off-by: Gustavo A. R. Silva --- drivers/iio/adc/qcom-vadc-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/adc/qcom-vadc-common.c b/drivers/iio/adc/qcom-vadc-common.c index dcd7fb5..e360e27 100644 --- a/drivers/iio/adc/qcom-vadc-common.c +++ b/drivers/iio/adc/qcom-vadc-common.c @@ -282,7 +282,7 @@ static int qcom_vadc_scale_code_voltage_factor(u16 adc_code, voltage = div64_s64(voltage, data->full_scale_code_volt); if (voltage > 0) { voltage *= prescale->den; - temp = prescale->num * factor; + temp = prescale->num * (s64)factor; voltage = div64_s64(voltage, temp); } else { voltage = 0;