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

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

authored by

Thomas Gleixner and committed by
Greg Kroah-Hartman
68dcb369 bf607dec

+13 -13
+13 -13
drivers/tty/serial/owl-uart.c
··· 125 125 u32 val; 126 126 unsigned int ret; 127 127 128 - spin_lock_irqsave(&port->lock, flags); 128 + uart_port_lock_irqsave(port, &flags); 129 129 130 130 val = owl_uart_read(port, OWL_UART_STAT); 131 131 ret = (val & OWL_UART_STAT_TFES) ? TIOCSER_TEMT : 0; 132 132 133 - spin_unlock_irqrestore(&port->lock, flags); 133 + uart_port_unlock_irqrestore(port, flags); 134 134 135 135 return ret; 136 136 } ··· 232 232 unsigned long flags; 233 233 u32 stat; 234 234 235 - spin_lock_irqsave(&port->lock, flags); 235 + uart_port_lock_irqsave(port, &flags); 236 236 237 237 stat = owl_uart_read(port, OWL_UART_STAT); 238 238 ··· 246 246 stat |= OWL_UART_STAT_RIP | OWL_UART_STAT_TIP; 247 247 owl_uart_write(port, stat, OWL_UART_STAT); 248 248 249 - spin_unlock_irqrestore(&port->lock, flags); 249 + uart_port_unlock_irqrestore(port, flags); 250 250 251 251 return IRQ_HANDLED; 252 252 } ··· 256 256 u32 val; 257 257 unsigned long flags; 258 258 259 - spin_lock_irqsave(&port->lock, flags); 259 + uart_port_lock_irqsave(port, &flags); 260 260 261 261 val = owl_uart_read(port, OWL_UART_CTL); 262 262 val &= ~(OWL_UART_CTL_TXIE | OWL_UART_CTL_RXIE 263 263 | OWL_UART_CTL_TXDE | OWL_UART_CTL_RXDE | OWL_UART_CTL_EN); 264 264 owl_uart_write(port, val, OWL_UART_CTL); 265 265 266 - spin_unlock_irqrestore(&port->lock, flags); 266 + uart_port_unlock_irqrestore(port, flags); 267 267 268 268 free_irq(port->irq, port); 269 269 } ··· 279 279 if (ret) 280 280 return ret; 281 281 282 - spin_lock_irqsave(&port->lock, flags); 282 + uart_port_lock_irqsave(port, &flags); 283 283 284 284 val = owl_uart_read(port, OWL_UART_STAT); 285 285 val |= OWL_UART_STAT_RIP | OWL_UART_STAT_TIP ··· 291 291 val |= OWL_UART_CTL_EN; 292 292 owl_uart_write(port, val, OWL_UART_CTL); 293 293 294 - spin_unlock_irqrestore(&port->lock, flags); 294 + uart_port_unlock_irqrestore(port, flags); 295 295 296 296 return 0; 297 297 } ··· 311 311 u32 ctl; 312 312 unsigned long flags; 313 313 314 - spin_lock_irqsave(&port->lock, flags); 314 + uart_port_lock_irqsave(port, &flags); 315 315 316 316 ctl = owl_uart_read(port, OWL_UART_CTL); 317 317 ··· 371 371 372 372 uart_update_timeout(port, termios->c_cflag, baud); 373 373 374 - spin_unlock_irqrestore(&port->lock, flags); 374 + uart_port_unlock_irqrestore(port, flags); 375 375 } 376 376 377 377 static void owl_uart_release_port(struct uart_port *port) ··· 515 515 if (port->sysrq) 516 516 locked = 0; 517 517 else if (oops_in_progress) 518 - locked = spin_trylock(&port->lock); 518 + locked = uart_port_trylock(port); 519 519 else { 520 - spin_lock(&port->lock); 520 + uart_port_lock(port); 521 521 locked = 1; 522 522 } 523 523 ··· 541 541 owl_uart_write(port, old_ctl, OWL_UART_CTL); 542 542 543 543 if (locked) 544 - spin_unlock(&port->lock); 544 + uart_port_unlock(port); 545 545 546 546 local_irq_restore(flags); 547 547 }