Skip to content

Commit

Permalink
tty: serial: kgdboc: synchronize tty_find_polling_driver() and regist…
Browse files Browse the repository at this point in the history
…er_console()

Calling tty_find_polling_driver() can lead to uart_set_options() being
called (via the poll_init() callback of tty_operations) to configure the
uart. But uart_set_options() can also be called by register_console()
(via the setup() callback of console).

Take the console_list_lock to synchronize against register_console() and
also use it for console list traversal. This also ensures the console list
cannot change until the polling console has been chosen.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20221116162152.193147-38-john.ogness@linutronix.de
  • Loading branch information
John Ogness authored and Petr Mladek committed Dec 2, 2022
1 parent 6685744 commit 6193bc9
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drivers/tty/serial/kgdboc.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,20 @@ static int configure_kgdboc(void)
if (kgdboc_register_kbd(&cptr))
goto do_register;

/*
* tty_find_polling_driver() can call uart_set_options()
* (via poll_init) to configure the uart. Take the console_list_lock
* in order to synchronize against register_console(), which can also
* configure the uart via uart_set_options(). This also allows safe
* traversal of the console list.
*/
console_list_lock();

p = tty_find_polling_driver(cptr, &tty_line);
if (!p)
if (!p) {
console_list_unlock();
goto noconfig;

/* For safe traversal of the console list. */
console_list_lock();
}

/*
* Take console_lock to serialize device() callback with
Expand Down

0 comments on commit 6193bc9

Please sign in to comment.