From 9f0ca750f8949f83e2beac93e92383de4586ede2 Mon Sep 17 00:00:00 2001 From: Tony Han Date: Mon, 14 Apr 2025 10:38:01 +0800 Subject: [PATCH] drivers: i2c: sam: fix the exception when transferring without data The issue is found when doing shell command "i2c scan" on sama7g54-ek. In this case no data will be transferred besides START and STOP. Data abort would occur on accessing "msg->buf[msg->idx++]" when MMU is enabled and "msg->idx" is very large. Signed-off-by: Tony Han --- drivers/i2c/i2c_sam_twi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c_sam_twi.c b/drivers/i2c/i2c_sam_twi.c index c652e795b22..f7166edc284 100644 --- a/drivers/i2c/i2c_sam_twi.c +++ b/drivers/i2c/i2c_sam_twi.c @@ -293,7 +293,7 @@ static void i2c_sam_twi_isr(const struct device *dev) /* Byte sent */ if (isr_status & TWI_SR_TXRDY) { - if (msg->idx == msg->len) { + if (msg->idx == msg->len || msg->len == 0) { if (msg->flags & I2C_MSG_STOP) { /* Send a STOP condition on the TWI */ twi->TWI_CR = TWI_CR_STOP;