mlxsw: i2c: Fix buffer increment counter for write transaction
authorVadim Pasternak <vadimp@mellanox.com>
Wed, 1 Nov 2017 11:10:42 +0000 (12:10 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 1 Nov 2017 11:40:58 +0000 (20:40 +0900)
It fixes a problem for the last chunk where 'chunk_size' is smaller than
MLXSW_I2C_BLK_MAX and data is copied to the wrong offset, overriding
previous data.

Fixes: 6882b0aee180 ("mlxsw: Introduce support for I2C bus")
Signed-off-by: Vadim Pasternak <vadimp@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/i2c.c

index 12c3a44491203824ef4eaa51acdee5b91dfdb194..c0dcfa05b0771589631e1c20fa68801622abb6c4 100644 (file)
@@ -294,7 +294,7 @@ mlxsw_i2c_write(struct device *dev, size_t in_mbox_size, u8 *in_mbox, int num,
                write_tran.len = MLXSW_I2C_ADDR_WIDTH + chunk_size;
                mlxsw_i2c_set_slave_addr(tran_buf, off);
                memcpy(&tran_buf[MLXSW_I2C_ADDR_BUF_SIZE], in_mbox +
-                      chunk_size * i, chunk_size);
+                      MLXSW_I2C_BLK_MAX * i, chunk_size);
 
                j = 0;
                end = jiffies + timeout;