]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
tty: serial: kgdboc: use console_list_lock for list traversal
authorJohn Ogness <john.ogness@linutronix.de>
Wed, 16 Nov 2022 16:21:48 +0000 (17:27 +0106)
committerPetr Mladek <pmladek@suse.com>
Fri, 2 Dec 2022 10:25:02 +0000 (11:25 +0100)
configure_kgdboc() uses the console_lock for console list iteration. Use
the console_list_lock instead because list synchronization responsibility
will be removed from the console_lock in a later change.

The SRCU iterator could have been used here, but a later change will
relocate the locking of the console_list_lock to also provide
synchronization against register_console().

Note, the console_lock is still needed to serialize the device()
callback with other console operations.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
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-37-john.ogness@linutronix.de
drivers/tty/serial/kgdboc.c

index c6df9ef34099023683aaffbe8bcf6dba8a3b630b..82b4b4d67823d392e911dabb4d23e258249b59f2 100644 (file)
@@ -193,7 +193,16 @@ static int configure_kgdboc(void)
        if (!p)
                goto noconfig;
 
+       /* For safe traversal of the console list. */
+       console_list_lock();
+
+       /*
+        * Take console_lock to serialize device() callback with
+        * other console operations. For example, fg_console is
+        * modified under console_lock when switching vt.
+        */
        console_lock();
+
        for_each_console(cons) {
                int idx;
                if (cons->device && cons->device(cons, &idx) == p &&
@@ -202,8 +211,11 @@ static int configure_kgdboc(void)
                        break;
                }
        }
+
        console_unlock();
 
+       console_list_unlock();
+
        kgdb_tty_driver = p;
        kgdb_tty_line = tty_line;