[PATCHv3] kernel/panic: mark init_taint_buf as __initdata and panic instead of warning in alloc_taint_buf()

Rio posted 1 patch 1 month, 3 weeks ago
kernel/panic.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
[PATCHv3] kernel/panic: mark init_taint_buf as __initdata and panic instead of warning in alloc_taint_buf()
Posted by Rio 1 month, 3 weeks ago
On Sun, Feb 22, 2026 at 11:25:52AM -0800, Andrew Morton wrote:

> However there's a convention of assuming that __init-time allocations
> cannot fail.  Because if a kmalloc() were to fail at this time, the
> kernel is hopelessly messed up anyway.
> So we could simply panic() if that kmalloc failed, then make that
> 350-byte buffer __initdata.

Ah, got it. I made it __initdata, and replaced the warn with panic.

> That saves about $100 per machine with current DRAM prices ;)

Haha, saving every bit counts huh

Signed-off-by: Rio <rioo.tsukatsukii@gmail.com>
---
V2 -> V3: Mark initial buffer as __initdata and panic if allocation
fails
V1 -> V2: Allocate taint string buffer dynamically during init

v2: https://lore.kernel.org/all/20260222140804.22225-1-rioo.tsukatsukii@gmail.com/
v1: https://lore.kernel.org/all/20260220151500.13585-1-rioo.tsukatsukii@gmail.com/

 kernel/panic.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/kernel/panic.c b/kernel/panic.c
index 5d498ff8a18b..20feada5319d 100644
--- a/kernel/panic.c
+++ b/kernel/panic.c
@@ -865,8 +865,8 @@ static void print_tainted_seq(struct seq_buf *s, bool verbose)
  */
 #define INIT_TAINT_BUF_MAX 350
 
-static char init_taint_buf[INIT_TAINT_BUF_MAX];
-static char *taint_buf = init_taint_buf;
+static char init_taint_buf[INIT_TAINT_BUF_MAX] __initdata;
+static char *taint_buf __refdata = init_taint_buf;
 static size_t taint_buf_size = INIT_TAINT_BUF_MAX;
 
 static __init int alloc_taint_buf(void)
@@ -887,11 +887,7 @@ static __init int alloc_taint_buf(void)
 	buf = kmalloc(size, GFP_KERNEL);
 
 	if (!buf) {
-		/* Allocation may fail; this warning explains possibly
-		 * truncated taint strings
-		 */
-		pr_warn_once("taint string buffer allocation failed, using fallback buffer\n");
-		return 0;
+		panic("Failed to allocate taint string buffer");
 	}
 
 	taint_buf = buf;
-- 
2.52.0