Received: by 10.223.176.5 with SMTP id f5csp2981061wra; Mon, 5 Feb 2018 13:31:28 -0800 (PST) X-Google-Smtp-Source: AH8x227ai3yxtUPGhmyjz4Na76PVRH4rMdiKjsKzi+RuzN8MwfjdjF0LFnv5itVc79Jik8q1ujcO X-Received: by 2002:a17:902:a711:: with SMTP id w17-v6mr155940plq.299.1517866288387; Mon, 05 Feb 2018 13:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517866288; cv=none; d=google.com; s=arc-20160816; b=CM7TvZqF4KgiZuWE0HUw/YUmJ2C63QI2C0G53/qhWHIwqD5MT04UBf1dVGEv/S5vwh YrdutwikWB+preObDSBJjkZGW4US947NtURoJK7xdtz9YGCiOwjSrYslrcYGZQ1O0WgQ sbcJV9qagMuo47632xbaGfHOPzJf8Ypkj1fNgIVm0nmjfgnpurUFpQG7eplFCWSuaqOq 5qJ2HGc2/lqpBKQHaltXVOeI83QaNEk3Em9TVm0EQt78vBsBHlc2NFoWH1RiQiBr3Duh EIgUyDiYu23YpYDI43V5sITiTZH+QqHtRMT0nlbqMLT4m7tnAlsOTUowBrbk3l70OJhl ElXg== 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:arc-authentication-results; bh=Qi24097tIn2TJzGzvxMdQ924TGCkAvzwIWB3MkMPxZI=; b=S/eJpRTvswJLFdIP0d7AUe/xeqCdmZwWoyORYjKiIT196mJUVlKmcK3GFnIZvmPPBR SfIZKeYFkgBqBmbnEhgFlAt3PFyOWgpgvJcQYAuTZ4Mb/2CjA3nV+6Gr3xrHi1Llhawn W6Xh2AHQJVst/Xr6LtbNm/7+wwMWfFx0wuo4to1gbtyw4eBvO+tPMz5jMkd0E81SZT8q Srgas3YyrxSVgyjeCep0mtT2D+FnoL9cKTbAB4NWiyUmz40wvirP3R0Way7V+kUyTAys +LgUlY2b4YoQLB9RMeLBrLclipSzULUxYi6w8r3FcVzKo+rSNYjEiVh0l+/NyqiH0Txu XBsA== 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 b1si2445801pgf.814.2018.02.05.13.31.13; Mon, 05 Feb 2018 13:31:28 -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 S1752125AbeBEV3y (ORCPT + 99 others); Mon, 5 Feb 2018 16:29:54 -0500 Received: from lb1-smtp-cloud9.xs4all.net ([194.109.24.22]:33406 "EHLO lb1-smtp-cloud9.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752013AbeBEV3q (ORCPT ); Mon, 5 Feb 2018 16:29:46 -0500 Received: from [192.168.2.10] ([212.251.195.8]) by smtp-cloud9.xs4all.net with ESMTPA id ioKbeLXOaoWCOioKeetdMX; Mon, 05 Feb 2018 22:29:45 +0100 Subject: Re: [PATCH v2 8/8] platform: vivid-cec: use 64-bit arithmetic instead of 32-bit To: "Gustavo A. R. Silva" , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" References: From: Hans Verkuil Message-ID: Date: Mon, 5 Feb 2018 22:29:41 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfN605l3ac8mNQiNNZABXLf05QktavD4yZAf1OHxWbT19NR0F0g+WusvhjN2FXjdA13K5Ukxu4b1hChjPt3+5fLIaweyrqi3hBdiADK0uet/tXQq00IBA zqfeg0tOUjyEZioktAj4h2BG6pnzTAhjDvMbqoNXX/tJuGcOHR9JX8YYNr5xq0jqlY6lm49c/9Z+2vIonINa/y7yAcrNycPPfA+AKJA8c3frBuywNWA30zmD TG4gKdq9jDVSfvgSz4tTgxe29BrTI466mad+Aq2G57+eMNCIxGcVh1AoBA8Hf/8gC/815o5OHrjZEbXn2QyLPA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > - 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: /* * 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. */ 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); >