Skip to content

Commit 8cb15f7

Browse files
jognesspmladek
authored andcommitted
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
1 parent 87f2e4b commit 8cb15f7

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

kernel/printk/printk.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3077,15 +3077,25 @@ struct tty_driver *console_device(int *index)
30773077
{
30783078
struct console *c;
30793079
struct tty_driver *driver = NULL;
3080+
int cookie;
30803081

3082+
/*
3083+
* Take console_lock to serialize device() callback with
3084+
* other console operations. For example, fg_console is
3085+
* modified under console_lock when switching vt.
3086+
*/
30813087
console_lock();
3082-
for_each_console(c) {
3088+
3089+
cookie = console_srcu_read_lock();
3090+
for_each_console_srcu(c) {
30833091
if (!c->device)
30843092
continue;
30853093
driver = c->device(c, index);
30863094
if (driver)
30873095
break;
30883096
}
3097+
console_srcu_read_unlock(cookie);
3098+
30893099
console_unlock();
30903100
return driver;
30913101
}

0 commit comments

Comments
 (0)