Skip to content

Commit 1be6f2b

Browse files
ccpalexgregkh
authored andcommitted
tty: serial: fsl_lpuart: fix race on RX DMA shutdown
From time to time DMA completion can come in the middle of DMA shutdown: <process ctx>: <IRQ>: lpuart32_shutdown() lpuart_dma_shutdown() del_timer_sync() lpuart_dma_rx_complete() lpuart_copy_rx_to_tty() mod_timer() lpuart_dma_rx_free() When the timer fires a bit later, sport->dma_rx_desc is NULL: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000004 pc : lpuart_copy_rx_to_tty+0xcc/0x5bc lr : lpuart_timer_func+0x1c/0x2c Call trace: lpuart_copy_rx_to_tty lpuart_timer_func call_timer_fn __run_timers.part.0 run_timer_softirq __do_softirq __irq_exit_rcu irq_exit handle_domain_irq gic_handle_irq call_on_irq_stack do_interrupt_handler ... To fix this fold del_timer_sync() into lpuart_dma_rx_free() after dmaengine_terminate_sync() to make sure timer will not be re-started in lpuart_copy_rx_to_tty() <= lpuart_dma_rx_complete(). Fixes: 4a8588a ("serial: fsl_lpuart: delete timer on shutdown") Cc: stable <[email protected]> Signed-off-by: Alexander Sverdlin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5d943b5 commit 1be6f2b

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

drivers/tty/serial/fsl_lpuart.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@ static void lpuart_dma_rx_free(struct uart_port *port)
13541354
struct dma_chan *chan = sport->dma_rx_chan;
13551355

13561356
dmaengine_terminate_sync(chan);
1357+
del_timer_sync(&sport->lpuart_timer);
13571358
dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
13581359
kfree(sport->rx_ring.buf);
13591360
sport->rx_ring.tail = 0;
@@ -1813,7 +1814,6 @@ static int lpuart32_startup(struct uart_port *port)
18131814
static void lpuart_dma_shutdown(struct lpuart_port *sport)
18141815
{
18151816
if (sport->lpuart_dma_rx_use) {
1816-
del_timer_sync(&sport->lpuart_timer);
18171817
lpuart_dma_rx_free(&sport->port);
18181818
sport->lpuart_dma_rx_use = false;
18191819
}
@@ -1973,10 +1973,8 @@ lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
19731973
* Since timer function acqures sport->port.lock, need to stop before
19741974
* acquring same lock because otherwise del_timer_sync() can deadlock.
19751975
*/
1976-
if (old && sport->lpuart_dma_rx_use) {
1977-
del_timer_sync(&sport->lpuart_timer);
1976+
if (old && sport->lpuart_dma_rx_use)
19781977
lpuart_dma_rx_free(&sport->port);
1979-
}
19801978

19811979
spin_lock_irqsave(&sport->port.lock, flags);
19821980

@@ -2210,10 +2208,8 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
22102208
* Since timer function acqures sport->port.lock, need to stop before
22112209
* acquring same lock because otherwise del_timer_sync() can deadlock.
22122210
*/
2213-
if (old && sport->lpuart_dma_rx_use) {
2214-
del_timer_sync(&sport->lpuart_timer);
2211+
if (old && sport->lpuart_dma_rx_use)
22152212
lpuart_dma_rx_free(&sport->port);
2216-
}
22172213

22182214
spin_lock_irqsave(&sport->port.lock, flags);
22192215

@@ -3020,7 +3016,6 @@ static int lpuart_suspend(struct device *dev)
30203016
* cannot resume as expected, hence gracefully release the
30213017
* Rx DMA path before suspend and start Rx DMA path on resume.
30223018
*/
3023-
del_timer_sync(&sport->lpuart_timer);
30243019
lpuart_dma_rx_free(&sport->port);
30253020

30263021
/* Disable Rx DMA to use UART port as wakeup source */

0 commit comments

Comments
 (0)