Skip to content

Commit 0a2456c

Browse files
anthonytexcarlescufi
authored andcommitted
i2c_imx: Fix system fault when there is no data to send
When there is no data to send (e.g. i2c message with NULL buffer and len=0), i2c_imx driver locks itself in isr handling forever. So if there is no data to send, only device's address must be written on bus. This fixes i2c_shell's scan command on both imx7 and imx6sx. Signed-off-by: Antonio Tessarolo <[email protected]>
1 parent fbee6cc commit 0a2456c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/i2c/i2c_imx.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,15 @@ static int i2c_imx_transfer(const struct device *dev, struct i2c_msg *msgs,
233233
}
234234

235235
/* Transfer data */
236-
buf = msgs->buf;
237-
buf_end = buf + msgs->len;
238-
if ((msgs->flags & I2C_MSG_RW_MASK) == I2C_MSG_READ) {
239-
i2c_imx_read(dev, msgs->buf, msgs->len);
240-
} else {
241-
if (!i2c_imx_write(dev, msgs->buf, msgs->len)) {
242-
goto finish; /* No ACK received */
236+
if (msgs->len) {
237+
buf = msgs->buf;
238+
buf_end = buf + msgs->len;
239+
if ((msgs->flags & I2C_MSG_RW_MASK) == I2C_MSG_READ) {
240+
i2c_imx_read(dev, msgs->buf, msgs->len);
241+
} else {
242+
if (!i2c_imx_write(dev, msgs->buf, msgs->len)) {
243+
goto finish; /* No ACK received */
244+
}
243245
}
244246
}
245247

0 commit comments

Comments
 (0)