From e9d1015da91aafef6717913908796380044dde37 Mon Sep 17 00:00:00 2001 From: Vitor Massaru Iha Date: Fri, 26 Jan 2018 20:09:29 -0200 Subject: [PATCH] drivers: i2c: esp32: Fix to_read value on i2c_esp32_read_msg() to_read is the minimum value between I2C_ESP32_BUFFER_SIZE and (msg.len - 1) rather than the maximum value. Signed-off-by: Vitor Massaru Iha --- drivers/i2c/i2c_esp32.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_esp32.c b/drivers/i2c/i2c_esp32.c index 72568373542268..6e651f069f6544 100644 --- a/drivers/i2c/i2c_esp32.c +++ b/drivers/i2c/i2c_esp32.c @@ -423,7 +423,7 @@ static int i2c_esp32_read_msg(struct device *dev, u16_t addr, for (; msg.len; cmd = (void *)I2C_COMD0_REG(config->index)) { volatile struct i2c_esp32_cmd *wait_cmd = NULL; - u32_t to_read = max(I2C_ESP32_BUFFER_SIZE, msg.len - 1); + u32_t to_read = min(I2C_ESP32_BUFFER_SIZE, msg.len - 1); /* Might be the last byte, in which case, `to_read` will * be 0 here. See comment below.