diff options
author | John Ogness <john.ogness@linutronix.de> | 2022-11-16 19:21:32 +0300 |
---|---|---|
committer | Petr Mladek <pmladek@suse.com> | 2022-12-02 13:25:01 +0300 |
commit | 8cb15f7f492f85d695a6f4d12044c47230f69d96 (patch) | |
tree | 41f575078a02039fea2204821414562413dd71b4 /kernel/printk | |
parent | 87f2e4b7d9e5c50756184b4f8d0b92680de61496 (diff) | |
download | linux-8cb15f7f492f85d695a6f4d12044c47230f69d96.tar.xz |
printk: console_device: use srcu console list iterator
Use srcu console list iteration for console list traversal. It is
acceptable because the consoles might come and go at any time.
Strict synchronizing with console registration code would not bring
any advantage over srcu.
Document why the console_lock is still necessary. Note that this
is a preparatory change for when console_lock no longer provides
synchronization for the console list.
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-21-john.ogness@linutronix.de
Diffstat (limited to 'kernel/printk')
-rw-r--r-- | kernel/printk/printk.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index b78947077659..101d08d9dc88 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -3077,15 +3077,25 @@ struct tty_driver *console_device(int *index) { struct console *c; struct tty_driver *driver = NULL; + int cookie; + /* + * 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(c) { + + cookie = console_srcu_read_lock(); + for_each_console_srcu(c) { if (!c->device) continue; driver = c->device(c, index); if (driver) break; } + console_srcu_read_unlock(cookie); + console_unlock(); return driver; } |