Skip to contentSkip to conversation

i2c: imx: keep the error of a failed read

PATCH In review Mehmet Fide 2 participants 2 messages Nov 16

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: imx: keep the error of a failed read

From: Mehmet Fide <[email protected]>

When the count byte of an SMBus block read is larger than I2C_SMBUS_BLOCK_MAX, i2c_imx_isr_read_block_data_len() sets -EPROTO and fails the read. The read of I2DR that took the count byte has started the reception of one more byte, and its interrupt comes in while the state is IMX_I2C_STATE_FAILED. i2c_imx_master_isr() has no case for that state, so the default case replaces -EPROTO with -EINVAL.

Ignore interrupts in IMX_I2C_STATE_FAILED so that the first error is returned.

Fixes 5f5c2d4579ca ("i2c: imx: prevent rescheduling in non dma mode")

---

Notes:
Tested on a Colibri VF50 on the Iris carrier, kernel at this base plus "i2c: imx: acknowledge the count byte of an atomic block read" and "i2c: imx: do not acknowledge the last byte of a block read of one byte", with the M41T0 RTC at 0x68. A test-only hook passed the messages that i2c_smbus_xfer_emulated() builds for a block read to the adapter, alone and followed by a one byte read. Register 0x03 (0xae) as count
byte: without the patch -EINVAL 40 of 40, and a print in the default case showed state IMX_I2C_STATE_FAILED with -EPROTO each time; with it -EPROTO 100 of 100, as the atomic read returns. Count bytes of 0, 1 and 0x13 read the same bytes as before, and the bus works after each failed read.

 drivers/i2c/busses/i2c-imx.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-imx.c +3 -0
index ccf08cd63151..c7fef98934d4 100644
@@ -1142,6 +1142,9 @@ static irqreturn_t i2c_imx_master_isr(struct imx_i2c_struct *i2c_imx, unsigned i
 		wake_up(&i2c_imx->queue);
 		break;
 
+	case IMX_I2C_STATE_FAILED:
+		break;
+
 	default:
 		i2c_imx->i2csr = status;
 		i2c_imx->state = IMX_I2C_STATE_FAILED;

base-commit: 25e7ab89f4774b0f842cee0e8a20c11f755924d5

Signature · 1 line
2.56.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 47 lines · Mehmet Fide

From: Mehmet Fide <[email protected]>

When the count byte of an SMBus block read is larger than I2C_SMBUS_BLOCK_MAX, i2c_imx_isr_read_block_data_len() sets -EPROTO and fails the read. The read of I2DR that took the count byte has started the reception of one more byte, and its interrupt comes in while the state is IMX_I2C_STATE_FAILED. i2c_imx_master_isr() has no case for that state, so the default case replaces -EPROTO with -EINVAL.

Ignore interrupts in IMX_I2C_STATE_FAILED so that the first error is returned.

Fixes 5f5c2d4579ca ("i2c: imx: prevent rescheduling in non dma mode")

---

Notes:
Tested on a Colibri VF50 on the Iris carrier, kernel at this base plus "i2c: imx: acknowledge the count byte of an atomic block read" and "i2c: imx: do not acknowledge the last byte of a block read of one byte", with the M41T0 RTC at 0x68. A test-only hook passed the messages that i2c_smbus_xfer_emulated() builds for a block read to the adapter, alone and followed by a one byte read. Register 0x03 (0xae) as count
byte: without the patch -EINVAL 40 of 40, and a print in the default case showed state IMX_I2C_STATE_FAILED with -EPROTO each time; with it -EPROTO 100 of 100, as the atomic read returns. Count bytes of 0, 1 and 0x13 read the same bytes as before, and the bus works after each failed read.

 drivers/i2c/busses/i2c-imx.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-imx.c +3 -0
index ccf08cd63151..c7fef98934d4 100644
@@ -1142,6 +1142,9 @@ static irqreturn_t i2c_imx_master_isr(struct imx_i2c_struct *i2c_imx, unsigned i
 		wake_up(&i2c_imx->queue);
 		break;
 
+	case IMX_I2C_STATE_FAILED:
+		break;
+
 	default:
 		i2c_imx->i2csr = status;
 		i2c_imx->state = IMX_I2C_STATE_FAILED;
Quoted 3 lines

base-commit: 25e7ab89f4774b0f842cee0e8a20c11f755924d5

Signature · 1 line
2.56.0

Looks good as well, thanks.