All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] i2c: xiic: Fix broken locking on tx_msg
@ 2020-06-13 15:07 Marek Vasut
  2020-06-13 15:07 ` [PATCH 2/5] i2c: xiic: Drop broken interrupt handler Marek Vasut
                   ` (4 more replies)
  0 siblings, 5 replies; 35+ messages in thread
From: Marek Vasut @ 2020-06-13 15:07 UTC (permalink / raw)
  To: linux-i2c; +Cc: Marek Vasut, Michal Simek, Shubhrajyoti Datta, Wolfram Sang

The tx_msg is set from multiple places, sometimes without locking,
which fall apart on any SMP system. Only ever access tx_msg inside
the driver mutex.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Cc: Wolfram Sang <wsa@kernel.org>
---
 drivers/i2c/busses/i2c-xiic.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 90c1c362394d0..0777e577720db 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -168,7 +168,7 @@ struct xiic_i2c {
 #define xiic_tx_space(i2c) ((i2c)->tx_msg->len - (i2c)->tx_pos)
 #define xiic_rx_space(i2c) ((i2c)->rx_msg->len - (i2c)->rx_pos)
 
-static int xiic_start_xfer(struct xiic_i2c *i2c);
+static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num);
 static void __xiic_start_xfer(struct xiic_i2c *i2c);
 
 /*
@@ -673,15 +673,24 @@ static void __xiic_start_xfer(struct xiic_i2c *i2c)
 
 }
 
-static int xiic_start_xfer(struct xiic_i2c *i2c)
+static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num)
 {
 	int ret;
+
 	mutex_lock(&i2c->lock);
 
+	ret = xiic_busy(i2c);
+	if (ret)
+		goto out;
+
+	i2c->tx_msg = msgs;
+	i2c->nmsgs = num;
+
 	ret = xiic_reinit(i2c);
 	if (!ret)
 		__xiic_start_xfer(i2c);
 
+out:
 	mutex_unlock(&i2c->lock);
 
 	return ret;
@@ -699,14 +708,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 	if (err < 0)
 		return err;
 
-	err = xiic_busy(i2c);
-	if (err)
-		goto out;
-
-	i2c->tx_msg = msgs;
-	i2c->nmsgs = num;
-
-	err = xiic_start_xfer(i2c);
+	err = xiic_start_xfer(i2c, msgs, num);
 	if (err < 0) {
 		dev_err(adap->dev.parent, "Error xiic_start_xfer\n");
 		goto out;
@@ -714,9 +716,11 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 
 	if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) ||
 		(i2c->state == STATE_DONE), HZ)) {
+		mutex_lock(&i2c->lock);
 		err = (i2c->state == STATE_DONE) ? num : -EIO;
 		goto out;
 	} else {
+		mutex_lock(&i2c->lock);
 		i2c->tx_msg = NULL;
 		i2c->rx_msg = NULL;
 		i2c->nmsgs = 0;
@@ -724,6 +728,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 		goto out;
 	}
 out:
+	mutex_unlock(&i2c->lock);
 	pm_runtime_mark_last_busy(i2c->dev);
 	pm_runtime_put_autosuspend(i2c->dev);
 	return err;
-- 
2.26.2


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

end of thread, other threads:[~2020-09-11 10:28 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-13 15:07 [PATCH 1/5] i2c: xiic: Fix broken locking on tx_msg Marek Vasut
2020-06-13 15:07 ` [PATCH 2/5] i2c: xiic: Drop broken interrupt handler Marek Vasut
2020-06-17 12:25   ` Shubhrajyoti Datta
2020-06-17 12:31     ` Marek Vasut
2020-06-26 12:13   ` Raviteja Narayanam
2020-06-28 23:41     ` Marek Vasut
2020-06-29 12:52       ` Raviteja Narayanam
2020-06-29 21:50         ` Marek Vasut
2020-07-08 15:23           ` Raviteja Narayanam
2020-08-19 17:42             ` Marek Vasut
2020-08-24  8:27               ` Raviteja Narayanam
2020-08-24 11:58                 ` Marek Vasut
2020-08-25  9:44                   ` Raviteja Narayanam
2020-08-25 20:50                     ` Marek Vasut
2020-09-07  8:51                       ` Raviteja Narayanam
2020-09-08 14:04                         ` Marek Vasut
2020-09-11 10:28                           ` Michal Simek
2020-06-13 15:07 ` [PATCH 3/5] i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process() Marek Vasut
2020-06-26 12:13   ` Raviteja Narayanam
2020-07-08 15:23     ` Raviteja Narayanam
2020-06-13 15:07 ` [PATCH 4/5] i2c: xiic: Switch from waitqueue to completion Marek Vasut
2020-06-26 12:13   ` Raviteja Narayanam
2020-06-28 23:41     ` Marek Vasut
2020-06-29 12:53       ` Raviteja Narayanam
2020-06-29 21:52         ` Marek Vasut
2020-06-13 15:07 ` [PATCH 5/5] i2c: xiic: Only ever transfer single message Marek Vasut
2020-06-13 19:33   ` Wolfram Sang
2020-06-13 19:37     ` Marek Vasut
2020-06-13 19:42       ` Wolfram Sang
2020-07-13  8:37         ` Michal Simek
2020-06-26 12:14   ` Raviteja Narayanam
2020-06-26 12:11 ` [PATCH 1/5] i2c: xiic: Fix broken locking on tx_msg Raviteja Narayanam
2020-06-28 23:18   ` Marek Vasut
2020-06-29 12:52     ` Raviteja Narayanam
2020-07-08 15:23       ` Raviteja Narayanam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.