@@ -280,6 +280,7 @@ 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 ;
283284int console_set_on_cmdline ;
284285EXPORT_SYMBOL (console_set_on_cmdline );
285286
@@ -974,6 +975,16 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
974975 user -> idx = log_next_idx ;
975976 user -> seq = log_next_seq ;
976977 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 ;
977988 default :
978989 ret = - EINVAL ;
979990 }
@@ -2140,7 +2151,7 @@ asmlinkage __visible void early_printk(const char *fmt, ...)
21402151#endif
21412152
21422153static int __add_preferred_console (char * name , int idx , char * options ,
2143- char * brl_options )
2154+ char * brl_options , bool user_specified )
21442155{
21452156 struct console_cmdline * c ;
21462157 int i ;
@@ -2155,6 +2166,8 @@ static int __add_preferred_console(char *name, int idx, char *options,
21552166 if (strcmp (c -> name , name ) == 0 && c -> index == idx ) {
21562167 if (!brl_options )
21572168 preferred_console = i ;
2169+ if (user_specified )
2170+ c -> user_specified = true;
21582171 return 0 ;
21592172 }
21602173 }
@@ -2164,6 +2177,7 @@ static int __add_preferred_console(char *name, int idx, char *options,
21642177 preferred_console = i ;
21652178 strlcpy (c -> name , name , sizeof (c -> name ));
21662179 c -> options = options ;
2180+ c -> user_specified = user_specified ;
21672181 braille_set_options (c , brl_options );
21682182
21692183 c -> index = idx ;
@@ -2190,6 +2204,9 @@ static int __init console_setup(char *str)
21902204 char * s , * options , * brl_options = NULL ;
21912205 int idx ;
21922206
2207+ if (str [0 ] == 0 )
2208+ return 1 ;
2209+
21932210 if (_braille_console_setup (& str , & brl_options ))
21942211 return 1 ;
21952212
@@ -2218,7 +2235,7 @@ static int __init console_setup(char *str)
22182235 idx = simple_strtoul (s , NULL , 10 );
22192236 * s = 0 ;
22202237
2221- __add_preferred_console (buf , idx , options , brl_options );
2238+ __add_preferred_console (buf , idx , options , brl_options , true );
22222239 console_set_on_cmdline = 1 ;
22232240 return 1 ;
22242241}
@@ -2239,7 +2256,7 @@ __setup("console=", console_setup);
22392256 */
22402257int add_preferred_console (char * name , int idx , char * options )
22412258{
2242- return __add_preferred_console (name , idx , options , NULL );
2259+ return __add_preferred_console (name , idx , options , NULL , false );
22432260}
22442261
22452262bool console_suspend_enabled = true;
@@ -2438,9 +2455,9 @@ void console_unlock(void)
24382455 printk_safe_enter_irqsave (flags );
24392456 raw_spin_lock (& logbuf_lock );
24402457 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 );
24442461
24452462 /* messages are gone, move to first one */
24462463 console_seq = log_first_seq ;
@@ -2651,6 +2668,63 @@ static int __init keep_bootcon_setup(char *str)
26512668
26522669early_param ("keep_bootcon" , keep_bootcon_setup );
26532670
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+
26542728/*
26552729 * The console driver calls this routine during kernel initialization
26562730 * to register the console printing procedure with printk() and to
@@ -2672,11 +2746,9 @@ early_param("keep_bootcon", keep_bootcon_setup);
26722746 */
26732747void register_console (struct console * newcon )
26742748{
2675- int i ;
26762749 unsigned long flags ;
26772750 struct console * bcon = NULL ;
2678- struct console_cmdline * c ;
2679- static bool has_preferred ;
2751+ int err ;
26802752
26812753 for_each_console (bcon ) {
26822754 if (WARN (bcon == newcon , "console '%s%d' already registered\n" ,
@@ -2701,63 +2773,36 @@ void register_console(struct console *newcon)
27012773 if (console_drivers && console_drivers -> flags & CON_BOOT )
27022774 bcon = console_drivers ;
27032775
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 ;
27062778
27072779 /*
27082780 * See if we want to use this console driver. If we
27092781 * didn't select a console we take the first one
27102782 * that registers here.
27112783 */
2712- if (!has_preferred ) {
2784+ if (!has_preferred_console ) {
27132785 if (newcon -> index < 0 )
27142786 newcon -> index = 0 ;
27152787 if (newcon -> setup == NULL ||
27162788 newcon -> setup (newcon , NULL ) == 0 ) {
27172789 newcon -> flags |= CON_ENABLED ;
27182790 if (newcon -> device ) {
27192791 newcon -> flags |= CON_CONSDEV ;
2720- has_preferred = true;
2792+ has_preferred_console = true;
27212793 }
27222794 }
27232795 }
27242796
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);
27432799
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);
27592803
2760- if (!(newcon -> flags & CON_ENABLED ))
2804+ /* printk() messages are not printed to the Braille console. */
2805+ if (err || newcon -> flags & CON_BRL )
27612806 return ;
27622807
27632808 /*
@@ -2779,6 +2824,8 @@ void register_console(struct console *newcon)
27792824 console_drivers = newcon ;
27802825 if (newcon -> next )
27812826 newcon -> next -> flags &= ~CON_CONSDEV ;
2827+ /* Ensure this flag is always set for the head of the list */
2828+ newcon -> flags |= CON_CONSDEV ;
27822829 } else {
27832830 newcon -> next = console_drivers -> next ;
27842831 console_drivers -> next = newcon ;
@@ -3384,7 +3431,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
33843431EXPORT_SYMBOL_GPL (kmsg_dump_get_buffer );
33853432
33863433/**
3387- * kmsg_dump_rewind_nolock - reset the interator (unlocked version)
3434+ * kmsg_dump_rewind_nolock - reset the iterator (unlocked version)
33883435 * @dumper: registered kmsg dumper
33893436 *
33903437 * 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)
34023449}
34033450
34043451/**
3405- * kmsg_dump_rewind - reset the interator
3452+ * kmsg_dump_rewind - reset the iterator
34063453 * @dumper: registered kmsg dumper
34073454 *
34083455 * Reset the dumper's iterator so that kmsg_dump_get_line() and
0 commit comments