]>
Commit | Line | Data |
---|---|---|
92052b71 GKH |
1 | From f8fd1b0350d3a4581125f5eda6528f5a2c5f9183 Mon Sep 17 00:00:00 2001 |
2 | From: Loic Poulain <loic.poulain@intel.com> | |
3 | Date: Thu, 24 Apr 2014 11:34:48 +0200 | |
4 | Subject: serial: 8250: Fix thread unsafe __dma_tx_complete function | |
5 | ||
6 | From: Loic Poulain <loic.poulain@intel.com> | |
7 | ||
8 | commit f8fd1b0350d3a4581125f5eda6528f5a2c5f9183 upstream. | |
9 | ||
10 | __dma_tx_complete is not protected against concurrent | |
11 | call of serial8250_tx_dma. it can lead to circular tail | |
12 | index corruption or parallel call of serial_tx_dma on the | |
13 | same data portion. | |
14 | ||
15 | This patch fixes this issue by holding the port lock. | |
16 | ||
17 | Signed-off-by: Loic Poulain <loic.poulain@intel.com> | |
18 | Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> | |
19 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
20 | ||
21 | --- | |
22 | drivers/tty/serial/8250/8250_dma.c | 9 +++++++-- | |
23 | 1 file changed, 7 insertions(+), 2 deletions(-) | |
24 | ||
25 | --- a/drivers/tty/serial/8250/8250_dma.c | |
26 | +++ b/drivers/tty/serial/8250/8250_dma.c | |
27 | @@ -20,12 +20,15 @@ static void __dma_tx_complete(void *para | |
28 | struct uart_8250_port *p = param; | |
29 | struct uart_8250_dma *dma = p->dma; | |
30 | struct circ_buf *xmit = &p->port.state->xmit; | |
31 | - | |
32 | - dma->tx_running = 0; | |
33 | + unsigned long flags; | |
34 | ||
35 | dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, | |
36 | UART_XMIT_SIZE, DMA_TO_DEVICE); | |
37 | ||
38 | + spin_lock_irqsave(&p->port.lock, flags); | |
39 | + | |
40 | + dma->tx_running = 0; | |
41 | + | |
42 | xmit->tail += dma->tx_size; | |
43 | xmit->tail &= UART_XMIT_SIZE - 1; | |
44 | p->port.icount.tx += dma->tx_size; | |
45 | @@ -35,6 +38,8 @@ static void __dma_tx_complete(void *para | |
46 | ||
47 | if (!uart_circ_empty(xmit) && !uart_tx_stopped(&p->port)) | |
48 | serial8250_tx_dma(p); | |
49 | + | |
50 | + spin_unlock_irqrestore(&p->port.lock, flags); | |
51 | } | |
52 | ||
53 | static void __dma_rx_complete(void *param) |