[PATCH 7/8] i2c: nomadik: fix race condition with interrupt handler

From: Dmitry Guzman

Date: Tue Nov 03 2026 - 03:31:57 EST


If nmk_i2c_wait_xfer_done() gets timeout on waiting for wakeup from
interrupt handler, there is no synchronization with interrupt handler
that may run in parallel. This can potentially lead to various race
conditions between thread and interrupt handler.

Disable and clear all pending interrupt requests and wait until running
interrupt handler finishes after the timeout.

Signed-off-by: Dmitry Guzman <Dmitry.Guzman@xxxxxxxxxxxx>
---
drivers/i2c/busses/i2c-nomadik.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 361a5fc6a587..cc8b5a357f06 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -505,6 +505,11 @@ static bool nmk_i2c_wait_xfer_done(struct nmk_i2c_dev *priv)
wait_event_timeout(priv->xfer_wq, priv->xfer_done, timeout);
}

+ /* Disable interrupts and wait for pending interrupts */
+ disable_all_interrupts(priv);
+ clear_all_interrupts(priv);
+ synchronize_irq(priv->irq);
+
return priv->xfer_done;
}


--
2.43.0