Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

serial: timbuart: Use port lock wrappers

When a serial port is used for kernel console output, then all
modifications to the UART registers which are done from other contexts,
e.g. getty, termios, are interference points for the kernel console.

So far this has been ignored and the printk output is based on the
principle of hope. The rework of the console infrastructure which aims to
support threaded and atomic consoles, requires to mark sections which
modify the UART registers as unsafe. This allows the atomic write function
to make informed decisions and eventually to restore operational state. It
also allows to prevent the regular UART code from modifying UART registers
while printk output is in progress.

All modifications of UART registers are guarded by the UART port lock,
which provides an obvious synchronization point with the console
infrastructure.

To avoid adding this functionality to all UART drivers, wrap the
spin_[un]lock*() invocations for uart_port::lock into helper functions
which just contain the spin_[un]lock*() invocations for now. In a
subsequent step these helpers will gain the console synchronization
mechanisms.

Converted with coccinelle. No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/r/20230914183831.587273-71-john.ogness@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
07e89352 3d728b9e

+4 -4
+4 -4
drivers/tty/serial/timbuart.c
··· 174 174 struct timbuart_port *uart = from_tasklet(uart, t, tasklet); 175 175 u32 isr, ier = 0; 176 176 177 - spin_lock(&uart->port.lock); 177 + uart_port_lock(&uart->port); 178 178 179 179 isr = ioread32(uart->port.membase + TIMBUART_ISR); 180 180 dev_dbg(uart->port.dev, "%s ISR: %x\n", __func__, isr); ··· 189 189 190 190 iowrite32(ier, uart->port.membase + TIMBUART_IER); 191 191 192 - spin_unlock(&uart->port.lock); 192 + uart_port_unlock(&uart->port); 193 193 dev_dbg(uart->port.dev, "%s leaving\n", __func__); 194 194 } 195 195 ··· 295 295 tty_termios_copy_hw(termios, old); 296 296 tty_termios_encode_baud_rate(termios, baud, baud); 297 297 298 - spin_lock_irqsave(&port->lock, flags); 298 + uart_port_lock_irqsave(port, &flags); 299 299 iowrite8((u8)bindex, port->membase + TIMBUART_BAUDRATE); 300 300 uart_update_timeout(port, termios->c_cflag, baud); 301 - spin_unlock_irqrestore(&port->lock, flags); 301 + uart_port_unlock_irqrestore(port, flags); 302 302 } 303 303 304 304 static const char *timbuart_type(struct uart_port *port)