@@ -280,7 +280,6 @@ static struct console *exclusive_console;
280
280
static struct console_cmdline console_cmdline [MAX_CMDLINECONSOLES ];
281
281
282
282
static int preferred_console = -1 ;
283
- static bool has_preferred_console ;
284
283
int console_set_on_cmdline ;
285
284
EXPORT_SYMBOL (console_set_on_cmdline );
286
285
@@ -2861,7 +2860,8 @@ early_param("keep_bootcon", keep_bootcon_setup);
2861
2860
* Care need to be taken with consoles that are statically
2862
2861
* enabled such as netconsole
2863
2862
*/
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 )
2865
2865
{
2866
2866
struct console_cmdline * c ;
2867
2867
int i , err ;
@@ -2891,10 +2891,8 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
2891
2891
return err ;
2892
2892
}
2893
2893
newcon -> flags |= CON_ENABLED ;
2894
- if (i == preferred_console ) {
2894
+ if (i == preferred_console )
2895
2895
newcon -> flags |= CON_CONSDEV ;
2896
- has_preferred_console = true;
2897
- }
2898
2896
return 0 ;
2899
2897
}
2900
2898
@@ -2909,6 +2907,21 @@ static int try_enable_new_console(struct console *newcon, bool user_specified)
2909
2907
return - ENOENT ;
2910
2908
}
2911
2909
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
+
2912
2925
/*
2913
2926
* The console driver calls this routine during kernel initialization
2914
2927
* 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)
2930
2943
*/
2931
2944
void register_console (struct console * newcon )
2932
2945
{
2933
- struct console * bcon = NULL ;
2946
+ struct console * con ;
2947
+ bool bootcon_enabled = false;
2948
+ bool realcon_enabled = false;
2934
2949
int err ;
2935
2950
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 ))
2939
2954
return ;
2940
2955
}
2941
2956
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;
2954
2962
}
2955
2963
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
+ }
2961
2970
2962
2971
/*
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.
2966
2982
*/
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 );
2977
2987
}
2978
2988
}
2979
2989
2980
2990
/* 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);
2982
2992
2983
2993
/* If not, try to match against the platform default(s) */
2984
2994
if (err == - ENOENT )
2985
- err = try_enable_new_console (newcon , false);
2995
+ err = try_enable_preferred_console (newcon , false);
2986
2996
2987
2997
/* printk() messages are not printed to the Braille console. */
2988
2998
if (err || newcon -> flags & CON_BRL )
@@ -2994,8 +3004,10 @@ void register_console(struct console *newcon)
2994
3004
* the real console are the same physical device, it's annoying to
2995
3005
* see the beginning boot messages twice
2996
3006
*/
2997
- if (bcon && ((newcon -> flags & (CON_CONSDEV | CON_BOOT )) == CON_CONSDEV ))
3007
+ if (bootcon_enabled &&
3008
+ ((newcon -> flags & (CON_CONSDEV | CON_BOOT )) == CON_CONSDEV )) {
2998
3009
newcon -> flags &= ~CON_PRINTBUFFER ;
3010
+ }
2999
3011
3000
3012
/*
3001
3013
* Put this console in the list - keep the
@@ -3051,15 +3063,15 @@ void register_console(struct console *newcon)
3051
3063
pr_info ("%sconsole [%s%d] enabled\n" ,
3052
3064
(newcon -> flags & CON_BOOT ) ? "boot" : "" ,
3053
3065
newcon -> name , newcon -> index );
3054
- if (bcon &&
3066
+ if (bootcon_enabled &&
3055
3067
((newcon -> flags & (CON_CONSDEV | CON_BOOT )) == CON_CONSDEV ) &&
3056
3068
!keep_bootcon ) {
3057
3069
/* We need to iterate through all boot consoles, to make
3058
3070
* sure we print everything out, before we unregister them.
3059
3071
*/
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 );
3063
3075
}
3064
3076
}
3065
3077
EXPORT_SYMBOL (register_console );
0 commit comments