staging: most: cdev: fix race condition
authorChristian Gromm <christian.gromm@microchip.com>
Tue, 8 May 2018 09:45:10 +0000 (11:45 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 May 2018 11:41:51 +0000 (13:41 +0200)
This patch fixes a race condition between the functions disconnect and poll.

Signed-off-by: Christian Gromm <christian.gromm@microchip.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/most/cdev/cdev.c

index 8e7652545402972e5eff389f4b6a764ff29084ac..4569838f27a02437d3bc353c3b629244a72fe9cd 100644 (file)
@@ -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;
 }