Received: by 10.223.176.5 with SMTP id f5csp884649wra; Tue, 6 Feb 2018 08:58:20 -0800 (PST) X-Google-Smtp-Source: AH8x226D2HejCLftwWrtSzzw9ZtW88JReAQ7AQFEO/J1VQH5/hqIPL6eMwhmNR7xK34ygz/ecMxj X-Received: by 10.99.111.71 with SMTP id k68mr2416782pgc.360.1517936300247; Tue, 06 Feb 2018 08:58:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517936300; cv=none; d=google.com; s=arc-20160816; b=SIppyF+EeKXASGO7TSJ9MSdoVWhqi4DWLDSG5YPPXNN0IzDZRfDLAM0HmLAt6sn1wY oVmhh8iHqV0bEu487AxwP/dGv/DavW4DNQrOLQKTpKTIbGrvG4BeBm2gz84shd0BLnCE E1Y8ryk2y+GSFZbQFH2v+ZxkmXzdpT+zyUkYG4E2iw50q8k5FoOlmJjLuDMdWfITvCmB mCu84zVFdRvHvaMD3dCeqOl00ei0OjygpqKK2KBL9NvjByTOFcJ42jzEgDmxSjjumTkm UO7PljDT3aruQNaPmbdcfQAUCpRRfkYRoB4ROrUphyNB20sSSKgnLryT5Sc8SPOr0Wm+ BmPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=P62GDIS79Dk7Mlte3TqG9gdkQHGBg+6ezOu1kQCZPi0=; b=0v++EfbYmqzbgGUvF9h2Ws4DjjM0RUfzlI7D4cyxp4wtCezbOZhAA8DGwMuRULO68P /qwrHhMAtJZ895fRQL7z08CfBoue6IVyjc4WGgyzChv3KjBD1Cp0KbIDbkXdItlDEEHn VUeioS/S4Ld/8dOE/OCKDgAny4/g9Dr+CekgGblnU2UOquTDlwEmErmcPswYmc3gL9mp Qv0BODSbtoqLsfaO+NS1B8OlxaTqg+QXORW52v6+wX/wrktXyC5MtHUWQnc8okFmekqs yd83/avnK0rKdGHJo8gIQcVhQ4De9M9rMWQ7pgXlj+yI+Qwjt7XU4s6W+EjEPC9lIGyA xXdw== 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 b7si1565351pgq.275.2018.02.06.08.58.06; Tue, 06 Feb 2018 08:58:20 -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 S1753219AbeBFQzb (ORCPT + 99 others); Tue, 6 Feb 2018 11:55:31 -0500 Received: from gateway21.websitewelcome.com ([192.185.45.191]:33359 "EHLO gateway21.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753128AbeBFQxp (ORCPT ); Tue, 6 Feb 2018 11:53:45 -0500 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 41860400E2A76 for ; Tue, 6 Feb 2018 10:53:45 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id j6V7eyNoPzzFjj6V7ec2Wo; Tue, 06 Feb 2018 10:53:45 -0600 Received: from [189.175.4.238] (port=46898 helo=embeddedgus) by gator4166.hostgator.com with esmtpa (Exim 4.89_1) (envelope-from ) id 1ej6V6-000rzF-Qw; Tue, 06 Feb 2018 10:53:44 -0600 Date: Tue, 6 Feb 2018 10:53:44 -0600 From: "Gustavo A. R. Silva" To: Hans Verkuil , Mauro Carvalho Chehab Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH v3 8/8] platform: vivid-cec: use 64-bit arithmetic instead of 32-bit Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) 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: 189.175.4.238 X-Source-L: No X-Exim-ID: 1ej6V6-000rzF-Qw X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedgus) [189.175.4.238]:46898 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 45 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 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 ("Unintentional integer overflow") 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 unnecessary parentheses. - Add code comment. Changes in v3: - Mention the specific Coverity report in the commit message. 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 + * to be evaluated using 64-bit unsigned arithmetic (u64), which + * is what ktime_sub_us expects as second argument. + */ + 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); -- 2.7.4