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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
9ed2d5d8 cf19e009

+8 -8
+8 -8
drivers/tty/serial/arc_uart.c
··· 279 279 if (status & RXIENB) { 280 280 281 281 /* already in ISR, no need of xx_irqsave */ 282 - spin_lock(&port->lock); 282 + uart_port_lock(port); 283 283 arc_serial_rx_chars(port, status); 284 - spin_unlock(&port->lock); 284 + uart_port_unlock(port); 285 285 } 286 286 287 287 if ((status & TXIENB) && (status & TXEMPTY)) { ··· 291 291 */ 292 292 UART_TX_IRQ_DISABLE(port); 293 293 294 - spin_lock(&port->lock); 294 + uart_port_lock(port); 295 295 296 296 if (!uart_tx_stopped(port)) 297 297 arc_serial_tx_chars(port); 298 298 299 - spin_unlock(&port->lock); 299 + uart_port_unlock(port); 300 300 } 301 301 302 302 return IRQ_HANDLED; ··· 366 366 uartl = hw_val & 0xFF; 367 367 uarth = (hw_val >> 8) & 0xFF; 368 368 369 - spin_lock_irqsave(&port->lock, flags); 369 + uart_port_lock_irqsave(port, &flags); 370 370 371 371 UART_ALL_IRQ_DISABLE(port); 372 372 ··· 391 391 392 392 uart_update_timeout(port, new->c_cflag, baud); 393 393 394 - spin_unlock_irqrestore(&port->lock, flags); 394 + uart_port_unlock_irqrestore(port, flags); 395 395 } 396 396 397 397 static const char *arc_serial_type(struct uart_port *port) ··· 521 521 struct uart_port *port = &arc_uart_ports[co->index].port; 522 522 unsigned long flags; 523 523 524 - spin_lock_irqsave(&port->lock, flags); 524 + uart_port_lock_irqsave(port, &flags); 525 525 uart_console_write(port, s, count, arc_serial_console_putchar); 526 - spin_unlock_irqrestore(&port->lock, flags); 526 + uart_port_unlock_irqrestore(port, flags); 527 527 } 528 528 529 529 static struct console arc_console = {