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

serial: vt8500: 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-74-john.ogness@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
4bfdd1ed e21d6c8d

+4 -4
+4 -4
drivers/tty/serial/vt8500_serial.c
··· 227 227 struct uart_port *port = dev_id; 228 228 unsigned long isr; 229 229 230 - spin_lock(&port->lock); 230 + uart_port_lock(port); 231 231 isr = vt8500_read(port, VT8500_URISR); 232 232 233 233 /* Acknowledge active status bits */ ··· 240 240 if (isr & TCTS) 241 241 handle_delta_cts(port); 242 242 243 - spin_unlock(&port->lock); 243 + uart_port_unlock(port); 244 244 245 245 return IRQ_HANDLED; 246 246 } ··· 342 342 unsigned int baud, lcr; 343 343 unsigned int loops = 1000; 344 344 345 - spin_lock_irqsave(&port->lock, flags); 345 + uart_port_lock_irqsave(port, &flags); 346 346 347 347 /* calculate and set baud rate */ 348 348 baud = uart_get_baud_rate(port, termios, old, 900, 921600); ··· 410 410 vt8500_write(&vt8500_port->uart, 0x881, VT8500_URFCR); 411 411 vt8500_write(&vt8500_port->uart, vt8500_port->ier, VT8500_URIER); 412 412 413 - spin_unlock_irqrestore(&port->lock, flags); 413 + uart_port_unlock_irqrestore(port, flags); 414 414 } 415 415 416 416 static const char *vt8500_type(struct uart_port *port)