]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
i2c: imx: Cancel hrtimer before clearing slave pointer
authorLiem <liem16213@gmail.com>
Mon, 29 Jun 2026 02:38:29 +0000 (10:38 +0800)
committerAndi Shyti <andi.shyti@kernel.org>
Tue, 28 Jul 2026 21:24:03 +0000 (23:24 +0200)
In i2c_imx_unreg_slave(), the slave pointer is set to NULL after
disabling interrupts.  However, a pending interrupt might already
have started the hrtimer (i2c_imx_slave_timeout) before the pointer
was cleared.  If the hrtimer fires after i2c_imx->slave is set to
NULL, the timer callback i2c_imx_slave_finish_op() will call
i2c_imx_slave_event() with a NULL slave pointer, which results in a
use-after-free / NULL pointer dereference.

Fix by canceling the hrtimer and waiting for it to complete after
disabling interrupts, before clearing the slave pointer.

Fixes: f7414cd6923f ("i2c: imx: support slave mode for imx I2C driver")
Signed-off-by: Liem <liem16213@gmail.com>
Cc: <stable@vger.kernel.org> # v5.11+
Acked-by: Carlos Song <carlos.song@nxp.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Andi Shyti <andi.shyti@kernel.org>
Link: https://lore.kernel.org/r/20260629023829.152651-3-liem16213@gmail.com
drivers/i2c/busses/i2c-imx.c

index 49859ee494c6913a483767e3d7af5bea39049a12..9477d814fde94bb589cea1d302045a75a46feea1 100644 (file)
@@ -960,6 +960,7 @@ static int i2c_imx_unreg_slave(struct i2c_client *client)
 
        i2c_imx_reset_regs(i2c_imx);
 
+       hrtimer_cancel(&i2c_imx->slave_timer);
        i2c_imx->slave = NULL;
 
        /* Suspend */