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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
b4a88fae 7c572c17

+10 -10
+10 -10
drivers/tty/serial/rp2.c
··· 276 276 * But the TXEMPTY bit doesn't seem to work unless the TX IRQ is 277 277 * enabled. 278 278 */ 279 - spin_lock_irqsave(&up->port.lock, flags); 279 + uart_port_lock_irqsave(&up->port, &flags); 280 280 tx_fifo_bytes = readw(up->base + RP2_TX_FIFO_COUNT); 281 - spin_unlock_irqrestore(&up->port.lock, flags); 281 + uart_port_unlock_irqrestore(&up->port, flags); 282 282 283 283 return tx_fifo_bytes ? 0 : TIOCSER_TEMT; 284 284 } ··· 323 323 { 324 324 unsigned long flags; 325 325 326 - spin_lock_irqsave(&port->lock, flags); 326 + uart_port_lock_irqsave(port, &flags); 327 327 rp2_rmw(port_to_up(port), RP2_TXRX_CTL, RP2_TXRX_CTL_BREAK_m, 328 328 break_state ? RP2_TXRX_CTL_BREAK_m : 0); 329 - spin_unlock_irqrestore(&port->lock, flags); 329 + uart_port_unlock_irqrestore(port, flags); 330 330 } 331 331 332 332 static void rp2_uart_enable_ms(struct uart_port *port) ··· 383 383 if (tty_termios_baud_rate(new)) 384 384 tty_termios_encode_baud_rate(new, baud, baud); 385 385 386 - spin_lock_irqsave(&port->lock, flags); 386 + uart_port_lock_irqsave(port, &flags); 387 387 388 388 /* ignore all characters if CREAD is not set */ 389 389 port->ignore_status_mask = (new->c_cflag & CREAD) ? 0 : RP2_DUMMY_READ; ··· 391 391 __rp2_uart_set_termios(up, new->c_cflag, new->c_iflag, baud_div); 392 392 uart_update_timeout(port, new->c_cflag, baud); 393 393 394 - spin_unlock_irqrestore(&port->lock, flags); 394 + uart_port_unlock_irqrestore(port, flags); 395 395 } 396 396 397 397 static void rp2_rx_chars(struct rp2_uart_port *up) ··· 440 440 { 441 441 u32 status; 442 442 443 - spin_lock(&up->port.lock); 443 + uart_port_lock(&up->port); 444 444 445 445 /* 446 446 * The IRQ status bits are clear-on-write. Other status bits in ··· 456 456 if (status & RP2_CHAN_STAT_MS_CHANGED_MASK) 457 457 wake_up_interruptible(&up->port.state->port.delta_msr_wait); 458 458 459 - spin_unlock(&up->port.lock); 459 + uart_port_unlock(&up->port); 460 460 } 461 461 462 462 static int rp2_asic_interrupt(struct rp2_card *card, unsigned int asic_id) ··· 516 516 517 517 rp2_uart_break_ctl(port, 0); 518 518 519 - spin_lock_irqsave(&port->lock, flags); 519 + uart_port_lock_irqsave(port, &flags); 520 520 rp2_mask_ch_irq(up, up->idx, 0); 521 521 rp2_rmw(up, RP2_CHAN_STAT, 0, 0); 522 - spin_unlock_irqrestore(&port->lock, flags); 522 + uart_port_unlock_irqrestore(port, flags); 523 523 } 524 524 525 525 static const char *rp2_uart_type(struct uart_port *port)