@@ -280,6 +280,7 @@ 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 ;
283
284
int console_set_on_cmdline ;
284
285
EXPORT_SYMBOL (console_set_on_cmdline );
285
286
@@ -2626,6 +2627,60 @@ static int __init keep_bootcon_setup(char *str)
2626
2627
2627
2628
early_param ("keep_bootcon" , keep_bootcon_setup );
2628
2629
2630
+ /*
2631
+ * This is called by register_console() to try to match
2632
+ * the newly registered console with any of the ones selected
2633
+ * by either the command line or add_preferred_console() and
2634
+ * setup/enable it.
2635
+ *
2636
+ * Care need to be taken with consoles that are statically
2637
+ * enabled such as netconsole
2638
+ */
2639
+ static int try_enable_new_console (struct console * newcon )
2640
+ {
2641
+ struct console_cmdline * c ;
2642
+ int i ;
2643
+
2644
+ for (i = 0 , c = console_cmdline ;
2645
+ i < MAX_CMDLINECONSOLES && c -> name [0 ];
2646
+ i ++ , c ++ ) {
2647
+ if (!newcon -> match ||
2648
+ newcon -> match (newcon , c -> name , c -> index , c -> options ) != 0 ) {
2649
+ /* default matching */
2650
+ BUILD_BUG_ON (sizeof (c -> name ) != sizeof (newcon -> name ));
2651
+ if (strcmp (c -> name , newcon -> name ) != 0 )
2652
+ continue ;
2653
+ if (newcon -> index >= 0 &&
2654
+ newcon -> index != c -> index )
2655
+ continue ;
2656
+ if (newcon -> index < 0 )
2657
+ newcon -> index = c -> index ;
2658
+
2659
+ if (_braille_register_console (newcon , c ))
2660
+ return 0 ;
2661
+
2662
+ if (newcon -> setup &&
2663
+ newcon -> setup (newcon , c -> options ) != 0 )
2664
+ return - EIO ;
2665
+ }
2666
+ newcon -> flags |= CON_ENABLED ;
2667
+ if (i == preferred_console ) {
2668
+ newcon -> flags |= CON_CONSDEV ;
2669
+ has_preferred_console = true;
2670
+ }
2671
+ return 0 ;
2672
+ }
2673
+
2674
+ /*
2675
+ * Some consoles, such as pstore and netconsole, can be enabled even
2676
+ * without matching.
2677
+ */
2678
+ if (newcon -> flags & CON_ENABLED )
2679
+ return 0 ;
2680
+
2681
+ return - ENOENT ;
2682
+ }
2683
+
2629
2684
/*
2630
2685
* The console driver calls this routine during kernel initialization
2631
2686
* to register the console printing procedure with printk() and to
@@ -2647,11 +2702,9 @@ early_param("keep_bootcon", keep_bootcon_setup);
2647
2702
*/
2648
2703
void register_console (struct console * newcon )
2649
2704
{
2650
- int i ;
2651
2705
unsigned long flags ;
2652
2706
struct console * bcon = NULL ;
2653
- struct console_cmdline * c ;
2654
- static bool has_preferred ;
2707
+ int err ;
2655
2708
2656
2709
if (console_drivers )
2657
2710
for_each_console (bcon )
@@ -2678,63 +2731,35 @@ void register_console(struct console *newcon)
2678
2731
if (console_drivers && console_drivers -> flags & CON_BOOT )
2679
2732
bcon = console_drivers ;
2680
2733
2681
- if (!has_preferred || bcon || !console_drivers )
2682
- has_preferred = preferred_console >= 0 ;
2734
+ if (!has_preferred_console || bcon || !console_drivers )
2735
+ has_preferred_console = preferred_console >= 0 ;
2683
2736
2684
2737
/*
2685
2738
* See if we want to use this console driver. If we
2686
2739
* didn't select a console we take the first one
2687
2740
* that registers here.
2688
2741
*/
2689
- if (!has_preferred ) {
2742
+ if (!has_preferred_console ) {
2690
2743
if (newcon -> index < 0 )
2691
2744
newcon -> index = 0 ;
2692
2745
if (newcon -> setup == NULL ||
2693
2746
newcon -> setup (newcon , NULL ) == 0 ) {
2694
2747
newcon -> flags |= CON_ENABLED ;
2695
2748
if (newcon -> device ) {
2696
2749
newcon -> flags |= CON_CONSDEV ;
2697
- has_preferred = true;
2750
+ has_preferred_console = true;
2698
2751
}
2699
2752
}
2700
2753
}
2701
2754
2702
2755
/*
2703
- * See if this console matches one we selected on
2704
- * the command line.
2756
+ * See if this console matches one we selected on
2757
+ * the command line or if it was statically enabled
2705
2758
*/
2706
- for (i = 0 , c = console_cmdline ;
2707
- i < MAX_CMDLINECONSOLES && c -> name [0 ];
2708
- i ++ , c ++ ) {
2709
- if (!newcon -> match ||
2710
- newcon -> match (newcon , c -> name , c -> index , c -> options ) != 0 ) {
2711
- /* default matching */
2712
- BUILD_BUG_ON (sizeof (c -> name ) != sizeof (newcon -> name ));
2713
- if (strcmp (c -> name , newcon -> name ) != 0 )
2714
- continue ;
2715
- if (newcon -> index >= 0 &&
2716
- newcon -> index != c -> index )
2717
- continue ;
2718
- if (newcon -> index < 0 )
2719
- newcon -> index = c -> index ;
2720
-
2721
- if (_braille_register_console (newcon , c ))
2722
- return ;
2723
-
2724
- if (newcon -> setup &&
2725
- newcon -> setup (newcon , c -> options ) != 0 )
2726
- break ;
2727
- }
2728
-
2729
- newcon -> flags |= CON_ENABLED ;
2730
- if (i == preferred_console ) {
2731
- newcon -> flags |= CON_CONSDEV ;
2732
- has_preferred = true;
2733
- }
2734
- break ;
2735
- }
2759
+ err = try_enable_new_console (newcon );
2736
2760
2737
- if (!(newcon -> flags & CON_ENABLED ))
2761
+ /* printk() messages are not printed to the Braille console. */
2762
+ if (err || newcon -> flags & CON_BRL )
2738
2763
return ;
2739
2764
2740
2765
/*
0 commit comments