Skip to content

Commit ca1f5df

Browse files
committed
Merge tag 'printk-for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux
Pull printk updates from Petr Mladek: - Benjamin Herrenschmidt solved a problem with non-matched console aliases by first checking consoles defined on the command line. It is a more conservative approach than the previous attempts. - Benjamin also made sure that the console accessible via /dev/console always has CON_CONSDEV flag. - Andy Shevchenko added the %ptT modifier for printing struct time64_t. It extends the existing %ptR handling for struct rtc_time. - Bruno Meneguele fixed /dev/kmsg error value returned by unsupported SEEK_CUR. - Tetsuo Handa removed unused pr_cont_once(). ... and a few small fixes. * tag 'printk-for-5.8' of git://git.kernel.org/pub/scm/linux/kernel/git/printk/linux: printk: Remove pr_cont_once() printk: handle blank console arguments passed in. kernel/printk: add kmsg SEEK_CUR handling printk: Fix a typo in comment "interator"->"iterator" usb: pulse8-cec: Switch to use %ptT ARM: bcm2835: Switch to use %ptT lib/vsprintf: Print time64_t in human readable format lib/vsprintf: update comment about simple_strto<foo>() functions printk: Correctly set CON_CONSDEV even when preferred console was not registered printk: Fix preferred console selection with multiple matches printk: Move console matching logic into a separate function printk: Convert a use of sprintf to snprintf in console_unlock
2 parents 4d67829 + 8b390ab commit ca1f5df

File tree

10 files changed

+163
-85
lines changed

10 files changed

+163
-85
lines changed

Documentation/ABI/testing/dev-kmsg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ Description: The /dev/kmsg character device node provides userspace access
5656
seek after the last record available at the time
5757
the last SYSLOG_ACTION_CLEAR was issued.
5858

59+
Due to the record nature of this interface with a "read all"
60+
behavior and the specific positions each seek operation sets,
61+
SEEK_CUR is not supported, returning -ESPIPE (invalid seek) to
62+
errno whenever requested.
63+
5964
The output format consists of a prefix carrying the syslog
6065
prefix including priority and facility, the 64 bit message
6166
sequence number and the monotonic timestamp in microseconds,

Documentation/core-api/printk-formats.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -482,21 +482,23 @@ Examples (OF)::
482482
%pfwf /ocp@68000000/i2c@48072000/camera@10/port/endpoint - Full name
483483
%pfwP endpoint - Node name
484484

485-
Time and date (struct rtc_time)
486-
-------------------------------
485+
Time and date
486+
-------------
487487

488488
::
489489

490-
%ptR YYYY-mm-ddTHH:MM:SS
491-
%ptRd YYYY-mm-dd
492-
%ptRt HH:MM:SS
493-
%ptR[dt][r]
490+
%pt[RT] YYYY-mm-ddTHH:MM:SS
491+
%pt[RT]d YYYY-mm-dd
492+
%pt[RT]t HH:MM:SS
493+
%pt[RT][dt][r]
494494

495-
For printing date and time as represented by struct rtc_time structure in
496-
human readable format.
495+
For printing date and time as represented by
496+
R struct rtc_time structure
497+
T time64_t type
498+
in human readable format.
497499

498-
By default year will be incremented by 1900 and month by 1. Use %ptRr (raw)
499-
to suppress this behaviour.
500+
By default year will be incremented by 1900 and month by 1.
501+
Use %pt[RT]r (raw) to suppress this behaviour.
500502

501503
Passed by reference.
502504

drivers/firmware/raspberrypi.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,10 @@ rpi_firmware_print_firmware_revision(struct rpi_firmware *fw)
182182
RPI_FIRMWARE_GET_FIRMWARE_REVISION,
183183
&packet, sizeof(packet));
184184

185-
if (ret == 0) {
186-
struct tm tm;
187-
188-
time64_to_tm(packet, 0, &tm);
185+
if (ret)
186+
return;
189187

190-
dev_info(fw->cl.dev,
191-
"Attached to firmware from %04ld-%02d-%02d %02d:%02d\n",
192-
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
193-
tm.tm_hour, tm.tm_min);
194-
}
188+
dev_info(fw->cl.dev, "Attached to firmware from %ptT\n", &packet);
195189
}
196190

197191
static void

drivers/media/usb/pulse8-cec/pulse8-cec.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ static int pulse8_setup(struct pulse8 *pulse8, struct serio *serio,
661661
u8 *data = pulse8->data + 1;
662662
u8 cmd[2];
663663
int err;
664-
struct tm tm;
665664
time64_t date;
666665

667666
pulse8->vers = 0;
@@ -682,10 +681,7 @@ static int pulse8_setup(struct pulse8 *pulse8, struct serio *serio,
682681
if (err)
683682
return err;
684683
date = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
685-
time64_to_tm(date, 0, &tm);
686-
dev_info(pulse8->dev, "Firmware build date %04ld.%02d.%02d %02d:%02d:%02d\n",
687-
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
688-
tm.tm_hour, tm.tm_min, tm.tm_sec);
684+
dev_info(pulse8->dev, "Firmware build date %ptT\n", &date);
689685

690686
dev_dbg(pulse8->dev, "Persistent config:\n");
691687
cmd[0] = MSGCODE_GET_AUTO_ENABLED;

include/linux/console.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static inline int con_debug_leave(void)
134134
*/
135135

136136
#define CON_PRINTBUFFER (1)
137-
#define CON_CONSDEV (2) /* Last on the command line */
137+
#define CON_CONSDEV (2) /* Preferred console, /dev/console */
138138
#define CON_ENABLED (4)
139139
#define CON_BOOT (8)
140140
#define CON_ANYTIME (16) /* Safe to call when cpu is offline */

include/linux/printk.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,7 @@ extern int kptr_restrict;
384384
printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
385385
#define pr_info_once(fmt, ...) \
386386
printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
387-
#define pr_cont_once(fmt, ...) \
388-
printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
387+
/* no pr_cont_once, don't do that... */
389388

390389
#if defined(DEBUG)
391390
#define pr_devel_once(fmt, ...) \

kernel/printk/console_cmdline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct console_cmdline
66
{
77
char name[16]; /* Name of the driver */
88
int index; /* Minor dev. to use */
9+
bool user_specified; /* Specified by command line vs. platform */
910
char *options; /* Options for the driver */
1011
#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
1112
char *brl_options; /* Options for braille driver */

kernel/printk/printk.c

Lines changed: 96 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ static struct console *exclusive_console;
280280
static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
281281

282282
static int preferred_console = -1;
283+
static bool has_preferred_console;
283284
int console_set_on_cmdline;
284285
EXPORT_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

21422153
static 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
*/
22402257
int 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

22452262
bool 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

26522669
early_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
*/
26732747
void 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,
33843431
EXPORT_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

Comments
 (0)