]> git.ipfire.org Git - thirdparty/linux.git/blobdiff - kernel/printk/printk.c
serial: Lock console when calling into driver before registration
[thirdparty/linux.git] / kernel / printk / printk.c
index f2444b581e16c3c3b4ef955ab89c2a0278436f7b..89f2aa2e1172f2222f5b82b2ec773b5ce2573710 100644 (file)
@@ -3263,6 +3263,21 @@ static int __init keep_bootcon_setup(char *str)
 
 early_param("keep_bootcon", keep_bootcon_setup);
 
+static int console_call_setup(struct console *newcon, char *options)
+{
+       int err;
+
+       if (!newcon->setup)
+               return 0;
+
+       /* Synchronize with possible boot console. */
+       console_lock();
+       err = newcon->setup(newcon, options);
+       console_unlock();
+
+       return err;
+}
+
 /*
  * This is called by register_console() to try to match
  * the newly registered console with any of the ones selected
@@ -3298,8 +3313,8 @@ static int try_enable_preferred_console(struct console *newcon,
                        if (_braille_register_console(newcon, c))
                                return 0;
 
-                       if (newcon->setup &&
-                           (err = newcon->setup(newcon, c->options)) != 0)
+                       err = console_call_setup(newcon, c->options);
+                       if (err)
                                return err;
                }
                newcon->flags |= CON_ENABLED;
@@ -3325,7 +3340,7 @@ static void try_enable_default_console(struct console *newcon)
        if (newcon->index < 0)
                newcon->index = 0;
 
-       if (newcon->setup && newcon->setup(newcon, NULL) != 0)
+       if (console_call_setup(newcon, NULL) != 0)
                return;
 
        newcon->flags |= CON_ENABLED;