Received: by 10.223.176.5 with SMTP id f5csp3000853wra; Mon, 5 Feb 2018 13:56:36 -0800 (PST) X-Google-Smtp-Source: AH8x22462MvFlP4cxrZ8dLlDv1ClItEVq+saCrBuhqWKtcNIgn+Ypvy/533E/RGgRwgOnMroyWlX X-Received: by 2002:a17:902:678b:: with SMTP id g11-v6mr227457plk.13.1517867796250; Mon, 05 Feb 2018 13:56:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517867796; cv=none; d=google.com; s=arc-20160816; b=YcOg1zyuF8FPaaW0rhrL23FWmIhMsSKIuxLqAu0LKOsQqeSahlN4BDjFC51dhhtkQT lth+jgctPIhRv2wJfZZJvHcc8f39w2cK8j58akPmRfXgNrEADUgI9jHIYZWLrQSB3aPz VOYtaX5qlWixYEAlcUr8ILyCczWDLXAT3zm9BnSRlR/yssB8czh8/SuFv8gpZphsUSyR jGwn8OV9Z1h9/bXRgpPr8KTmvBC+eaSqBYum/zhUzB5Bkl14sHM0z4VJzxAfnpnM04Xu jPd4F5Mf7MG4N9YavIBWoyZmxfXmKbaHHS51x/skRq2jlhoHAizqlrDjMaG4RLECeJF9 zuPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :user-agent:in-reply-to:references:subject:cc:to:from:message-id :date:arc-authentication-results; bh=SJk5AmgPlCHbXuyl1DLPMTcjJsFfrQWIG1lZB/xRTo8=; b=uSXpl6lP+otqRT9aCBXG9B5CJXVmelmGZ9ZK14ECPk6SzcsEXLS2mfk4jTp4qure28 s3dPCFWa/AjfwXgD44z/hnZgxEQkTaUrD4oGkCggdgUTG/8xnnt57hoEsOazQ40O+qcL lzPHHIGTpuRerN+W73DPV7G8L15iJV7reolO3g7so/lcf8C3tdN34Pyr3ufFlY47mQtd C/9RXPjoPLKN8EazurR1+g5XOqtNgmYjSiYHEY51mShjYwK6uwdcip+QmPEdMPTrLEo+ a4cRs1LTfqYjv2xeK3hCsSqS7zXcJwiAjeQ5RZpgo8QpwbqykEY2KyWfceRs7Pju8U6X eNNQ== 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 w10si269816pgc.656.2018.02.05.13.56.21; Mon, 05 Feb 2018 13:56:36 -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 S1752126AbeBEVy1 (ORCPT + 99 others); Mon, 5 Feb 2018 16:54:27 -0500 Received: from gateway34.websitewelcome.com ([192.185.149.105]:41184 "EHLO gateway34.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751960AbeBEVyV (ORCPT ); Mon, 5 Feb 2018 16:54:21 -0500 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway34.websitewelcome.com (Postfix) with ESMTP id 26DB31F124B for ; Mon, 5 Feb 2018 15:54:20 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id ioiSerARyODN4ioiSelZG3; Mon, 05 Feb 2018 15:54:20 -0600 Received: from gator4166.hostgator.com ([108.167.133.22]:46053) by gator4166.hostgator.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1eioiS-000RVZ-6v; Mon, 05 Feb 2018 15:54:20 -0600 Received: from 189.152.201.65 ([189.152.201.65]) by gator4166.hostgator.com (Horde Framework) with HTTPS; Mon, 05 Feb 2018 15:54:19 -0600 Date: Mon, 05 Feb 2018 15:54:19 -0600 Message-ID: <20180205155419.Horde.WgpJoLkqF8wsBtPMp9n7V8U@gator4166.hostgator.com> From: "Gustavo A. R. Silva" To: Hans Verkuil Cc: "Gustavo A. R. Silva" , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 8/8] platform: vivid-cec: use 64-bit arithmetic instead of 32-bit References: In-Reply-To: User-Agent: Horde Application Framework 5 Content-Type: text/plain; charset=utf-8; format=flowed; DelSp=Yes MIME-Version: 1.0 Content-Disposition: inline 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: 108.167.133.22 X-Source-L: Yes X-Exim-ID: 1eioiS-000RVZ-6v X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: gator4166.hostgator.com [108.167.133.22]:46053 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 1 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Hans, Quoting Hans Verkuil : > On 02/05/2018 09:36 PM, Gustavo A. R. Silva wrote: >> Add suffix ULL to constant 10 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 len * 10 * CEC_TIM_DATA_BIT_TOTAL is currently being >> evaluated using 32-bit arithmetic. >> >> Also, remove unnecessary parentheses and add a code comment to make it >> clear what is the reason of the code change. >> >> Addresses-Coverity-ID: 1454996 >> Signed-off-by: Gustavo A. R. Silva >> --- >> Changes in v2: >> - Update subject and changelog to better reflect the proposed code changes. >> - Add suffix ULL to constant instead of casting a variable. >> - Remove unncessary parentheses. > > unncessary -> unnecessary > Thanks for this. >> - Add code comment. >> >> drivers/media/platform/vivid/vivid-cec.c | 11 +++++++++-- >> 1 file changed, 9 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/media/platform/vivid/vivid-cec.c >> b/drivers/media/platform/vivid/vivid-cec.c >> index b55d278..614787b 100644 >> --- a/drivers/media/platform/vivid/vivid-cec.c >> +++ b/drivers/media/platform/vivid/vivid-cec.c >> @@ -82,8 +82,15 @@ static void vivid_cec_pin_adap_events(struct >> cec_adapter *adap, ktime_t ts, >> >> if (adap == NULL) >> return; >> - ts = ktime_sub_us(ts, (CEC_TIM_START_BIT_TOTAL + >> - len * 10 * CEC_TIM_DATA_BIT_TOTAL)); >> + >> + /* >> + * Suffix ULL on constant 10 makes the expression >> + * CEC_TIM_START_BIT_TOTAL + 10ULL * len * CEC_TIM_DATA_BIT_TOTAL >> + * be evaluated using 64-bit unsigned arithmetic (u64), which >> + * is what ktime_sub_us expects as second argument. >> + */ > > That's not really the comment that I was looking for. It still doesn't > explain *why* this is needed at all. How about something like this: > In MHO the reason for the change is simply the discrepancy between the arithmetic expected by the function ktime_sub_us and the arithmetic in which the expression is being evaluated. And this has nothing to do with any particular tool. > /* > * Add the ULL suffix to the constant 10 to work around a false Coverity > * "Unintentional integer overflow" warning. Coverity isn't smart enough > * to understand that len is always <= 16, so there is no chance of an > * integer overflow. > */ > :P In my opinion it is not a good idea to tie the code to a particular tool. There are only three appearances of the word 'Coverity' in the whole code base, and, honestly I don't want to add more. So I think I will document this issue as a FP in the Coverity platform. Thanks! -- Gustavo > Regards, > > Hans > >> + ts = ktime_sub_us(ts, CEC_TIM_START_BIT_TOTAL + >> + 10ULL * len * CEC_TIM_DATA_BIT_TOTAL); >> cec_queue_pin_cec_event(adap, false, ts); >> ts = ktime_add_us(ts, CEC_TIM_START_BIT_LOW); >> cec_queue_pin_cec_event(adap, true, ts); >>