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>
This commit is contained in:
Jiri Slaby (SUSE) 2025-08-14 09:24:43 +02:00 committed by Greg Kroah-Hartman
parent e8398b8aed
commit 0fd60b689b
1 changed files with 13 additions and 0 deletions

View File

@ -788,6 +788,19 @@ static inline void uart_port_unlock_irqrestore(struct uart_port *up, unsigned lo
spin_unlock_irqrestore(&up->lock, flags);
}
DEFINE_GUARD(uart_port_lock, struct uart_port *, uart_port_lock(_T), uart_port_unlock(_T));
DEFINE_GUARD_COND(uart_port_lock, _try, uart_port_trylock(_T));
DEFINE_GUARD(uart_port_lock_irq, struct uart_port *, uart_port_lock_irq(_T),
uart_port_unlock_irq(_T));
DEFINE_LOCK_GUARD_1(uart_port_lock_irqsave, struct uart_port,
uart_port_lock_irqsave(_T->lock, &_T->flags),
uart_port_unlock_irqrestore(_T->lock, _T->flags),
unsigned long flags);
DEFINE_LOCK_GUARD_1_COND(uart_port_lock_irqsave, _try,
uart_port_trylock_irqsave(_T->lock, &_T->flags));
static inline int serial_port_in(struct uart_port *up, int offset)
{
return up->serial_in(up, offset);