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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
f82723d0 4f8cf64e

+6 -6
+6 -6
drivers/tty/serial/mpc52xx_uart.c
··· 1096 1096 mpc52xx_uart_break_ctl(struct uart_port *port, int ctl) 1097 1097 { 1098 1098 unsigned long flags; 1099 - spin_lock_irqsave(&port->lock, flags); 1099 + uart_port_lock_irqsave(port, &flags); 1100 1100 1101 1101 if (ctl == -1) 1102 1102 psc_ops->command(port, MPC52xx_PSC_START_BRK); 1103 1103 else 1104 1104 psc_ops->command(port, MPC52xx_PSC_STOP_BRK); 1105 1105 1106 - spin_unlock_irqrestore(&port->lock, flags); 1106 + uart_port_unlock_irqrestore(port, flags); 1107 1107 } 1108 1108 1109 1109 static int ··· 1214 1214 } 1215 1215 1216 1216 /* Get the lock */ 1217 - spin_lock_irqsave(&port->lock, flags); 1217 + uart_port_lock_irqsave(port, &flags); 1218 1218 1219 1219 /* Do our best to flush TX & RX, so we don't lose anything */ 1220 1220 /* But we don't wait indefinitely ! */ ··· 1250 1250 psc_ops->command(port, MPC52xx_PSC_RX_ENABLE); 1251 1251 1252 1252 /* We're all set, release the lock */ 1253 - spin_unlock_irqrestore(&port->lock, flags); 1253 + uart_port_unlock_irqrestore(port, flags); 1254 1254 } 1255 1255 1256 1256 static const char * ··· 1477 1477 struct uart_port *port = dev_id; 1478 1478 irqreturn_t ret; 1479 1479 1480 - spin_lock(&port->lock); 1480 + uart_port_lock(port); 1481 1481 1482 1482 ret = psc_ops->handle_irq(port); 1483 1483 1484 - spin_unlock(&port->lock); 1484 + uart_port_unlock(port); 1485 1485 1486 1486 return ret; 1487 1487 }