Skip to content

Commit c7c9e91

Browse files
Wolfram Sangwsakernel
authored andcommitted
i2c: rcar: avoid race when unregistering slave
Due to the lockless design of the driver, it is theoretically possible to access a NULL pointer, if a slave interrupt was running while we were unregistering the slave. To make this rock solid, disable the interrupt for a short time while we are clearing the interrupt_enable register. This patch is purely based on code inspection. The OOPS is super-hard to trigger because clearing SAR (the address) makes interrupts even more unlikely to happen as well. While here, reinit SCR to SDBS because this bit should always be set according to documentation. There is no effect, though, because the interface is disabled. Fixes: 7b814d8 ("i2c: rcar: avoid race when unregistering slave client") Signed-off-by: Wolfram Sang <[email protected]> Reviewed-by: Niklas Söderlund <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 073d398 commit c7c9e91

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

drivers/i2c/busses/i2c-rcar.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,14 @@ static int rcar_unreg_slave(struct i2c_client *slave)
866866

867867
WARN_ON(!priv->slave);
868868

869-
/* disable irqs and ensure none is running before clearing ptr */
869+
/* ensure no irq is running before clearing ptr */
870+
disable_irq(priv->irq);
870871
rcar_i2c_write(priv, ICSIER, 0);
871-
rcar_i2c_write(priv, ICSCR, 0);
872+
rcar_i2c_write(priv, ICSSR, 0);
873+
enable_irq(priv->irq);
874+
rcar_i2c_write(priv, ICSCR, SDBS);
872875
rcar_i2c_write(priv, ICSAR, 0); /* Gen2: must be 0 if not using slave */
873876

874-
synchronize_irq(priv->irq);
875877
priv->slave = NULL;
876878

877879
pm_runtime_put(rcar_i2c_priv_to_dev(priv));

0 commit comments

Comments
 (0)