Received: by 10.223.185.116 with SMTP id b49csp1751931wrg; Sat, 17 Feb 2018 04:39:40 -0800 (PST) X-Google-Smtp-Source: AH8x226CEkQQzxZh79I795cO01kymV5/iz4FgCVzcQm2+vgRDbUS+4nnvqNtlIF/nW1Ye35uuseP X-Received: by 2002:a17:902:900c:: with SMTP id a12-v6mr8675036plp.330.1518871180276; Sat, 17 Feb 2018 04:39:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518871180; cv=none; d=google.com; s=arc-20160816; b=vRCypsP9QN++LQS+Zgg+8s7rP5G8OgQ2tU/hgu7WyBUMCLCx1zRFOqxkZ4yE5TKDRy mMzMulER3cMmr7U41DwHdTHrbvevR9FImOA+f2uTEeOMkHfXVquZTSoYOHtt+sKWd3Mp zt6OnZu8J0CkvTUwCveEhy9ln1JYeB2CdPDlnyJlkIXhCvzXO5DmSwVSQ4aECrx3m+DK XQ8tsAoFf7hod5J+f5XbX5P8Z3+5FRGl3SKoIXxpPL9vnZNRsdgTzxsff1FWC7EsPN1r ZCyrFSAKvPTYP7I1sf6ZS5eFqaPaXeetmlN0GxVDHXz0AjKrelaknH3su+N1oCHT9VcM atKA== 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 :dmarc-filter:arc-authentication-results; bh=ze4mhSCKNPmo3css+xE6zBiky8QkrEsuG0lbjg7Ob8I=; b=bDoztgSYgJP9WK8YngmBqehyFTqXwjfCOTAcDJ/cp8E6g45c90zGZanmybFKWIQzCT yJSN9CRXpzCLW9e2tXeRkMzaOd9lu3GVAbcS555y6bAiHI6SGqwIs0O/Nm0bI4UdBAwS rlG8y0V65ciJkBXpK04fSCeQ7xJqq9GA/92P7g7CJwUeUzHAYv1nkv+NrIbgbY7ptp9i r40L/BPDe+6EmBaizshS4qsSjmJZdTAj0MCDNyzQc5DK2tZHydeoTTKvRTgwuYji+Efh Pt3Ewmf9sm9ylP3QlPfRZNTxhS3p/6vpgqoJf7HyLfY7ccfLwMNiLMVCGeX46gtW72XF RqiA== 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 n16-v6si5633233pll.360.2018.02.17.04.39.24; Sat, 17 Feb 2018 04:39:40 -0800 (PST) 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 S1751114AbeBQMim (ORCPT + 99 others); Sat, 17 Feb 2018 07:38:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:46372 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750960AbeBQMil (ORCPT ); Sat, 17 Feb 2018 07:38:41 -0500 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 28C14217CA; Sat, 17 Feb 2018 12:38:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 28C14217CA Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=jic23@kernel.org Date: Sat, 17 Feb 2018 12:38:36 +0000 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, Marc Titinger , Stefan =?UTF-8?B?QnLDvG5z?= Subject: Re: [PATCH] iio: adc: ina2xx: Use 64-bit arithmetic instead of 32-bit Message-ID: <20180217123836.61cb3b25@archlinux> In-Reply-To: <20180213165258.GA12967@embeddedor.com> References: <20180213165258.GA12967@embeddedor.com> X-Mailer: Claws Mail 3.16.0 (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, 13 Feb 2018 10:52:58 -0600 "Gustavo A. R. Silva" wrote: > Add suffix ULL to constant 1000 in order to give the compiler complete > information about the proper arithmetic to use. Notice that this > constant is used in a context that expects an expression of type > u64 (64 bits, unsigned). > > The expression 1000 * sampling_us is currently being evaluated > using 32-bit arithmetic. > > Addresses-Coverity-ID: 1463793 > Signed-off-by: Gustavo A. R. Silva I've been trying to figure out if this matters in reality. i.e. whether or not sampling_us is big enough for us to need 64 bit multiplication. It's equal to the output for the macro SAMPLING_PERIOD(c) (int_time_vbus + int_time_vshunt) * avg So taking max values (8244 + 68100) * 1024 = 78176256 Then * 1000 which brings it well into the > 32bit range. So the next question is when was this introduced. I guess it was Stefan's recent patch but haven't checked yet... Marc / Stephan, could you check if we are correct in thinking this is a real bug rather than just a numerical oddity? Thanks, Jonathan > --- > drivers/iio/adc/ina2xx-adc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iio/adc/ina2xx-adc.c b/drivers/iio/adc/ina2xx-adc.c > index 0635a79..8649700 100644 > --- a/drivers/iio/adc/ina2xx-adc.c > +++ b/drivers/iio/adc/ina2xx-adc.c > @@ -810,7 +810,7 @@ static int ina2xx_capture_thread(void *data) > * multiple times, i.e. samples are dropped. > */ > do { > - timespec64_add_ns(&next, 1000 * sampling_us); > + timespec64_add_ns(&next, 1000ULL * sampling_us); > delta = timespec64_sub(next, now); > delay_us = div_s64(timespec64_to_ns(&delta), 1000); > } while (delay_us <= 0);