public inbox for linux-i2c@vger.kernel.org
 help / color / mirror / Atom feed
From: Thor Thayer <thor.thayer@linux.intel.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Wolfram Sang <wsa@the-dreams.de>,
	David Laight <David.Laight@ACULAB.COM>
Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] i2c: altera: Fix potential integer overflow
Date: Tue, 11 Feb 2020 13:54:29 -0600	[thread overview]
Message-ID: <4e1127bc-a4f2-fea2-225f-dfb00f0b5a10@linux.intel.com> (raw)
In-Reply-To: <20200211144704.GA6461@embeddedor>

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 <David.Laight@ACULAB.COM>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
> 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 <thor.thayer@linux.intel.com>

  reply	other threads:[~2020-02-11 19:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-11 14:47 [PATCH v2] i2c: altera: Fix potential integer overflow Gustavo A. R. Silva
2020-02-11 19:54 ` Thor Thayer [this message]
2020-02-13  9:09 ` Wolfram Sang
2020-02-13  9:58   ` David Laight

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e1127bc-a4f2-fea2-225f-dfb00f0b5a10@linux.intel.com \
    --to=thor.thayer@linux.intel.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=andy.shevchenko@gmail.com \
    --cc=gustavo@embeddedor.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wsa@the-dreams.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox