Skip to contentSkip to conversation

drivers/fsi: Fix SBEFIFO write() race condition

PATCH In review Eddie James 2 participants 2 messages Jun 28, 2017 FSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers/fsi: Fix SBEFIFO write() race condition

From: "Edward A. James" <[email protected]>

There was a race condition with the XFR_WRITE_DONE flag between write() and the worker thread. Occasionally the worker wrote all the data and checked the flag before write() could set it.

---
 drivers/fsi/fsi-sbefifo.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/fsi/fsi-sbefifo.c +6 -1
index f1bc144..d7dccf9 100644
@@ -688,6 +688,12 @@ static ssize_t sbefifo_write_common(struct sbefifo_client *client,
 		len -= n;
 		ret += n;
 
+		/* set flag before starting the worker, as it may run through
+		 * and check the flag before we exit this loop!
+		 */
+		if (!len)
+			set_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags);
+
 		/*
 		 * Drain the write buffer.
 		 */
@@ -696,7 +702,6 @@ static ssize_t sbefifo_write_common(struct sbefifo_client *client,
 			sbefifo_put(sbefifo);
 	}
 
-	set_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags);
 	sbefifo_put_client(client);
 
 	return ret;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw

thx Eddie!

Quoted 40 lines · Eddie James

From: "Edward A. James" <[email protected]>

There was a race condition with the XFR_WRITE_DONE flag between write() and the worker thread. Occasionally the worker wrote all the data and checked the flag before write() could set it.

---
drivers/fsi/fsi-sbefifo.c | 7 ++++++-

1 file changed, 6 insertions(+), 1 deletion(-)
drivers/fsi/fsi-sbefifo.c +6 -1
index f1bc144..d7dccf9 100644
@@ -688,6 +688,12 @@ static ssize_t sbefifo_write_common(struct sbefifo_client *client,
 		len -= n;
 		ret += n;
 
+		/* set flag before starting the worker, as it may run through
+		 * and check the flag before we exit this loop!
+		 */
+		if (!len)
+			set_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags);
+
 		/*
 		 * Drain the write buffer.
 		 */
@@ -696,7 +702,6 @@ static ssize_t sbefifo_write_common(struct sbefifo_client *client,
 			sbefifo_put(sbefifo);
 	}
 
-	set_bit(SBEFIFO_XFR_WRITE_DONE, &xfr->flags);
 	sbefifo_put_client(client);
 
 	return ret;
Signature · 1 line
1.8.3.1