Skip to content

Commit cf5b020

Browse files
jognesspmladek
authored andcommitted
printk: introduce CONSOLE_LOG_MAX
Instead of using "LOG_LINE_MAX + PREFIX_MAX" for temporary buffer sizes, introduce CONSOLE_LOG_MAX. This represents the maximum size that is allowed to be printed to the console for a single record. Signed-off-by: John Ogness <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4260e0e commit cf5b020

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

kernel/printk/printk.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,12 @@ static u64 clear_seq;
410410
#else
411411
#define PREFIX_MAX 32
412412
#endif
413-
#define LOG_LINE_MAX (1024 - PREFIX_MAX)
413+
414+
/* the maximum size of a formatted record (i.e. with prefix added per line) */
415+
#define CONSOLE_LOG_MAX 1024
416+
417+
/* the maximum size allowed to be reserved for a record */
418+
#define LOG_LINE_MAX (CONSOLE_LOG_MAX - PREFIX_MAX)
414419

415420
#define LOG_LEVEL(v) ((v) & 0x07)
416421
#define LOG_FACILITY(v) ((v) >> 3 & 0xff)
@@ -1472,11 +1477,11 @@ static int syslog_print(char __user *buf, int size)
14721477
char *text;
14731478
int len = 0;
14741479

1475-
text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
1480+
text = kmalloc(CONSOLE_LOG_MAX, GFP_KERNEL);
14761481
if (!text)
14771482
return -ENOMEM;
14781483

1479-
prb_rec_init_rd(&r, &info, text, LOG_LINE_MAX + PREFIX_MAX);
1484+
prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX);
14801485

14811486
while (size > 0) {
14821487
size_t n;
@@ -1542,7 +1547,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
15421547
u64 seq;
15431548
bool time;
15441549

1545-
text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL);
1550+
text = kmalloc(CONSOLE_LOG_MAX, GFP_KERNEL);
15461551
if (!text)
15471552
return -ENOMEM;
15481553

@@ -1554,7 +1559,7 @@ static int syslog_print_all(char __user *buf, int size, bool clear)
15541559
*/
15551560
seq = find_first_fitting_seq(clear_seq, -1, size, true, time);
15561561

1557-
prb_rec_init_rd(&r, &info, text, LOG_LINE_MAX + PREFIX_MAX);
1562+
prb_rec_init_rd(&r, &info, text, CONSOLE_LOG_MAX);
15581563

15591564
len = 0;
15601565
prb_for_each_record(seq, prb, seq, &r) {
@@ -2187,8 +2192,7 @@ EXPORT_SYMBOL(printk);
21872192

21882193
#else /* CONFIG_PRINTK */
21892194

2190-
#define LOG_LINE_MAX 0
2191-
#define PREFIX_MAX 0
2195+
#define CONSOLE_LOG_MAX 0
21922196
#define printk_time false
21932197

21942198
#define prb_read_valid(rb, seq, r) false
@@ -2506,7 +2510,7 @@ static inline int can_use_console(void)
25062510
void console_unlock(void)
25072511
{
25082512
static char ext_text[CONSOLE_EXT_LOG_MAX];
2509-
static char text[LOG_LINE_MAX + PREFIX_MAX];
2513+
static char text[CONSOLE_LOG_MAX];
25102514
unsigned long flags;
25112515
bool do_cond_resched, retry;
25122516
struct printk_info info;

0 commit comments

Comments
 (0)