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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
bf607dec f9b7652c

+19 -19
+19 -19
drivers/tty/serial/omap-serial.c
··· 390 390 struct uart_omap_port *up = to_uart_omap_port(port); 391 391 unsigned long flags; 392 392 393 - spin_lock_irqsave(&up->port.lock, flags); 393 + uart_port_lock_irqsave(&up->port, &flags); 394 394 up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); 395 395 serial_out(up, UART_IER, up->ier); 396 - spin_unlock_irqrestore(&up->port.lock, flags); 396 + uart_port_unlock_irqrestore(&up->port, flags); 397 397 } 398 398 399 399 static void serial_omap_unthrottle(struct uart_port *port) ··· 401 401 struct uart_omap_port *up = to_uart_omap_port(port); 402 402 unsigned long flags; 403 403 404 - spin_lock_irqsave(&up->port.lock, flags); 404 + uart_port_lock_irqsave(&up->port, &flags); 405 405 up->ier |= UART_IER_RLSI | UART_IER_RDI; 406 406 serial_out(up, UART_IER, up->ier); 407 - spin_unlock_irqrestore(&up->port.lock, flags); 407 + uart_port_unlock_irqrestore(&up->port, flags); 408 408 } 409 409 410 410 static unsigned int check_modem_status(struct uart_omap_port *up) ··· 527 527 irqreturn_t ret = IRQ_NONE; 528 528 int max_count = 256; 529 529 530 - spin_lock(&up->port.lock); 530 + uart_port_lock(&up->port); 531 531 532 532 do { 533 533 iir = serial_in(up, UART_IIR); ··· 563 563 } 564 564 } while (max_count--); 565 565 566 - spin_unlock(&up->port.lock); 566 + uart_port_unlock(&up->port); 567 567 568 568 tty_flip_buffer_push(&up->port.state->port); 569 569 ··· 579 579 unsigned int ret = 0; 580 580 581 581 dev_dbg(up->port.dev, "serial_omap_tx_empty+%d\n", up->port.line); 582 - spin_lock_irqsave(&up->port.lock, flags); 582 + uart_port_lock_irqsave(&up->port, &flags); 583 583 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0; 584 - spin_unlock_irqrestore(&up->port.lock, flags); 584 + uart_port_unlock_irqrestore(&up->port, flags); 585 585 586 586 return ret; 587 587 } ··· 647 647 unsigned long flags; 648 648 649 649 dev_dbg(up->port.dev, "serial_omap_break_ctl+%d\n", up->port.line); 650 - spin_lock_irqsave(&up->port.lock, flags); 650 + uart_port_lock_irqsave(&up->port, &flags); 651 651 if (break_state == -1) 652 652 up->lcr |= UART_LCR_SBC; 653 653 else 654 654 up->lcr &= ~UART_LCR_SBC; 655 655 serial_out(up, UART_LCR, up->lcr); 656 - spin_unlock_irqrestore(&up->port.lock, flags); 656 + uart_port_unlock_irqrestore(&up->port, flags); 657 657 } 658 658 659 659 static int serial_omap_startup(struct uart_port *port) ··· 701 701 * Now, initialize the UART 702 702 */ 703 703 serial_out(up, UART_LCR, UART_LCR_WLEN8); 704 - spin_lock_irqsave(&up->port.lock, flags); 704 + uart_port_lock_irqsave(&up->port, &flags); 705 705 /* 706 706 * Most PC uarts need OUT2 raised to enable interrupts. 707 707 */ 708 708 up->port.mctrl |= TIOCM_OUT2; 709 709 serial_omap_set_mctrl(&up->port, up->port.mctrl); 710 - spin_unlock_irqrestore(&up->port.lock, flags); 710 + uart_port_unlock_irqrestore(&up->port, flags); 711 711 712 712 up->msr_saved_flags = 0; 713 713 /* ··· 742 742 up->ier = 0; 743 743 serial_out(up, UART_IER, 0); 744 744 745 - spin_lock_irqsave(&up->port.lock, flags); 745 + uart_port_lock_irqsave(&up->port, &flags); 746 746 up->port.mctrl &= ~TIOCM_OUT2; 747 747 serial_omap_set_mctrl(&up->port, up->port.mctrl); 748 - spin_unlock_irqrestore(&up->port.lock, flags); 748 + uart_port_unlock_irqrestore(&up->port, flags); 749 749 750 750 /* 751 751 * Disable break condition and FIFOs ··· 815 815 * Ok, we're now changing the port state. Do it with 816 816 * interrupts disabled. 817 817 */ 818 - spin_lock_irqsave(&up->port.lock, flags); 818 + uart_port_lock_irqsave(&up->port, &flags); 819 819 820 820 /* 821 821 * Update the per-port timeout. ··· 1013 1013 1014 1014 serial_omap_set_mctrl(&up->port, up->port.mctrl); 1015 1015 1016 - spin_unlock_irqrestore(&up->port.lock, flags); 1016 + uart_port_unlock_irqrestore(&up->port, flags); 1017 1017 dev_dbg(up->port.dev, "serial_omap_set_termios+%d\n", up->port.line); 1018 1018 } 1019 1019 ··· 1216 1216 if (up->port.sysrq) 1217 1217 locked = 0; 1218 1218 else if (oops_in_progress) 1219 - locked = spin_trylock(&up->port.lock); 1219 + locked = uart_port_trylock(&up->port); 1220 1220 else 1221 - spin_lock(&up->port.lock); 1221 + uart_port_lock(&up->port); 1222 1222 1223 1223 /* 1224 1224 * First save the IER then disable the interrupts ··· 1245 1245 check_modem_status(up); 1246 1246 1247 1247 if (locked) 1248 - spin_unlock(&up->port.lock); 1248 + uart_port_unlock(&up->port); 1249 1249 local_irq_restore(flags); 1250 1250 } 1251 1251