[PATCH 22/28] staging: most: cdev: fix race condition

Christian Gromm christian.gromm at microchip.com
Tue May 8 09:45:10 UTC 2018


This patch fixes a race condition between the functions disconnect and poll.

Signed-off-by: Christian Gromm <christian.gromm at microchip.com>
---
 drivers/staging/most/cdev/cdev.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/most/cdev/cdev.c b/drivers/staging/most/cdev/cdev.c
index 8e76525..4569838 100644
--- a/drivers/staging/most/cdev/cdev.c
+++ b/drivers/staging/most/cdev/cdev.c
@@ -292,13 +292,15 @@ static __poll_t comp_poll(struct file *filp, poll_table *wait)
 
 	poll_wait(filp, &c->wq, wait);
 
+	mutex_lock(&c->io_mutex);
 	if (c->cfg->direction == MOST_CH_RX) {
-		if (!kfifo_is_empty(&c->fifo))
+		if (!c->dev || !kfifo_is_empty(&c->fifo))
 			mask |= EPOLLIN | EPOLLRDNORM;
 	} else {
-		if (!kfifo_is_empty(&c->fifo) || ch_has_mbo(c))
+		if (!c->dev || !kfifo_is_empty(&c->fifo) || ch_has_mbo(c))
 			mask |= EPOLLOUT | EPOLLWRNORM;
 	}
+	mutex_unlock(&c->io_mutex);
 	return mask;
 }
 
-- 
2.7.4



More information about the devel mailing list