Skip to content

Commit 8bc661b

Browse files
marekrgregkh
authored andcommitted
tty/serial: at91: disable uart timer at start of shutdown
The uart timer will schedule a tasklet when it fires. It is possible that it can fire inside _shutdown before it is killed in the dma and pdc cleanup routines. This causes a tasklet that exists after the port is shutdown, so when the kernel finally executes it, it panics as the tty port is NULL. This is a somewhat rare condition but its possible if a program keeps on opening/closing the port. It has been observed in particular with systemd boot messages that were causing a kernel panic because of this behavior. Moving the timer deletion to the beginning of the function stops a tasklet from being scheduled unexpectedly. Signed-off-by: Marek Roszko <mark.roszko@gmail.com> Cc: stable <stable@vger.kernel.org> # v3.12 [nicolas.ferre@atmel.com: modify commit message, call setup_timer() in any case] Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 3685f19 commit 8bc661b

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

drivers/tty/serial/atmel_serial.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -825,9 +825,6 @@ static void atmel_release_rx_dma(struct uart_port *port)
825825
atmel_port->desc_rx = NULL;
826826
atmel_port->chan_rx = NULL;
827827
atmel_port->cookie_rx = -EINVAL;
828-
829-
if (!atmel_port->is_usart)
830-
del_timer_sync(&atmel_port->uart_timer);
831828
}
832829

833830
static void atmel_rx_from_dma(struct uart_port *port)
@@ -1229,9 +1226,6 @@ static void atmel_release_rx_pdc(struct uart_port *port)
12291226
DMA_FROM_DEVICE);
12301227
kfree(pdc->buf);
12311228
}
1232-
1233-
if (!atmel_port->is_usart)
1234-
del_timer_sync(&atmel_port->uart_timer);
12351229
}
12361230

12371231
static void atmel_rx_from_pdc(struct uart_port *port)
@@ -1604,12 +1598,13 @@ static int atmel_startup(struct uart_port *port)
16041598
/* enable xmit & rcvr */
16051599
UART_PUT_CR(port, ATMEL_US_TXEN | ATMEL_US_RXEN);
16061600

1601+
setup_timer(&atmel_port->uart_timer,
1602+
atmel_uart_timer_callback,
1603+
(unsigned long)port);
1604+
16071605
if (atmel_use_pdc_rx(port)) {
16081606
/* set UART timeout */
16091607
if (!atmel_port->is_usart) {
1610-
setup_timer(&atmel_port->uart_timer,
1611-
atmel_uart_timer_callback,
1612-
(unsigned long)port);
16131608
mod_timer(&atmel_port->uart_timer,
16141609
jiffies + uart_poll_timeout(port));
16151610
/* set USART timeout */
@@ -1624,9 +1619,6 @@ static int atmel_startup(struct uart_port *port)
16241619
} else if (atmel_use_dma_rx(port)) {
16251620
/* set UART timeout */
16261621
if (!atmel_port->is_usart) {
1627-
setup_timer(&atmel_port->uart_timer,
1628-
atmel_uart_timer_callback,
1629-
(unsigned long)port);
16301622
mod_timer(&atmel_port->uart_timer,
16311623
jiffies + uart_poll_timeout(port));
16321624
/* set USART timeout */
@@ -1651,6 +1643,12 @@ static void atmel_shutdown(struct uart_port *port)
16511643
{
16521644
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
16531645

1646+
/*
1647+
* Prevent any tasklets being scheduled during
1648+
* cleanup
1649+
*/
1650+
del_timer_sync(&atmel_port->uart_timer);
1651+
16541652
/*
16551653
* Clear out any scheduled tasklets before
16561654
* we destroy the buffers

0 commit comments

Comments
 (0)