diff options
author | John Ogness <john.ogness@linutronix.de> | 2024-08-20 08:35:37 +0206 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2024-08-21 14:56:23 +0200 |
commit | eabd4600dafacf9895184259373f2445ff748654 (patch) | |
tree | 90b91a5ba7f25e2418caceae5475672a51e3e7f6 /include/linux/serial_core.h | |
parent | 77e73c0687f5bc884fa1b0cb97aca912bcc01957 (diff) |
serial: core: Introduce wrapper to set @uart_port->cons
Introduce uart_port_set_cons() as a wrapper to set @cons of a
uart_port. The wrapper sets @cons under the port lock in order
to prevent @cons from disappearing while another context is
holding the port lock. This is necessary for a follow-up
commit relating to the port lock wrappers, which rely on @cons
not changing between lock and unlock.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Tested-by: Théo Lebrun <theo.lebrun@bootlin.com> # EyeQ5, AMBA-PL011
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20240820063001.36405-12-john.ogness@linutronix.de
Signed-off-by: Petr Mladek <pmladek@suse.com>
Diffstat (limited to 'include/linux/serial_core.h')
-rw-r--r-- | include/linux/serial_core.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 8872cd21e70a..2cf03ff2056a 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -609,6 +609,23 @@ static inline void __uart_port_unlock_irqrestore(struct uart_port *up, unsigned } /** + * uart_port_set_cons - Safely set the @cons field for a uart + * @up: The uart port to set + * @con: The new console to set to + * + * This function must be used to set @up->cons. It uses the port lock to + * synchronize with the port lock wrappers in order to ensure that the console + * cannot change or disappear while another context is holding the port lock. + */ +static inline void uart_port_set_cons(struct uart_port *up, struct console *con) +{ + unsigned long flags; + + __uart_port_lock_irqsave(up, &flags); + up->cons = con; + __uart_port_unlock_irqrestore(up, flags); +} +/** * uart_port_lock - Lock the UART port * @up: Pointer to UART port structure */ |