Commit 850a28ec authored by Vasily Khoruzhick's avatar Vasily Khoruzhick Committed by Grant Likely

spi: Fix race condition in stop_queue()

There's a race condition in stop_queue() in some drivers -
if drv_data->queue is empty, but drv_data->busy is still set
(or opposite situation) stop_queue will return -EBUSY.
So fix loop condition to check that both drv_data->queue is empty
and drv_data->busy is not set.

This patch affects following drivers:
pxa2xx_spi
spi_bfin5xx
amba-pl022
dw_spi
Signed-off-by: default avatarVasily Khoruzhick <anarsoul@gmail.com>
Acked-by: default avatarEric Miao <eric.y.miao@gmail.com>
Acked-by: default avatarMike Frysinger <vapier@gentoo.org>
Signed-off-by: default avatarGrant Likely <grant.likely@secretlab.ca>
parent 454abcc5
...@@ -1555,7 +1555,7 @@ static int stop_queue(struct pl022 *pl022) ...@@ -1555,7 +1555,7 @@ static int stop_queue(struct pl022 *pl022)
* A wait_queue on the pl022->busy could be used, but then the common * A wait_queue on the pl022->busy could be used, but then the common
* execution path (pump_messages) would be required to call wake_up or * execution path (pump_messages) would be required to call wake_up or
* friends on every SPI message. Do this instead */ * friends on every SPI message. Do this instead */
while (!list_empty(&pl022->queue) && pl022->busy && limit--) { while ((!list_empty(&pl022->queue) || pl022->busy) && limit--) {
spin_unlock_irqrestore(&pl022->queue_lock, flags); spin_unlock_irqrestore(&pl022->queue_lock, flags);
msleep(10); msleep(10);
spin_lock_irqsave(&pl022->queue_lock, flags); spin_lock_irqsave(&pl022->queue_lock, flags);
......
...@@ -821,7 +821,7 @@ static int stop_queue(struct dw_spi *dws) ...@@ -821,7 +821,7 @@ static int stop_queue(struct dw_spi *dws)
spin_lock_irqsave(&dws->lock, flags); spin_lock_irqsave(&dws->lock, flags);
dws->run = QUEUE_STOPPED; dws->run = QUEUE_STOPPED;
while (!list_empty(&dws->queue) && dws->busy && limit--) { while ((!list_empty(&dws->queue) || dws->busy) && limit--) {
spin_unlock_irqrestore(&dws->lock, flags); spin_unlock_irqrestore(&dws->lock, flags);
msleep(10); msleep(10);
spin_lock_irqsave(&dws->lock, flags); spin_lock_irqsave(&dws->lock, flags);
......
...@@ -1493,7 +1493,7 @@ static int stop_queue(struct driver_data *drv_data) ...@@ -1493,7 +1493,7 @@ static int stop_queue(struct driver_data *drv_data)
* execution path (pump_messages) would be required to call wake_up or * execution path (pump_messages) would be required to call wake_up or
* friends on every SPI message. Do this instead */ * friends on every SPI message. Do this instead */
drv_data->run = QUEUE_STOPPED; drv_data->run = QUEUE_STOPPED;
while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) { while ((!list_empty(&drv_data->queue) || drv_data->busy) && limit--) {
spin_unlock_irqrestore(&drv_data->lock, flags); spin_unlock_irqrestore(&drv_data->lock, flags);
msleep(10); msleep(10);
spin_lock_irqsave(&drv_data->lock, flags); spin_lock_irqsave(&drv_data->lock, flags);
......
...@@ -1284,7 +1284,7 @@ static inline int bfin_spi_stop_queue(struct bfin_spi_master_data *drv_data) ...@@ -1284,7 +1284,7 @@ static inline int bfin_spi_stop_queue(struct bfin_spi_master_data *drv_data)
* friends on every SPI message. Do this instead * friends on every SPI message. Do this instead
*/ */
drv_data->running = false; drv_data->running = false;
while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) { while ((!list_empty(&drv_data->queue) || drv_data->busy) && limit--) {
spin_unlock_irqrestore(&drv_data->lock, flags); spin_unlock_irqrestore(&drv_data->lock, flags);
msleep(10); msleep(10);
spin_lock_irqsave(&drv_data->lock, flags); spin_lock_irqsave(&drv_data->lock, flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment