Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kernel/panic: convert print_tainted() to use struct seq_buf internally

Convert print_tainted() to use struct seq_buf internally in order to be
more aware of the buffer constraints as well as make it easier to extend
in follow-up work.

Link: https://lkml.kernel.org/r/cb6006fa7c0f82a6b6885e8eea2920fcdc4fc9d0.1717146197.git.jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Jani Nikula and committed by
Andrew Morton
aff1db0e f4b62423

+24 -14
+24 -14
kernel/panic.c
··· 35 35 #include <linux/debugfs.h> 36 36 #include <linux/sysfs.h> 37 37 #include <linux/context_tracking.h> 38 + #include <linux/seq_buf.h> 38 39 #include <trace/events/error_report.h> 39 40 #include <asm/sections.h> 40 41 ··· 497 496 [ TAINT_TEST ] = { 'N', ' ', true }, 498 497 }; 499 498 499 + static void print_tainted_seq(struct seq_buf *s) 500 + { 501 + int i; 502 + 503 + if (!tainted_mask) { 504 + seq_buf_puts(s, "Not tainted"); 505 + return; 506 + } 507 + 508 + seq_buf_printf(s, "Tainted: "); 509 + for (i = 0; i < TAINT_FLAGS_COUNT; i++) { 510 + const struct taint_flag *t = &taint_flags[i]; 511 + bool is_set = test_bit(i, &tainted_mask); 512 + char c = is_set ? t->c_true : t->c_false; 513 + 514 + seq_buf_putc(s, c); 515 + } 516 + } 517 + 500 518 /** 501 519 * print_tainted - return a string to represent the kernel taint state. 502 520 * ··· 527 507 const char *print_tainted(void) 528 508 { 529 509 static char buf[TAINT_FLAGS_COUNT + sizeof("Tainted: ")]; 530 - char *s; 531 - int i; 510 + struct seq_buf s; 532 511 533 512 BUILD_BUG_ON(ARRAY_SIZE(taint_flags) != TAINT_FLAGS_COUNT); 534 513 535 - if (!tainted_mask) { 536 - snprintf(buf, sizeof(buf), "Not tainted"); 537 - return buf; 538 - } 514 + seq_buf_init(&s, buf, sizeof(buf)); 539 515 540 - s = buf + sprintf(buf, "Tainted: "); 541 - for (i = 0; i < TAINT_FLAGS_COUNT; i++) { 542 - const struct taint_flag *t = &taint_flags[i]; 543 - *s++ = test_bit(i, &tainted_mask) ? 544 - t->c_true : t->c_false; 545 - } 546 - *s = 0; 516 + print_tainted_seq(&s); 547 517 548 - return buf; 518 + return seq_buf_str(&s); 549 519 } 550 520 551 521 int test_taint(unsigned flag)