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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
e0e6d8b4 893d2251

+10 -10
+2 -2
drivers/tty/serial/jsm/jsm_neo.c
··· 816 816 /* Parse any modem signal changes */ 817 817 jsm_dbg(INTR, &ch->ch_bd->pci_dev, 818 818 "MOD_STAT: sending to parse_modem_sigs\n"); 819 - spin_lock_irqsave(&ch->uart_port.lock, lock_flags); 819 + uart_port_lock_irqsave(&ch->uart_port, &lock_flags); 820 820 neo_parse_modem(ch, readb(&ch->ch_neo_uart->msr)); 821 - spin_unlock_irqrestore(&ch->uart_port.lock, lock_flags); 821 + uart_port_unlock_irqrestore(&ch->uart_port, lock_flags); 822 822 } 823 823 } 824 824
+8 -8
drivers/tty/serial/jsm/jsm_tty.c
··· 152 152 container_of(port, struct jsm_channel, uart_port); 153 153 struct ktermios *termios; 154 154 155 - spin_lock_irqsave(&port->lock, lock_flags); 155 + uart_port_lock_irqsave(port, &lock_flags); 156 156 termios = &port->state->port.tty->termios; 157 157 if (ch == termios->c_cc[VSTART]) 158 158 channel->ch_bd->bd_ops->send_start_character(channel); 159 159 160 160 if (ch == termios->c_cc[VSTOP]) 161 161 channel->ch_bd->bd_ops->send_stop_character(channel); 162 - spin_unlock_irqrestore(&port->lock, lock_flags); 162 + uart_port_unlock_irqrestore(port, lock_flags); 163 163 } 164 164 165 165 static void jsm_tty_stop_rx(struct uart_port *port) ··· 176 176 struct jsm_channel *channel = 177 177 container_of(port, struct jsm_channel, uart_port); 178 178 179 - spin_lock_irqsave(&port->lock, lock_flags); 179 + uart_port_lock_irqsave(port, &lock_flags); 180 180 if (break_state == -1) 181 181 channel->ch_bd->bd_ops->send_break(channel); 182 182 else 183 183 channel->ch_bd->bd_ops->clear_break(channel); 184 184 185 - spin_unlock_irqrestore(&port->lock, lock_flags); 185 + uart_port_unlock_irqrestore(port, lock_flags); 186 186 } 187 187 188 188 static int jsm_tty_open(struct uart_port *port) ··· 241 241 channel->ch_cached_lsr = 0; 242 242 channel->ch_stops_sent = 0; 243 243 244 - spin_lock_irqsave(&port->lock, lock_flags); 244 + uart_port_lock_irqsave(port, &lock_flags); 245 245 termios = &port->state->port.tty->termios; 246 246 channel->ch_c_cflag = termios->c_cflag; 247 247 channel->ch_c_iflag = termios->c_iflag; ··· 261 261 jsm_carrier(channel); 262 262 263 263 channel->ch_open_count++; 264 - spin_unlock_irqrestore(&port->lock, lock_flags); 264 + uart_port_unlock_irqrestore(port, lock_flags); 265 265 266 266 jsm_dbg(OPEN, &channel->ch_bd->pci_dev, "finish\n"); 267 267 return 0; ··· 307 307 struct jsm_channel *channel = 308 308 container_of(port, struct jsm_channel, uart_port); 309 309 310 - spin_lock_irqsave(&port->lock, lock_flags); 310 + uart_port_lock_irqsave(port, &lock_flags); 311 311 channel->ch_c_cflag = termios->c_cflag; 312 312 channel->ch_c_iflag = termios->c_iflag; 313 313 channel->ch_c_oflag = termios->c_oflag; ··· 317 317 318 318 channel->ch_bd->bd_ops->param(channel); 319 319 jsm_carrier(channel); 320 - spin_unlock_irqrestore(&port->lock, lock_flags); 320 + uart_port_unlock_irqrestore(port, lock_flags); 321 321 } 322 322 323 323 static const char *jsm_tty_type(struct uart_port *port)