@@ -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
@@ -974,6 +975,16 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
974
975
user -> idx = log_next_idx ;
975
976
user -> seq = log_next_seq ;
976
977
break ;
978
+ case SEEK_CUR :
979
+ /*
980
+ * It isn't supported due to the record nature of this
981
+ * interface: _SET _DATA and _END point to very specific
982
+ * record positions, while _CUR would be more useful in case
983
+ * of a byte-based log. Because of that, return the default
984
+ * errno value for invalid seek operation.
985
+ */
986
+ ret = - ESPIPE ;
987
+ break ;
977
988
default :
978
989
ret = - EINVAL ;
979
990
}
@@ -2140,7 +2151,7 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
2140
2151
#endif
2141
2152
2142
2153
static int __add_preferred_console (char * name , int idx , char * options ,
2143
- char * brl_options )
2154
+ char * brl_options , bool user_specified )
2144
2155
{
2145
2156
struct console_cmdline * c ;
2146
2157
int i ;
@@ -2155,6 +2166,8 @@ static int __add_preferred_console(char *name, int idx, char *options,
2155
2166
if (strcmp (c -> name , name ) == 0 && c -> index == idx ) {
2156
2167
if (!brl_options )
2157
2168
preferred_console = i ;
2169
+ if (user_specified )
2170
+ c -> user_specified = true;
2158
2171
return 0 ;
2159
2172
}
2160
2173
}
@@ -2164,6 +2177,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
2164
2177
preferred_console = i ;
2165
2178
strlcpy (c -> name , name , sizeof (c -> name ));
2166
2179
c -> options = options ;
2180
+ c -> user_specified = user_specified ;
2167
2181
braille_set_options (c , brl_options );
2168
2182
2169
2183
c -> index = idx ;
@@ -2190,6 +2204,9 @@ static int __init console_setup(char *str)
2190
2204
char * s , * options , * brl_options = NULL ;
2191
2205
int idx ;
2192
2206
2207
+ if (str [0 ] == 0 )
2208
+ return 1 ;
2209
+
2193
2210
if (_braille_console_setup (& str , & brl_options ))
2194
2211
return 1 ;
2195
2212
@@ -2218,7 +2235,7 @@ static int __init console_setup(char *str)
2218
2235
idx = simple_strtoul (s , NULL , 10 );
2219
2236
* s = 0 ;
2220
2237
2221
- __add_preferred_console (buf , idx , options , brl_options );
2238
+ __add_preferred_console (buf , idx , options , brl_options , true );
2222
2239
console_set_on_cmdline = 1 ;
2223
2240
return 1 ;
2224
2241
}
@@ -2239,7 +2256,7 @@ __setup("console=", console_setup);
2239
2256
*/
2240
2257
int add_preferred_console (char * name , int idx , char * options )
2241
2258
{
2242
- return __add_preferred_console (name , idx , options , NULL );
2259
+ return __add_preferred_console (name , idx , options , NULL , false );
2243
2260
}
2244
2261
2245
2262
bool console_suspend_enabled = true;
@@ -2438,9 +2455,9 @@ void console_unlock(void)
2438
2455
printk_safe_enter_irqsave (flags );
2439
2456
raw_spin_lock (& logbuf_lock );
2440
2457
if (console_seq < log_first_seq ) {
2441
- len = sprintf (text ,
2442
- "** %llu printk messages dropped **\n" ,
2443
- log_first_seq - console_seq );
2458
+ len = snprintf (text , sizeof ( text ) ,
2459
+ "** %llu printk messages dropped **\n" ,
2460
+ log_first_seq - console_seq );
2444
2461
2445
2462
/* messages are gone, move to first one */
2446
2463
console_seq = log_first_seq ;
@@ -2651,6 +2668,63 @@ static int __init keep_bootcon_setup(char *str)
2651
2668
2652
2669
early_param ("keep_bootcon" , keep_bootcon_setup );
2653
2670
2671
+ /*
2672
+ * This is called by register_console() to try to match
2673
+ * the newly registered console with any of the ones selected
2674
+ * by either the command line or add_preferred_console() and
2675
+ * setup/enable it.
2676
+ *
2677
+ * Care need to be taken with consoles that are statically
2678
+ * enabled such as netconsole
2679
+ */
2680
+ static int try_enable_new_console (struct console * newcon , bool user_specified )
2681
+ {
2682
+ struct console_cmdline * c ;
2683
+ int i ;
2684
+
2685
+ for (i = 0 , c = console_cmdline ;
2686
+ i < MAX_CMDLINECONSOLES && c -> name [0 ];
2687
+ i ++ , c ++ ) {
2688
+ if (c -> user_specified != user_specified )
2689
+ continue ;
2690
+ if (!newcon -> match ||
2691
+ newcon -> match (newcon , c -> name , c -> index , c -> options ) != 0 ) {
2692
+ /* default matching */
2693
+ BUILD_BUG_ON (sizeof (c -> name ) != sizeof (newcon -> name ));
2694
+ if (strcmp (c -> name , newcon -> name ) != 0 )
2695
+ continue ;
2696
+ if (newcon -> index >= 0 &&
2697
+ newcon -> index != c -> index )
2698
+ continue ;
2699
+ if (newcon -> index < 0 )
2700
+ newcon -> index = c -> index ;
2701
+
2702
+ if (_braille_register_console (newcon , c ))
2703
+ return 0 ;
2704
+
2705
+ if (newcon -> setup &&
2706
+ newcon -> setup (newcon , c -> options ) != 0 )
2707
+ return - EIO ;
2708
+ }
2709
+ newcon -> flags |= CON_ENABLED ;
2710
+ if (i == preferred_console ) {
2711
+ newcon -> flags |= CON_CONSDEV ;
2712
+ has_preferred_console = true;
2713
+ }
2714
+ return 0 ;
2715
+ }
2716
+
2717
+ /*
2718
+ * Some consoles, such as pstore and netconsole, can be enabled even
2719
+ * without matching. Accept the pre-enabled consoles only when match()
2720
+ * and setup() had a change to be called.
2721
+ */
2722
+ if (newcon -> flags & CON_ENABLED && c -> user_specified == user_specified )
2723
+ return 0 ;
2724
+
2725
+ return - ENOENT ;
2726
+ }
2727
+
2654
2728
/*
2655
2729
* The console driver calls this routine during kernel initialization
2656
2730
* to register the console printing procedure with printk() and to
@@ -2672,11 +2746,9 @@ early_param("keep_bootcon", keep_bootcon_setup);
2672
2746
*/
2673
2747
void register_console (struct console * newcon )
2674
2748
{
2675
- int i ;
2676
2749
unsigned long flags ;
2677
2750
struct console * bcon = NULL ;
2678
- struct console_cmdline * c ;
2679
- static bool has_preferred ;
2751
+ int err ;
2680
2752
2681
2753
for_each_console (bcon ) {
2682
2754
if (WARN (bcon == newcon , "console '%s%d' already registered\n" ,
@@ -2701,63 +2773,36 @@ void register_console(struct console *newcon)
2701
2773
if (console_drivers && console_drivers -> flags & CON_BOOT )
2702
2774
bcon = console_drivers ;
2703
2775
2704
- if (!has_preferred || bcon || !console_drivers )
2705
- has_preferred = preferred_console >= 0 ;
2776
+ if (!has_preferred_console || bcon || !console_drivers )
2777
+ has_preferred_console = preferred_console >= 0 ;
2706
2778
2707
2779
/*
2708
2780
* See if we want to use this console driver. If we
2709
2781
* didn't select a console we take the first one
2710
2782
* that registers here.
2711
2783
*/
2712
- if (!has_preferred ) {
2784
+ if (!has_preferred_console ) {
2713
2785
if (newcon -> index < 0 )
2714
2786
newcon -> index = 0 ;
2715
2787
if (newcon -> setup == NULL ||
2716
2788
newcon -> setup (newcon , NULL ) == 0 ) {
2717
2789
newcon -> flags |= CON_ENABLED ;
2718
2790
if (newcon -> device ) {
2719
2791
newcon -> flags |= CON_CONSDEV ;
2720
- has_preferred = true;
2792
+ has_preferred_console = true;
2721
2793
}
2722
2794
}
2723
2795
}
2724
2796
2725
- /*
2726
- * See if this console matches one we selected on
2727
- * the command line.
2728
- */
2729
- for (i = 0 , c = console_cmdline ;
2730
- i < MAX_CMDLINECONSOLES && c -> name [0 ];
2731
- i ++ , c ++ ) {
2732
- if (!newcon -> match ||
2733
- newcon -> match (newcon , c -> name , c -> index , c -> options ) != 0 ) {
2734
- /* default matching */
2735
- BUILD_BUG_ON (sizeof (c -> name ) != sizeof (newcon -> name ));
2736
- if (strcmp (c -> name , newcon -> name ) != 0 )
2737
- continue ;
2738
- if (newcon -> index >= 0 &&
2739
- newcon -> index != c -> index )
2740
- continue ;
2741
- if (newcon -> index < 0 )
2742
- newcon -> index = c -> index ;
2797
+ /* See if this console matches one we selected on the command line */
2798
+ err = try_enable_new_console (newcon , true);
2743
2799
2744
- if (_braille_register_console (newcon , c ))
2745
- return ;
2746
-
2747
- if (newcon -> setup &&
2748
- newcon -> setup (newcon , c -> options ) != 0 )
2749
- break ;
2750
- }
2751
-
2752
- newcon -> flags |= CON_ENABLED ;
2753
- if (i == preferred_console ) {
2754
- newcon -> flags |= CON_CONSDEV ;
2755
- has_preferred = true;
2756
- }
2757
- break ;
2758
- }
2800
+ /* If not, try to match against the platform default(s) */
2801
+ if (err == - ENOENT )
2802
+ err = try_enable_new_console (newcon , false);
2759
2803
2760
- if (!(newcon -> flags & CON_ENABLED ))
2804
+ /* printk() messages are not printed to the Braille console. */
2805
+ if (err || newcon -> flags & CON_BRL )
2761
2806
return ;
2762
2807
2763
2808
/*
@@ -2779,6 +2824,8 @@ void register_console(struct console *newcon)
2779
2824
console_drivers = newcon ;
2780
2825
if (newcon -> next )
2781
2826
newcon -> next -> flags &= ~CON_CONSDEV ;
2827
+ /* Ensure this flag is always set for the head of the list */
2828
+ newcon -> flags |= CON_CONSDEV ;
2782
2829
} else {
2783
2830
newcon -> next = console_drivers -> next ;
2784
2831
console_drivers -> next = newcon ;
@@ -3384,7 +3431,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
3384
3431
EXPORT_SYMBOL_GPL (kmsg_dump_get_buffer );
3385
3432
3386
3433
/**
3387
- * kmsg_dump_rewind_nolock - reset the interator (unlocked version)
3434
+ * kmsg_dump_rewind_nolock - reset the iterator (unlocked version)
3388
3435
* @dumper: registered kmsg dumper
3389
3436
*
3390
3437
* Reset the dumper's iterator so that kmsg_dump_get_line() and
@@ -3402,7 +3449,7 @@ void kmsg_dump_rewind_nolock(struct kmsg_dumper *dumper)
3402
3449
}
3403
3450
3404
3451
/**
3405
- * kmsg_dump_rewind - reset the interator
3452
+ * kmsg_dump_rewind - reset the iterator
3406
3453
* @dumper: registered kmsg dumper
3407
3454
*
3408
3455
* Reset the dumper's iterator so that kmsg_dump_get_line() and
0 commit comments