linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: rcar: avoid race when unregistering slave client
@ 2019-08-08 19:39 Wolfram Sang
  2019-08-09 10:23 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  2019-08-14 12:48 ` Wolfram Sang
  0 siblings, 2 replies; 3+ messages in thread
From: Wolfram Sang @ 2019-08-08 19:39 UTC (permalink / raw)
  To: linux-i2c; +Cc: linux-renesas-soc, Wolfram Sang, Krzysztof Adamski

After we disabled interrupts, there might still be an active one
running. Sync before clearing the pointer to the slave device.

Reported-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---

Tested with a Lager board (Renesas R-Car H2) and no regressions found. I
tried to run into this race via stress-testing but failed. The race
window is tiny, but it is still there, so let's fix it.

 drivers/i2c/busses/i2c-rcar.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index d39a4606f72d..531c01100b56 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -139,6 +139,7 @@ struct rcar_i2c_priv {
 	enum dma_data_direction dma_direction;
 
 	struct reset_control *rstc;
+	int irq;
 };
 
 #define rcar_i2c_priv_to_dev(p)		((p)->adap.dev.parent)
@@ -861,9 +862,11 @@ static int rcar_unreg_slave(struct i2c_client *slave)
 
 	WARN_ON(!priv->slave);
 
+	/* disable irqs and ensure none is running before clearing ptr */
 	rcar_i2c_write(priv, ICSIER, 0);
 	rcar_i2c_write(priv, ICSCR, 0);
 
+	synchronize_irq(priv->irq);
 	priv->slave = NULL;
 
 	pm_runtime_put(rcar_i2c_priv_to_dev(priv));
@@ -918,7 +921,7 @@ static int rcar_i2c_probe(struct platform_device *pdev)
 	struct i2c_adapter *adap;
 	struct device *dev = &pdev->dev;
 	struct i2c_timings i2c_t;
-	int irq, ret;
+	int ret;
 
 	/* Otherwise logic will break because some bytes must always use PIO */
 	BUILD_BUG_ON_MSG(RCAR_MIN_DMA_LEN < 3, "Invalid min DMA length");
@@ -984,10 +987,10 @@ static int rcar_i2c_probe(struct platform_device *pdev)
 		pm_runtime_put(dev);
 
 
-	irq = platform_get_irq(pdev, 0);
-	ret = devm_request_irq(dev, irq, rcar_i2c_irq, 0, dev_name(dev), priv);
+	priv->irq = platform_get_irq(pdev, 0);
+	ret = devm_request_irq(dev, priv->irq, rcar_i2c_irq, 0, dev_name(dev), priv);
 	if (ret < 0) {
-		dev_err(dev, "cannot get irq %d\n", irq);
+		dev_err(dev, "cannot get irq %d\n", priv->irq);
 		goto out_pm_disable;
 	}
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: rcar: avoid race when unregistering slave client
  2019-08-08 19:39 [PATCH] i2c: rcar: avoid race when unregistering slave client Wolfram Sang
@ 2019-08-09 10:23 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
  2019-08-14 12:48 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-08-09 10:23 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-renesas-soc

On Thu, Aug 08, 2019 at 09:39:10PM +0200, Wolfram Sang wrote:
>After we disabled interrupts, there might still be an active one
>running. Sync before clearing the pointer to the slave device.
>
>Reported-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
>Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
>---
>
>Tested with a Lager board (Renesas R-Car H2) and no regressions found. I
>tried to run into this race via stress-testing but failed. The race
>window is tiny, but it is still there, so let's fix it.
>
> drivers/i2c/busses/i2c-rcar.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>

Reviewed-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] i2c: rcar: avoid race when unregistering slave client
  2019-08-08 19:39 [PATCH] i2c: rcar: avoid race when unregistering slave client Wolfram Sang
  2019-08-09 10:23 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
@ 2019-08-14 12:48 ` Wolfram Sang
  1 sibling, 0 replies; 3+ messages in thread
From: Wolfram Sang @ 2019-08-14 12:48 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c, linux-renesas-soc, Krzysztof Adamski

[-- Attachment #1: Type: text/plain, Size: 368 bytes --]

On Thu, Aug 08, 2019 at 09:39:10PM +0200, Wolfram Sang wrote:
> After we disabled interrupts, there might still be an active one
> running. Sync before clearing the pointer to the slave device.
> 
> Reported-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Applied to for-current, thanks!


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-14 12:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-08 19:39 [PATCH] i2c: rcar: avoid race when unregistering slave client Wolfram Sang
2019-08-09 10:23 ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-08-14 12:48 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).