Skip to content

Commit 49b30a6

Browse files
Wolfram Sanggregkh
authored andcommitted
i2c: rcar: avoid race when unregistering slave
[ Upstream commit c7c9e91 ] 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 <wsa+renesas@sang-engineering.com> Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se> Signed-off-by: Wolfram Sang <wsa@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent bb1da23 commit 49b30a6

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

drivers/i2c/busses/i2c-rcar.c

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

862862
WARN_ON(!priv->slave);
863863

864-
/* disable irqs and ensure none is running before clearing ptr */
864+
/* ensure no irq is running before clearing ptr */
865+
disable_irq(priv->irq);
865866
rcar_i2c_write(priv, ICSIER, 0);
866-
rcar_i2c_write(priv, ICSCR, 0);
867+
rcar_i2c_write(priv, ICSSR, 0);
868+
enable_irq(priv->irq);
869+
rcar_i2c_write(priv, ICSCR, SDBS);
867870
rcar_i2c_write(priv, ICSAR, 0); /* Gen2: must be 0 if not using slave */
868871

869-
synchronize_irq(priv->irq);
870872
priv->slave = NULL;
871873

872874
pm_runtime_put(rcar_i2c_priv_to_dev(priv));

0 commit comments

Comments
 (0)