From: Stefan Eichenberger <eichest@gmail.com>
To: Vincent Jardin <vjardin@free.fr>
Cc: Oleksij Rempel <o.rempel@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Andi Shyti <andi.shyti@kernel.org>, Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>, Wolfram Sang <wsa@kernel.org>,
Kaushal Butala <kaushalkernelmailinglist@gmail.com>,
Shawn Guo <shawn.guo@freescale.com>,
Stefan Eichenberger <stefan.eichenberger@toradex.com>,
linux-i2c@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 2/2] i2c: imx: fix locked bus on SMBus block-read of 0 (IRQ)
Date: Thu, 25 Jun 2026 11:11:16 +0200 [thread overview]
Message-ID: <ajzwtNbCKXdxQAUA@eichest-laptop> (raw)
In-Reply-To: <20260525-for-upstream-i2c-lx2160-fix-v1-v2-2-26a3cc8cd055@free.fr>
On Mon, May 25, 2026 at 06:43:16PM +0200, Vincent Jardin wrote:
> SMBus 3.1 6.5.7 allows a Block Read byte count of 0, but the
> interrupt-driven block-read state machine rejects it as -EPROTO. Worse,
> it returns without a NACK+STOP: the next receive cycle has already
> started, so the target keeps holding SDA and the bus stays stuck until a
> power cycle of this i2c controller.
>
> Accept count=0: NACK the in-flight dummy byte (TXAK) and set msg->len to
> 2 so i2c_imx_isr_read_continue() emits STOP via its normal last-byte
> path. The dummy byte is discarded; block-read callers only consume
> buf[0..count-1].
>
> Reading I2DR has likewise already armed the next byte on the
> count > I2C_SMBUS_BLOCK_MAX error path, so NACK it (TXAK) before aborting
> with -EPROTO; otherwise the failing transfer's STOP cannot complete and
> the bus stays held.
>
> The atomic path regressed earlier (v3.16) and is fixed separately; this
> patch covers only the v6.13 state-machine rework.
>
> Fixes: 5f5c2d4579ca ("i2c: imx: prevent rescheduling in non dma mode")
> Cc: <stable@vger.kernel.org> # v6.13+
> Signed-off-by: Vincent Jardin <vjardin@free.fr>
> ---
> drivers/i2c/busses/i2c-imx.c | 17 +++++++++++++++++
> 1 file changed, 17 insertions(+)
>
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 14107e1ad413..8db8d2e10f5c 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -1061,11 +1061,28 @@ static inline enum imx_i2c_state i2c_imx_isr_read_continue(struct imx_i2c_struct
> static inline void i2c_imx_isr_read_block_data_len(struct imx_i2c_struct *i2c_imx)
> {
> u8 len = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR);
> + unsigned int temp;
>
> if (len == 0 || len > I2C_SMBUS_BLOCK_MAX) {
> + /*
> + * SMBus 3.1 6.5.7: support count byte of 0.
> + * I2C_SMBUS_BLOCK_MAX case should not hold the SDA either.
> + * So NACK it (TXAK) to not hold the bus.
> + */
> + temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2CR);
> + temp |= I2CR_TXAK;
> + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2CR);
> +
> + if (len == 0) {
> + i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = 0;
> + i2c_imx->msg->len = 2;
> + return;
> + }
> +
> i2c_imx->isr_result = -EPROTO;
> i2c_imx->state = IMX_I2C_STATE_FAILED;
> wake_up(&i2c_imx->queue);
> + return;
> }
> i2c_imx->msg->len += len;
> i2c_imx->msg->buf[i2c_imx->msg_buf_idx++] = len;
>
> --
> 2.43.0
>
Reviewed-by: Stefan Eichenberger <eichest@gmail.com>
next prev parent reply other threads:[~2026-06-25 9:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 11:24 [PATCH 0/2] i2c: imx: fix SMBus block-read of 0 locking the bus Vincent Jardin
2026-05-25 11:24 ` [PATCH 1/2] i2c: imx: fix locked bus on SMBus block-read of 0 (atomic) Vincent Jardin
2026-05-25 11:24 ` [PATCH 2/2] i2c: imx: fix locked bus on SMBus block-read of 0 (IRQ) Vincent Jardin
2026-05-25 16:43 ` [PATCH v2 0/2] i2c: imx: fix SMBus block-read of 0 locking the bus Vincent Jardin
2026-05-25 16:43 ` [PATCH v2 1/2] i2c: imx: fix locked bus on SMBus block-read of 0 (atomic) Vincent Jardin
2026-06-25 9:04 ` Stefan Eichenberger
2026-05-25 16:43 ` [PATCH v2 2/2] i2c: imx: fix locked bus on SMBus block-read of 0 (IRQ) Vincent Jardin
2026-06-25 9:11 ` Stefan Eichenberger [this message]
2026-05-26 7:00 ` [PATCH v2 0/2] i2c: imx: fix SMBus block-read of 0 locking the bus Carlos Song (OSS)
2026-05-26 8:12 ` Vincent Jardin
2026-05-26 9:00 ` Carlos Song (OSS)
2026-06-23 20:14 ` Andi Shyti
2026-06-25 7:18 ` Oleksij Rempel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajzwtNbCKXdxQAUA@eichest-laptop \
--to=eichest@gmail.com \
--cc=Frank.Li@nxp.com \
--cc=andi.shyti@kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kaushalkernelmailinglist@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=o.rempel@pengutronix.de \
--cc=s.hauer@pengutronix.de \
--cc=shawn.guo@freescale.com \
--cc=stable@vger.kernel.org \
--cc=stefan.eichenberger@toradex.com \
--cc=vjardin@free.fr \
--cc=wsa@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox