Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5331991ybv; Tue, 11 Feb 2020 13:41:13 -0800 (PST) X-Google-Smtp-Source: APXvYqxSNXIRrxPQOC7c34gqS39AQXv7eznHomzoE9YpGicZsaddNZB/A6kEG/7G+kOKDZMre0q8 X-Received: by 2002:a9d:7508:: with SMTP id r8mr6856884otk.116.1581457273404; Tue, 11 Feb 2020 13:41:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581457273; cv=none; d=google.com; s=arc-20160816; b=HtBbXvhJ9hBcsEsgbI5pGRBxvn6lIVDBAW+7XyjUpFm/MsU8pH3Rl7ocbN6oYIb0sK UuTC+bzuqMr6uWV+dq1aAT0moNYuhaHvPM7nJ650z66gvJruxnZOh6HvglRx/56Uc3iw ipKIAZzxFrX/cIXyMJSyj1fEu8rJloIPAevFcbajCkwDrDKLVo5zOkUfgEfsEuYEukJu pevydNvkTpbD6a+2E7ywgVjts1U1Sv9jBluvt715WndnmAw8J6fSp3HDzkRm1yPG57Sn kiRcyg1YfHD2WfRcMCHNLOK7XkNxWs+D+T2TsgOOOOd2SixArWn1JNjTYPzF+hs1gREs ZTzA== 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:reply-to; bh=tGjV8lhcP5XBDlrj6i3x3QDnU/jF6EQQDjLY9etLfKU=; b=MOn24oUAwmpzrfPw2UFf5pam8AjtW6GyUT1nuMIpXD0kOFfedRfTDDMZepowx4e2fz meV34r/Ci5/IUxq1Y1cgJyfp1J6Sq0ufppyLebQKiFxEBd1M0x3ut+aKZnout1J5PVH/ R9xYUAE96kUJe/v4mJ4ps8uvXOtViUNoy9vEqBuiGWb3OookYlxnJhPX1BWcdLz65+GD SuIStTw22fJV9gnuQY9toW1ADndU7uK+D25blDr57wqbcIml8hgH1+ztEjRq0ZpxIHa6 0xVQjWhqbVR6wIOTZBRpOQd7Qo1PVf78+gwBktFxBP1KkZ7L9CdK/lkuBrQFld7cngT5 SqLQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a12si2345477oid.189.2020.02.11.13.41.01; Tue, 11 Feb 2020 13:41:13 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730812AbgBKTwW (ORCPT + 99 others); Tue, 11 Feb 2020 14:52:22 -0500 Received: from mga09.intel.com ([134.134.136.24]:40698 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730182AbgBKTwW (ORCPT ); Tue, 11 Feb 2020 14:52:22 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Feb 2020 11:52:21 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,428,1574150400"; d="scan'208";a="347346714" Received: from tthayer-hp-z620.an.intel.com (HELO [10.122.105.146]) ([10.122.105.146]) by fmsmga001.fm.intel.com with ESMTP; 11 Feb 2020 11:52:21 -0800 Reply-To: thor.thayer@linux.intel.com Subject: Re: [PATCH v2] i2c: altera: Fix potential integer overflow To: "Gustavo A. R. Silva" , Andy Shevchenko , Wolfram Sang , David Laight Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200211144704.GA6461@embeddedor> From: Thor Thayer Message-ID: <4e1127bc-a4f2-fea2-225f-dfb00f0b5a10@linux.intel.com> Date: Tue, 11 Feb 2020 13:54:29 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200211144704.GA6461@embeddedor> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/11/20 8:47 AM, Gustavo A. R. Silva wrote: > Factor out 100 from the equation and do 32-bit arithmetic (3 * clk_mhz / 10) > instead of 64-bit. > > Notice that clk_mhz is MHz, so the multiplication will never wrap 32 bits > and there is no need for div_u64(). > > Addresses-Coverity: 1458369 ("Unintentional integer overflow") > Fixes: 0560ad576268 ("i2c: altera: Add Altera I2C Controller driver") > Suggested-by: David Laight > Signed-off-by: Gustavo A. R. Silva > --- > Changes in v2: > - Update subject and changelog text. > - Avoid the need for 64-bit arithmetic at all. > > drivers/i2c/busses/i2c-altera.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/i2c/busses/i2c-altera.c b/drivers/i2c/busses/i2c-altera.c > index 5255d3755411..1de23b4f3809 100644 > --- a/drivers/i2c/busses/i2c-altera.c > +++ b/drivers/i2c/busses/i2c-altera.c > @@ -171,7 +171,7 @@ static void altr_i2c_init(struct altr_i2c_dev *idev) > /* SCL Low Time */ > writel(t_low, idev->base + ALTR_I2C_SCL_LOW); > /* SDA Hold Time, 300ns */ > - writel(div_u64(300 * clk_mhz, 1000), idev->base + ALTR_I2C_SDA_HOLD); > + writel(3 * clk_mhz / 10, idev->base + ALTR_I2C_SDA_HOLD); > > /* Mask all master interrupt bits */ > altr_i2c_int_enable(idev, ALTR_I2C_ALL_IRQ, false); > Reviewed-by: Thor Thayer