* [PATCH] i2c: imx: keep the error of a failed read
@ 2026-11-16 12:59 Mehmet Fide
2026-11-16 18:25 ` Stefan Eichenberger
0 siblings, 1 reply; 2+ messages in thread
From: Mehmet Fide @ 2026-11-16 12:59 UTC (permalink / raw)
To: Andi Shyti, Oleksij Rempel
Cc: Pengutronix Kernel Team, Frank Li, Sascha Hauer, Fabio Estevam,
Stefan Eichenberger, Stefan Eichenberger, linux-i2c, imx,
linux-arm-kernel, linux-kernel, mehmet.fide
From: Mehmet Fide <mehmet.fide@screeningeagle.com>
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")
Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
---
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(+)
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index ccf08cd63151..c7fef98934d4 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -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
--
2.56.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] i2c: imx: keep the error of a failed read
2026-11-16 12:59 [PATCH] i2c: imx: keep the error of a failed read Mehmet Fide
@ 2026-11-16 18:25 ` Stefan Eichenberger
0 siblings, 0 replies; 2+ messages in thread
From: Stefan Eichenberger @ 2026-11-16 18:25 UTC (permalink / raw)
To: Mehmet Fide
Cc: Andi Shyti, Oleksij Rempel, Pengutronix Kernel Team, Frank Li,
Sascha Hauer, Fabio Estevam, Stefan Eichenberger, linux-i2c, imx,
linux-arm-kernel, linux-kernel, mehmet.fide
On Mon, Nov 16, 2026 at 01:59:40PM +0100, Mehmet Fide wrote:
> From: Mehmet Fide <mehmet.fide@screeningeagle.com>
>
> 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")
> Signed-off-by: Mehmet Fide <mehmet.fide@screeningeagle.com>
> ---
>
> 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(+)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index ccf08cd63151..c7fef98934d4 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -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
> --
> 2.56.0
Looks good as well, thanks.
Reviewed-by: Stefan Eichenberger <eichest@gmail.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-16 18:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 12:59 [PATCH] i2c: imx: keep the error of a failed read Mehmet Fide
2026-11-16 18:25 ` Stefan Eichenberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®