@@ -280,7 +280,6 @@ static struct console *exclusive_console;
280280static struct console_cmdline console_cmdline [MAX_CMDLINECONSOLES ];
281281
282282static int preferred_console = -1 ;
283- static bool has_preferred_console ;
284283int console_set_on_cmdline ;
285284EXPORT_SYMBOL (console_set_on_cmdline );
286285
@@ -2861,7 +2860,8 @@ early_param("keep_bootcon", keep_bootcon_setup);
28612860 * Care need to be taken with consoles that are statically
28622861 * enabled such as netconsole
28632862 */
2864- static int try_enable_new_console (struct console * newcon , bool user_specified )
2863+ static int try_enable_preferred_console (struct console * newcon ,
2864+ bool user_specified )
28652865{
28662866 struct console_cmdline * c ;
28672867 int i , err ;
@@ -2891,10 +2891,8 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
28912891 return err ;
28922892 }
28932893 newcon -> flags |= CON_ENABLED ;
2894- if (i == preferred_console ) {
2894+ if (i == preferred_console )
28952895 newcon -> flags |= CON_CONSDEV ;
2896- has_preferred_console = true;
2897- }
28982896 return 0 ;
28992897 }
29002898
@@ -2909,6 +2907,21 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
29092907 return - ENOENT ;
29102908}
29112909
2910+ /* Try to enable the console unconditionally */
2911+ static void try_enable_default_console (struct console * newcon )
2912+ {
2913+ if (newcon -> index < 0 )
2914+ newcon -> index = 0 ;
2915+
2916+ if (newcon -> setup && newcon -> setup (newcon , NULL ) != 0 )
2917+ return ;
2918+
2919+ newcon -> flags |= CON_ENABLED ;
2920+
2921+ if (newcon -> device )
2922+ newcon -> flags |= CON_CONSDEV ;
2923+ }
2924+
29122925/*
29132926 * The console driver calls this routine during kernel initialization
29142927 * to register the console printing procedure with printk() and to
@@ -2930,59 +2943,56 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
29302943 */
29312944void register_console (struct console * newcon )
29322945{
2933- struct console * bcon = NULL ;
2946+ struct console * con ;
2947+ bool bootcon_enabled = false;
2948+ bool realcon_enabled = false;
29342949 int err ;
29352950
2936- for_each_console (bcon ) {
2937- if (WARN (bcon == newcon , "console '%s%d' already registered\n" ,
2938- bcon -> name , bcon -> index ))
2951+ for_each_console (con ) {
2952+ if (WARN (con == newcon , "console '%s%d' already registered\n" ,
2953+ con -> name , con -> index ))
29392954 return ;
29402955 }
29412956
2942- /*
2943- * before we register a new CON_BOOT console, make sure we don't
2944- * already have a valid console
2945- */
2946- if (newcon -> flags & CON_BOOT ) {
2947- for_each_console (bcon ) {
2948- if (!(bcon -> flags & CON_BOOT )) {
2949- pr_info ("Too late to register bootconsole %s%d\n" ,
2950- newcon -> name , newcon -> index );
2951- return ;
2952- }
2953- }
2957+ for_each_console (con ) {
2958+ if (con -> flags & CON_BOOT )
2959+ bootcon_enabled = true;
2960+ else
2961+ realcon_enabled = true;
29542962 }
29552963
2956- if (console_drivers && console_drivers -> flags & CON_BOOT )
2957- bcon = console_drivers ;
2958-
2959- if (!has_preferred_console || bcon || !console_drivers )
2960- has_preferred_console = preferred_console >= 0 ;
2964+ /* Do not register boot consoles when there already is a real one. */
2965+ if (newcon -> flags & CON_BOOT && realcon_enabled ) {
2966+ pr_info ("Too late to register bootconsole %s%d\n" ,
2967+ newcon -> name , newcon -> index );
2968+ return ;
2969+ }
29612970
29622971 /*
2963- * See if we want to use this console driver. If we
2964- * didn't select a console we take the first one
2965- * that registers here.
2972+ * See if we want to enable this console driver by default.
2973+ *
2974+ * Nope when a console is preferred by the command line, device
2975+ * tree, or SPCR.
2976+ *
2977+ * The first real console with tty binding (driver) wins. More
2978+ * consoles might get enabled before the right one is found.
2979+ *
2980+ * Note that a console with tty binding will have CON_CONSDEV
2981+ * flag set and will be first in the list.
29662982 */
2967- if (!has_preferred_console ) {
2968- if (newcon -> index < 0 )
2969- newcon -> index = 0 ;
2970- if (newcon -> setup == NULL ||
2971- newcon -> setup (newcon , NULL ) == 0 ) {
2972- newcon -> flags |= CON_ENABLED ;
2973- if (newcon -> device ) {
2974- newcon -> flags |= CON_CONSDEV ;
2975- has_preferred_console = true;
2976- }
2983+ if (preferred_console < 0 ) {
2984+ if (!console_drivers || !console_drivers -> device ||
2985+ console_drivers -> flags & CON_BOOT ) {
2986+ try_enable_default_console (newcon );
29772987 }
29782988 }
29792989
29802990 /* See if this console matches one we selected on the command line */
2981- err = try_enable_new_console (newcon , true);
2991+ err = try_enable_preferred_console (newcon , true);
29822992
29832993 /* If not, try to match against the platform default(s) */
29842994 if (err == - ENOENT )
2985- err = try_enable_new_console (newcon , false);
2995+ err = try_enable_preferred_console (newcon , false);
29862996
29872997 /* printk() messages are not printed to the Braille console. */
29882998 if (err || newcon -> flags & CON_BRL )
@@ -2994,8 +3004,10 @@ void register_console(struct console *newcon)
29943004 * the real console are the same physical device, it's annoying to
29953005 * see the beginning boot messages twice
29963006 */
2997- if (bcon && ((newcon -> flags & (CON_CONSDEV | CON_BOOT )) == CON_CONSDEV ))
3007+ if (bootcon_enabled &&
3008+ ((newcon -> flags & (CON_CONSDEV | CON_BOOT )) == CON_CONSDEV )) {
29983009 newcon -> flags &= ~CON_PRINTBUFFER ;
3010+ }
29993011
30003012 /*
30013013 * Put this console in the list - keep the
@@ -3051,15 +3063,15 @@ void register_console(struct console *newcon)
30513063 pr_info ("%sconsole [%s%d] enabled\n" ,
30523064 (newcon -> flags & CON_BOOT ) ? "boot" : "" ,
30533065 newcon -> name , newcon -> index );
3054- if (bcon &&
3066+ if (bootcon_enabled &&
30553067 ((newcon -> flags & (CON_CONSDEV | CON_BOOT )) == CON_CONSDEV ) &&
30563068 !keep_bootcon ) {
30573069 /* We need to iterate through all boot consoles, to make
30583070 * sure we print everything out, before we unregister them.
30593071 */
3060- for_each_console (bcon )
3061- if (bcon -> flags & CON_BOOT )
3062- unregister_console (bcon );
3072+ for_each_console (con )
3073+ if (con -> flags & CON_BOOT )
3074+ unregister_console (con );
30633075 }
30643076}
30653077EXPORT_SYMBOL (register_console );
0 commit comments