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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
5412c394 68ca3e72

+4 -4
+4 -4
drivers/tty/serial/apbuart.c
··· 133 133 struct uart_port *port = dev_id; 134 134 unsigned int status; 135 135 136 - spin_lock(&port->lock); 136 + uart_port_lock(port); 137 137 138 138 status = UART_GET_STATUS(port); 139 139 if (status & UART_STATUS_DR) ··· 141 141 if (status & UART_STATUS_THE) 142 142 apbuart_tx_chars(port); 143 143 144 - spin_unlock(&port->lock); 144 + uart_port_unlock(port); 145 145 146 146 return IRQ_HANDLED; 147 147 } ··· 228 228 if (termios->c_cflag & CRTSCTS) 229 229 cr |= UART_CTRL_FL; 230 230 231 - spin_lock_irqsave(&port->lock, flags); 231 + uart_port_lock_irqsave(port, &flags); 232 232 233 233 /* Update the per-port timeout. */ 234 234 uart_update_timeout(port, termios->c_cflag, baud); ··· 251 251 UART_PUT_SCAL(port, quot); 252 252 UART_PUT_CTRL(port, cr); 253 253 254 - spin_unlock_irqrestore(&port->lock, flags); 254 + uart_port_unlock_irqrestore(port, flags); 255 255 } 256 256 257 257 static const char *apbuart_type(struct uart_port *port)