Skip to content

Commit 54498e8

Browse files
GustavoARSilvaWolfram Sang
authored andcommitted
i2c: altera: Fix potential integer overflow
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: 0560ad5 ("i2c: altera: Add Altera I2C Controller driver") Suggested-by: David Laight <[email protected]> Signed-off-by: Gustavo A. R. Silva <[email protected]> Reviewed-by: Thor Thayer <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 9e661ce commit 54498e8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/i2c/busses/i2c-altera.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void altr_i2c_init(struct altr_i2c_dev *idev)
171171
/* SCL Low Time */
172172
writel(t_low, idev->base + ALTR_I2C_SCL_LOW);
173173
/* SDA Hold Time, 300ns */
174-
writel(div_u64(300 * clk_mhz, 1000), idev->base + ALTR_I2C_SDA_HOLD);
174+
writel(3 * clk_mhz / 10, idev->base + ALTR_I2C_SDA_HOLD);
175175

176176
/* Mask all master interrupt bits */
177177
altr_i2c_int_enable(idev, ALTR_I2C_ALL_IRQ, false);

0 commit comments

Comments
 (0)