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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
8975ed8c 150b59a7

+10 -10
+10 -10
drivers/tty/serial/pic32_uart.c
··· 243 243 struct pic32_sport *sport = to_pic32_sport(port); 244 244 unsigned long flags; 245 245 246 - spin_lock_irqsave(&port->lock, flags); 246 + uart_port_lock_irqsave(port, &flags); 247 247 248 248 if (ctl) 249 249 pic32_uart_writel(sport, PIC32_SET(PIC32_UART_STA), ··· 252 252 pic32_uart_writel(sport, PIC32_CLR(PIC32_UART_STA), 253 253 PIC32_UART_STA_UTXBRK); 254 254 255 - spin_unlock_irqrestore(&port->lock, flags); 255 + uart_port_unlock_irqrestore(port, flags); 256 256 } 257 257 258 258 /* get port type in string format */ ··· 274 274 */ 275 275 max_count = PIC32_UART_RX_FIFO_DEPTH; 276 276 277 - spin_lock(&port->lock); 277 + uart_port_lock(port); 278 278 279 279 tty = &port->state->port; 280 280 ··· 331 331 332 332 } while (--max_count); 333 333 334 - spin_unlock(&port->lock); 334 + uart_port_unlock(port); 335 335 336 336 tty_flip_buffer_push(tty); 337 337 } ··· 410 410 struct uart_port *port = dev_id; 411 411 unsigned long flags; 412 412 413 - spin_lock_irqsave(&port->lock, flags); 413 + uart_port_lock_irqsave(port, &flags); 414 414 pic32_uart_do_tx(port); 415 - spin_unlock_irqrestore(&port->lock, flags); 415 + uart_port_unlock_irqrestore(port, flags); 416 416 417 417 return IRQ_HANDLED; 418 418 } ··· 580 580 unsigned long flags; 581 581 582 582 /* disable uart */ 583 - spin_lock_irqsave(&port->lock, flags); 583 + uart_port_lock_irqsave(port, &flags); 584 584 pic32_uart_dsbl_and_mask(port); 585 - spin_unlock_irqrestore(&port->lock, flags); 585 + uart_port_unlock_irqrestore(port, flags); 586 586 clk_disable_unprepare(sport->clk); 587 587 588 588 /* free all 3 interrupts for this UART */ ··· 604 604 unsigned int quot; 605 605 unsigned long flags; 606 606 607 - spin_lock_irqsave(&port->lock, flags); 607 + uart_port_lock_irqsave(port, &flags); 608 608 609 609 /* disable uart and mask all interrupts while changing speed */ 610 610 pic32_uart_dsbl_and_mask(port); ··· 672 672 /* enable uart */ 673 673 pic32_uart_en_and_unmask(port); 674 674 675 - spin_unlock_irqrestore(&port->lock, flags); 675 + uart_port_unlock_irqrestore(port, flags); 676 676 } 677 677 678 678 /* serial core request to claim uart iomem */