Skip to content

Commit abf1e0a

Browse files
agnersgregkh
authored andcommitted
tty: serial: fsl_lpuart: lock port on console write
The console write code is not entirely race free (e.g. the operations to disabling the UART interrupts are not atomic) hence locking is required. This has been become apparent with the PREEMPT RT patchset applied: With the fully preemptible kernel configuration the system often ended up in a freeze already at startup. Disable interrupts and lock using read_lock_irqsave. Try to lock in the sysrq/oops case, but don't bother if locking fails. Signed-off-by: Stefan Agner <stefan@agner.ch> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4d9d7d8 commit abf1e0a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

drivers/tty/serial/fsl_lpuart.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,13 @@ lpuart_console_write(struct console *co, const char *s, unsigned int count)
17051705
{
17061706
struct lpuart_port *sport = lpuart_ports[co->index];
17071707
unsigned char old_cr2, cr2;
1708+
unsigned long flags;
1709+
int locked = 1;
1710+
1711+
if (sport->port.sysrq || oops_in_progress)
1712+
locked = spin_trylock_irqsave(&sport->port.lock, flags);
1713+
else
1714+
spin_lock_irqsave(&sport->port.lock, flags);
17081715

17091716
/* first save CR2 and then disable interrupts */
17101717
cr2 = old_cr2 = readb(sport->port.membase + UARTCR2);
@@ -1719,13 +1726,23 @@ lpuart_console_write(struct console *co, const char *s, unsigned int count)
17191726
barrier();
17201727

17211728
writeb(old_cr2, sport->port.membase + UARTCR2);
1729+
1730+
if (locked)
1731+
spin_unlock_irqrestore(&sport->port.lock, flags);
17221732
}
17231733

17241734
static void
17251735
lpuart32_console_write(struct console *co, const char *s, unsigned int count)
17261736
{
17271737
struct lpuart_port *sport = lpuart_ports[co->index];
17281738
unsigned long old_cr, cr;
1739+
unsigned long flags;
1740+
int locked = 1;
1741+
1742+
if (sport->port.sysrq || oops_in_progress)
1743+
locked = spin_trylock_irqsave(&sport->port.lock, flags);
1744+
else
1745+
spin_lock_irqsave(&sport->port.lock, flags);
17291746

17301747
/* first save CR2 and then disable interrupts */
17311748
cr = old_cr = lpuart32_read(sport->port.membase + UARTCTRL);
@@ -1740,6 +1757,9 @@ lpuart32_console_write(struct console *co, const char *s, unsigned int count)
17401757
barrier();
17411758

17421759
lpuart32_write(old_cr, sport->port.membase + UARTCTRL);
1760+
1761+
if (locked)
1762+
spin_unlock_irqrestore(&sport->port.lock, flags);
17431763
}
17441764

17451765
/*

0 commit comments

Comments
 (0)