Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2813445imm; Mon, 24 Sep 2018 10:19:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV60OevTqAY0UQXlTUR47rTq2tvdcxWujpDcQB7GvvfkKUxmDMiGwlp9/gB8EmtQmz/1YAmDQ X-Received: by 2002:a17:902:900a:: with SMTP id a10-v6mr11552569plp.143.1537809546209; Mon, 24 Sep 2018 10:19:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537809546; cv=none; d=google.com; s=arc-20160816; b=RM4jsU74EZoS9SVJx1TbNqaUPaeNEcMKDt4osOGTuKYLUNHvFabjEeONKmR2XvJP0N FAZeAXKi2yKLfj6BN90o6GsufqEqOLIn/Z8ReH5Gm1P1vKxK5Y53Ev7kij0+uFkGxkAK 2x8on4HpxwIp9eeZWJUwtViGEMMgr3ySbvN4ThhX2IAZ3U8IryqM9WN4CLsBUYYARgxx 4ua0+Ltessm9h1S9ZA8L50LUJ3iR2rkQZD+pPc5kL/GZi+bMRf6bQTKnRLIojqlrigKo QP5iF8l2qpAHJLc26p7qodmmzRKveB2gysPjhHWcSk/9vt7WCKfbd07yaCCaCFEZPkFr xiLw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=AKK0tRGVrNd5swX8F+Wwkl9bLVUoCNiqCMc9E1U+juQ=; b=QCmPRw3e5a6cW97ofo1vYipOryyieDoEVhQmZe5GBX03r6rS4qosGWnQK6IPnKaRxO Zqf2fQFNCGOJ6SoUEcKxzd2gIrMom/ZgOioWXvj/Q0+1Hul7LQ6oboIYZgsgwmTRoSFK 6qPDtLaErnJ3+7Hb5A6pRLxA9rxE1KVFalk1TFeEYOwfR9ICpwWBY6NNal/xcx5vgYlb liXf7tDOvivDGZ1wWVU54LUUo95FeaGBPULKJCW6uqaMoyP5Zm8+1ShgTxsgvsxzgfp1 oV+8oycLLmaTSwG7BZkIyT7dXXaj8cClXShZcbDOwzxXX25MyWz9XY4l9x/7g2i8YT4C Vj6w== ARC-Authentication-Results: i=1; mx.google.com; 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 ba6-v6si35209416plb.364.2018.09.24.10.18.50; Mon, 24 Sep 2018 10:19:06 -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; 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 S1732908AbeIXXVi (ORCPT + 99 others); Mon, 24 Sep 2018 19:21:38 -0400 Received: from www381.your-server.de ([78.46.137.84]:49108 "EHLO www381.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728758AbeIXXVi (ORCPT ); Mon, 24 Sep 2018 19:21:38 -0400 Received: from [78.46.172.2] (helo=sslproxy05.your-server.de) by www381.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1g4UV5-0003SI-4M; Mon, 24 Sep 2018 19:18:23 +0200 Received: from [188.174.126.27] (helo=[192.168.178.22]) by sslproxy05.your-server.de with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89) (envelope-from ) id 1g4UV4-000V1l-U5; Mon, 24 Sep 2018 19:18:23 +0200 Subject: Re: [PATCH] iio: adc: Fix potential integer overflow To: Jonathan Cameron , "Gustavo A. R. Silva" Cc: Hartmut Knaack , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org References: <20180918125314.GA12752@embeddedor.com> <20180922144230.7d5e6c80@archlinux> From: Lars-Peter Clausen Message-ID: Date: Mon, 24 Sep 2018 19:18:22 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180922144230.7d5e6c80@archlinux> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.100.1/24981/Mon Sep 24 15:50:40 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/22/2018 03:42 PM, Jonathan Cameron wrote: > On Tue, 18 Sep 2018 07:53:14 -0500 > "Gustavo A. R. Silva" wrote: > >> 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; > So factor is an unsigned int so could be 32 bits. In reality it only > takes a small set of values between 1 and 1000 > > Maximum numerator is 10 so a maximum of 10,000. > > Hence this is a false positive, be it one that would be very hard > for a static checker to identify. I think the reason why it complains is because temp is s64. So it infers that the idea was that the result of the multiplication can be larger than 64 bit. For 32bit * 32bit -> 32bit it should not complain. > > So that moves it from a fix to a warning suppression change. > I have no problem with those, but description needs to reflect that. Maybe just change the type of temp to u32. There is also mul_u64_u32_div() which could be used here to further simplify things.