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

serial: introduce uart_port_lock() guard()s

Having this, guards like these work:
guard(uart_port_lock_irq)(&up->port);
or
scoped_guard(uart_port_lock_irqsave, port) {
...
}

See e.g. "serial: 8250: use guard()s" later in this series.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250814072456.182853-4-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
0fd60b68 e8398b8a

+13
+13
include/linux/serial_core.h
··· 788 788 spin_unlock_irqrestore(&up->lock, flags); 789 789 } 790 790 791 + DEFINE_GUARD(uart_port_lock, struct uart_port *, uart_port_lock(_T), uart_port_unlock(_T)); 792 + DEFINE_GUARD_COND(uart_port_lock, _try, uart_port_trylock(_T)); 793 + 794 + DEFINE_GUARD(uart_port_lock_irq, struct uart_port *, uart_port_lock_irq(_T), 795 + uart_port_unlock_irq(_T)); 796 + 797 + DEFINE_LOCK_GUARD_1(uart_port_lock_irqsave, struct uart_port, 798 + uart_port_lock_irqsave(_T->lock, &_T->flags), 799 + uart_port_unlock_irqrestore(_T->lock, _T->flags), 800 + unsigned long flags); 801 + DEFINE_LOCK_GUARD_1_COND(uart_port_lock_irqsave, _try, 802 + uart_port_trylock_irqsave(_T->lock, &_T->flags)); 803 + 791 804 static inline int serial_port_in(struct uart_port *up, int offset) 792 805 { 793 806 return up->serial_in(up, offset);