Skip to content

Commit

Permalink
serial: 8250: Fix thread unsafe __dma_tx_complete function
Browse files Browse the repository at this point in the history
__dma_tx_complete is not protected against concurrent
call of serial8250_tx_dma. it can lead to circular tail
index corruption or parallel call of serial_tx_dma on the
same data portion.

This patch fixes this issue by holding the port lock.

Signed-off-by: Loic Poulain <loic.poulain@intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Loic Poulain authored and Greg Kroah-Hartman committed Apr 24, 2014
1 parent b08c9c3 commit f8fd1b0
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/tty/serial/8250/8250_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@ static void __dma_tx_complete(void *param)
struct uart_8250_port *p = param;
struct uart_8250_dma *dma = p->dma;
struct circ_buf *xmit = &p->port.state->xmit;

dma->tx_running = 0;
unsigned long flags;

dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr,
UART_XMIT_SIZE, DMA_TO_DEVICE);

spin_lock_irqsave(&p->port.lock, flags);

dma->tx_running = 0;

xmit->tail += dma->tx_size;
xmit->tail &= UART_XMIT_SIZE - 1;
p->port.icount.tx += dma->tx_size;
Expand All @@ -35,6 +38,8 @@ static void __dma_tx_complete(void *param)

if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port))
serial8250_tx_dma(p);

spin_unlock_irqrestore(&p->port.lock, flags);
}

static void __dma_rx_complete(void *param)
Expand Down

0 comments on commit f8fd1b0

Please sign in to comment.