[PATCH 01/10] i2c: imx-lpi2c: Clear rx_cmd_buf pointer after freeing in lpi2c_imx_dma_xfer()
Frank Li
Frank.li at oss.nxp.com
Thu Dec 3 12:36:31 PST 2026
On Thu, Dec 03, 2026 at 06:31:05PM +0000, Lee Jones wrote:
> lpi2c_imx->dma persists across transfers. On a DMA read, the
> disable_dma path frees dma->rx_cmd_buf without clearing the pointer.
> If a subsequent DMA read fails in lpi2c_dma_config() or
> lpi2c_dma_submit() before lpi2c_imx_alloc_rx_cmd_buf() runs, the
> cleanup path calls kfree(dma->rx_cmd_buf) a second time on the stale
> pointer.
>
> Reset dma->rx_cmd_buf to NULL immediately after freeing it.
>
> Fixes: a09c8b3f9047 ("i2c: imx-lpi2c: add eDMA mode support for LPI2C")
> Closes: https://sashiko.dev/#/bug/linux-17d925e1-8c99-4efb-a920-2c90ce2b53b5
> Cc: stable at vger.kernel.org
> Signed-off-by: Lee Jones <lee at kernel.org>
> ---
Reviewed-by: Frank Li <Frank.Li at nxp.com>
> drivers/i2c/busses/i2c-imx-lpi2c.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/i2c/busses/i2c-imx-lpi2c.c b/drivers/i2c/busses/i2c-imx-lpi2c.c
> index ecf2bed01b29..f911b3b7367e 100644
> --- a/drivers/i2c/busses/i2c-imx-lpi2c.c
> +++ b/drivers/i2c/busses/i2c-imx-lpi2c.c
> @@ -1097,8 +1097,10 @@ static int lpi2c_imx_dma_xfer(struct lpi2c_imx_struct *lpi2c_imx,
> /* Disable I2C DMA function */
> writel(0, lpi2c_imx->base + LPI2C_MDER);
>
> - if (dma->dma_msg_flag & I2C_M_RD)
> + if (dma->dma_msg_flag & I2C_M_RD) {
> kfree(dma->rx_cmd_buf);
> + dma->rx_cmd_buf = NULL;
> + }
>
> if (ret)
> i2c_put_dma_safe_msg_buf(dma->dma_buf, msg, false);
> --
> 2.56.1.911.g883d8bcb20-goog
>
>
More information about the linux-arm-kernel
mailing list