Skip to contentSkip to conversation

printk: fix kmsg_dump_get_buffer length calulations

PATCH In review John Ogness 3 participants 4 messages Jan 13, 2021 – Jan 15, 2021 Printk

lore
Share & tools
lore

John Ogness

author maintainer
#0 lore raw

PATCH 1/1 printk: fix kmsg_dump_get_buffer length calulations

kmsg_dump_get_buffer() uses @syslog to determine if the syslog prefix should be written to the buffer. However, when calculating the maximum number of records that can fit into the buffer, it always counts the bytes from the syslog prefix.

Use @syslog when calculating the maximum number of records that can fit into the buffer.

Fixes e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")
---
 kernel/printk/printk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/printk/printk.c +2 -2
index ffdd0dc7ec6d..848b56efc9d7 100644
@@ -3427,7 +3427,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
 	while (prb_read_valid_info(prb, seq, &info, &line_count)) {
 		if (r.info->seq >= dumper->next_seq)
 			break;
-		l += get_record_print_text_size(&info, line_count, true, time);
+		l += get_record_print_text_size(&info, line_count, syslog, time);
 		seq = r.info->seq + 1;
 	}
 
@@ -3437,7 +3437,7 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
 						&info, &line_count)) {
 		if (r.info->seq >= dumper->next_seq)
 			break;
-		l -= get_record_print_text_size(&info, line_count, true, time);
+		l -= get_record_print_text_size(&info, line_count, syslog, time);
 		seq = r.info->seq + 1;
 	}
 
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · John Ogness

kmsg_dump_get_buffer() uses @syslog to determine if the syslog prefix should be written to the buffer. However, when calculating the maximum number of records that can fit into the buffer, it always counts the bytes from the syslog prefix.

Use @syslog when calculating the maximum number of records that can fit into the buffer.

Another great catch!

Quoted 2 lines
Fixes e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")

Best Regards,
Petr

Acked-by on v1 1/1
#2 lore raw
In reply to John Ogness
Quoted 11 lines · John Ogness

kmsg_dump_get_buffer() uses @syslog to determine if the syslog prefix should be written to the buffer. However, when calculating the maximum number of records that can fit into the buffer, it always counts the bytes from the syslog prefix.

Use @syslog when calculating the maximum number of records that can fit into the buffer.

Fixes e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")
	-ss
maintainer
#3 lore raw
In reply to John Ogness
Quoted 10 lines · John Ogness

kmsg_dump_get_buffer() uses @syslog to determine if the syslog prefix should be written to the buffer. However, when calculating the maximum number of records that can fit into the buffer, it always counts the bytes from the syslog prefix.

Use @syslog when calculating the maximum number of records that can fit into the buffer.

Fixes e2ae715d66bf ("kmsg - kmsg_dump() use iterator to receive log buffer content")

The patch is committed in printk/linux.git, branch printk-rework.

I plan to send it for-5.11 the following week after it spends few days in linux-next.

Best Regards,
Petr