Skip to content

Commit 452b9b2

Browse files
jognesspmladek
authored andcommitted
serial_core: replace uart_console_enabled() with uart_console_registered()
All users of uart_console_enabled() really want to know if a console is registered. It is not reliable to check for CON_ENABLED in order to identify if a console is registered. Use console_is_registered() instead. A _locked() variant is provided because uart_set_options() is always called with the console_list_lock held and must check if a console is registered in order to synchronize with kgdboc. Signed-off-by: John Ogness <john.ogness@linutronix.de> Reviewed-by: Petr Mladek <pmladek@suse.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20221116162152.193147-23-john.ogness@linutronix.de
1 parent 1fd4224 commit 452b9b2

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

drivers/tty/serial/8250/8250_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev)
565565

566566
up->port.dev = dev;
567567

568-
if (uart_console_enabled(&up->port))
568+
if (uart_console_registered(&up->port))
569569
pm_runtime_get_sync(up->port.dev);
570570

571571
serial8250_apply_quirks(up);

drivers/tty/serial/pic32_uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ static int pic32_uart_probe(struct platform_device *pdev)
919919
}
920920

921921
#ifdef CONFIG_SERIAL_PIC32_CONSOLE
922-
if (uart_console_enabled(port)) {
922+
if (uart_console_registered(port)) {
923923
/* The peripheral clock has been enabled by console_setup,
924924
* so disable it till the port is used.
925925
*/

drivers/tty/serial/serial_core.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,11 +2223,11 @@ uart_set_options(struct uart_port *port, struct console *co,
22232223
/*
22242224
* Ensure that the serial-console lock is initialised early.
22252225
*
2226-
* Note that the console-enabled check is needed because of kgdboc,
2227-
* which can end up calling uart_set_options() for an already enabled
2226+
* Note that the console-registered check is needed because
2227+
* kgdboc can call uart_set_options() for an already registered
22282228
* console via tty_find_polling_driver() and uart_poll_init().
22292229
*/
2230-
if (!uart_console_enabled(port) && !port->console_reinit)
2230+
if (!uart_console_registered_locked(port) && !port->console_reinit)
22312231
uart_port_spin_lock_init(port);
22322232

22332233
memset(&termios, 0, sizeof(struct ktermios));
@@ -2573,7 +2573,7 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
25732573
* successfully registered yet, try to re-register it.
25742574
* It may be that the port was not available.
25752575
*/
2576-
if (port->cons && !(port->cons->flags & CON_ENABLED))
2576+
if (port->cons && !console_is_registered(port->cons))
25772577
register_console(port->cons);
25782578

25792579
/*
@@ -2956,7 +2956,7 @@ static ssize_t console_show(struct device *dev,
29562956
mutex_lock(&port->mutex);
29572957
uport = uart_port_check(state);
29582958
if (uport)
2959-
console = uart_console_enabled(uport);
2959+
console = uart_console_registered(uport);
29602960
mutex_unlock(&port->mutex);
29612961

29622962
return sprintf(buf, "%c\n", console ? 'Y' : 'N');
@@ -2978,7 +2978,7 @@ static ssize_t console_store(struct device *dev,
29782978
mutex_lock(&port->mutex);
29792979
uport = uart_port_check(state);
29802980
if (uport) {
2981-
oldconsole = uart_console_enabled(uport);
2981+
oldconsole = uart_console_registered(uport);
29822982
if (oldconsole && !newconsole) {
29832983
ret = unregister_console(uport->cons);
29842984
} else if (!oldconsole && newconsole) {
@@ -3086,7 +3086,7 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
30863086
* If this port is in use as a console then the spinlock is already
30873087
* initialised.
30883088
*/
3089-
if (!uart_console_enabled(uport))
3089+
if (!uart_console_registered(uport))
30903090
uart_port_spin_lock_init(uport);
30913091

30923092
if (uport->cons && uport->dev)

include/linux/serial_core.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,15 @@ static const bool earlycon_acpi_spcr_enable EARLYCON_USED_OR_UNUSED;
743743
static inline int setup_earlycon(char *buf) { return 0; }
744744
#endif
745745

746-
static inline bool uart_console_enabled(struct uart_port *port)
746+
/* Variant of uart_console_registered() when the console_list_lock is held. */
747+
static inline bool uart_console_registered_locked(struct uart_port *port)
747748
{
748-
return uart_console(port) && (port->cons->flags & CON_ENABLED);
749+
return uart_console(port) && console_is_registered_locked(port->cons);
750+
}
751+
752+
static inline bool uart_console_registered(struct uart_port *port)
753+
{
754+
return uart_console(port) && console_is_registered(port->cons);
749755
}
750756

751757
struct uart_port *uart_get_console(struct uart_port *ports, int nr,

0 commit comments

Comments
 (0)