Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp598160imm; Sat, 22 Sep 2018 06:43:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV63KGHKF5Ik7zMI/39SBha/ncCo9eLXpieZrNem7+L9VJ+9NwMHs+VuwsO1kXbdOLh1D2tK2 X-Received: by 2002:a63:2b4d:: with SMTP id r74-v6mr2412205pgr.406.1537623793590; Sat, 22 Sep 2018 06:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537623793; cv=none; d=google.com; s=arc-20160816; b=syga9f7dWc3qeIOC2t7eJfM4jbqo/qLncza3Gm3iuwLM2x7kQU82gO2Z4EmfoIyE9d 0VYRRvWuhvWlA2tySLfoxroH9nC6jfymgtnzo9Nnu2zeTcBzbSEq+deQjAYM6XHOYYOy cQii/BWp/kBFlNC+XUHq1GBb0xc6ZICx5TVR/UDKe1L3dCVGZv/bhTBlV954wZseVLnx hwv1JBFP/N7BCxLSDIp+kHV3wtCXDoLIOaHASofv9qMAt+bZlY/Xwxya5jcFMKYeFVyh qnmoIPPL5X0fm+aifarKDvb7tFGS19cfmKaAXMJKt1dppJ4BJaHU9AoCDW2Bj9lnjqr/ b6eg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Zh8yQT4JGy6BttTRNkF+NJxP9iu7J6Q0AVCWUPpXLBU=; b=Oo4TjPdTu8Z2lA3Fr6kfoEfsSJXICpthNJofW2aN3uqrJ6+JH93JVzRiqqDDAVU1I/ yNaLUdn8Wx0LX0M0RUN4JF/Q20NlmAr1PdNxQsPEbYOi+6Er0CoYkZ1f/VMe/P3KLcBP teHEAl1XrfHaX40yBDflIyAVkhJTl9UrVC0D5Z8b0edwr1t6n2kf1CqipuqtgiB9LX1K Zpr6rAY4yBXHoN+hgNfFjQVAqpT1s4RsVzF8ptYsPK6QRxmtJb7b129XjKP23JBKfUJL duUXgWGLn2RiDrXoQ3OaViJw+8TtL4UfCCekqsdn5VoTjK4Bk38SwfpL0ntH5IKIWcnU Eo7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="i1BdDL/y"; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v190-v6si1518195pgd.658.2018.09.22.06.42.58; Sat, 22 Sep 2018 06:43:13 -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="i1BdDL/y"; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732053AbeIVTgN (ORCPT + 99 others); Sat, 22 Sep 2018 15:36:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:51074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730601AbeIVTgN (ORCPT ); Sat, 22 Sep 2018 15:36:13 -0400 Received: from archlinux (cpc91196-cmbg18-2-0-cust659.5-4.cable.virginm.net [81.96.234.148]) (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 78178208A3; Sat, 22 Sep 2018 13:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1537623754; bh=BDWoHhL+NDnmGxH+6AYinWut1yIuKevjGbM5rR5QZX0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=i1BdDL/yJJWKengioXbv0k0RNLWJP7IPutzCzsObkHhdQeYJmyZo4cr35rpgf3mbt AvgcBQS54uU/MS4mZycTlHCCPmgSXJlvVLAZRE7v2Cqn1v+bgAzQVxbYGT2OYpvgYR IVsj+zyRILt/Eq+CbkDKTTW0fEIulyBCTGbAZSbA= Date: Sat, 22 Sep 2018 14:42:30 +0100 From: Jonathan Cameron To: "Gustavo A. R. Silva" Cc: Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: adc: Fix potential integer overflow Message-ID: <20180922144230.7d5e6c80@archlinux> In-Reply-To: <20180918125314.GA12752@embeddedor.com> References: <20180918125314.GA12752@embeddedor.com> X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. So that moves it from a fix to a warning suppression change. I have no problem with those, but description needs to reflect that. Let me know if I've missed something, if not I'm happy to apply this and will put some text in the message to explain the above reasoning. Thanks, Jonathan > voltage = div64_s64(voltage, temp); > } else { > voltage = 0;