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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
dab781d2 f82723d0

+8 -8
+8 -8
drivers/tty/serial/mps2-uart.c
··· 188 188 if (unlikely(!(irqflag & UARTn_INT_RX))) 189 189 return IRQ_NONE; 190 190 191 - spin_lock(&port->lock); 191 + uart_port_lock(port); 192 192 193 193 mps2_uart_write8(port, UARTn_INT_RX, UARTn_INT); 194 194 mps2_uart_rx_chars(port); 195 195 196 - spin_unlock(&port->lock); 196 + uart_port_unlock(port); 197 197 198 198 return IRQ_HANDLED; 199 199 } ··· 206 206 if (unlikely(!(irqflag & UARTn_INT_TX))) 207 207 return IRQ_NONE; 208 208 209 - spin_lock(&port->lock); 209 + uart_port_lock(port); 210 210 211 211 mps2_uart_write8(port, UARTn_INT_TX, UARTn_INT); 212 212 mps2_uart_tx_chars(port); 213 213 214 - spin_unlock(&port->lock); 214 + uart_port_unlock(port); 215 215 216 216 return IRQ_HANDLED; 217 217 } ··· 222 222 struct uart_port *port = data; 223 223 u8 irqflag = mps2_uart_read8(port, UARTn_INT); 224 224 225 - spin_lock(&port->lock); 225 + uart_port_lock(port); 226 226 227 227 if (irqflag & UARTn_INT_RX_OVERRUN) { 228 228 struct tty_port *tport = &port->state->port; ··· 244 244 handled = IRQ_HANDLED; 245 245 } 246 246 247 - spin_unlock(&port->lock); 247 + uart_port_unlock(port); 248 248 249 249 return handled; 250 250 } ··· 356 356 357 357 bauddiv = DIV_ROUND_CLOSEST(port->uartclk, baud); 358 358 359 - spin_lock_irqsave(&port->lock, flags); 359 + uart_port_lock_irqsave(port, &flags); 360 360 361 361 uart_update_timeout(port, termios->c_cflag, baud); 362 362 mps2_uart_write32(port, bauddiv, UARTn_BAUDDIV); 363 363 364 - spin_unlock_irqrestore(&port->lock, flags); 364 + uart_port_unlock_irqrestore(port, flags); 365 365 366 366 if (tty_termios_baud_rate(termios)) 367 367 tty_termios_encode_baud_rate(termios, baud, baud);