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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
4f8cf64e 042d7848

+8 -8
+8 -8
drivers/tty/serial/milbeaut_usio.c
··· 207 207 { 208 208 struct uart_port *port = dev_id; 209 209 210 - spin_lock(&port->lock); 210 + uart_port_lock(port); 211 211 mlb_usio_rx_chars(port); 212 - spin_unlock(&port->lock); 212 + uart_port_unlock(port); 213 213 214 214 return IRQ_HANDLED; 215 215 } ··· 218 218 { 219 219 struct uart_port *port = dev_id; 220 220 221 - spin_lock(&port->lock); 221 + uart_port_lock(port); 222 222 if (readb(port->membase + MLB_USIO_REG_SSR) & MLB_USIO_SSR_TBI) 223 223 mlb_usio_tx_chars(port); 224 - spin_unlock(&port->lock); 224 + uart_port_unlock(port); 225 225 226 226 return IRQ_HANDLED; 227 227 } ··· 267 267 escr = readb(port->membase + MLB_USIO_REG_ESCR); 268 268 if (of_property_read_bool(port->dev->of_node, "auto-flow-control")) 269 269 escr |= MLB_USIO_ESCR_FLWEN; 270 - spin_lock_irqsave(&port->lock, flags); 270 + uart_port_lock_irqsave(port, &flags); 271 271 writeb(0, port->membase + MLB_USIO_REG_SCR); 272 272 writeb(escr, port->membase + MLB_USIO_REG_ESCR); 273 273 writeb(MLB_USIO_SCR_UPCL, port->membase + MLB_USIO_REG_SCR); ··· 282 282 283 283 writeb(MLB_USIO_SCR_TXE | MLB_USIO_SCR_RIE | MLB_USIO_SCR_TBIE | 284 284 MLB_USIO_SCR_RXE, port->membase + MLB_USIO_REG_SCR); 285 - spin_unlock_irqrestore(&port->lock, flags); 285 + uart_port_unlock_irqrestore(port, flags); 286 286 287 287 return 0; 288 288 } ··· 337 337 else 338 338 quot = 0; 339 339 340 - spin_lock_irqsave(&port->lock, flags); 340 + uart_port_lock_irqsave(port, &flags); 341 341 uart_update_timeout(port, termios->c_cflag, baud); 342 342 port->read_status_mask = MLB_USIO_SSR_ORE | MLB_USIO_SSR_RDRF | 343 343 MLB_USIO_SSR_TDRE; ··· 367 367 writew(BIT(12), port->membase + MLB_USIO_REG_FBYTE); 368 368 writeb(MLB_USIO_SCR_RIE | MLB_USIO_SCR_RXE | MLB_USIO_SCR_TBIE | 369 369 MLB_USIO_SCR_TXE, port->membase + MLB_USIO_REG_SCR); 370 - spin_unlock_irqrestore(&port->lock, flags); 370 + uart_port_unlock_irqrestore(port, flags); 371 371 } 372 372 373 373 static const char *mlb_usio_type(struct uart_port *port)