* [PATCH] init: Remove strlcat() and sprintf() from do_one_initcall()
@ 2026-11-14 11:05 Thorsten Blum
0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-11-14 11:05 UTC (permalink / raw)
To: Andrew Morton, Masami Hiramatsu (Google), Christian Brauner,
Sang-Heon Jeon, Breno Leitao, Mike Rapoport (Microsoft),
Ryan Roberts
Cc: Thorsten Blum, Wilson Felipe Pereira, linux-kernel
In preparation for removing strlcat() from the kernel [1], format the
warning directly in WARN(). This also removes the temporary 64-byte
buffer and the sprintf() call while preserving the warning text.
Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
init/main.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/init/main.c b/init/main.c
index 93a2b12976f0..430b403e0880 100644
--- a/init/main.c
+++ b/init/main.c
@@ -1397,7 +1397,8 @@ static inline void do_trace_initcall_level(const char *level)
int __init_or_module do_one_initcall(initcall_t fn)
{
int count = preempt_count();
- char msgbuf[64];
+ bool preempt_imbalanced;
+ bool irqs_left_disabled;
int ret;
if (initcall_blacklisted(fn))
@@ -1407,17 +1408,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
ret = fn();
do_trace_initcall_finish(fn, ret);
- msgbuf[0] = 0;
-
- if (preempt_count() != count) {
- sprintf(msgbuf, "preemption imbalance ");
+ preempt_imbalanced = preempt_count() != count;
+ if (preempt_imbalanced)
preempt_count_set(count);
- }
- if (irqs_disabled()) {
- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
+
+ irqs_left_disabled = irqs_disabled();
+ if (irqs_left_disabled)
local_irq_enable();
- }
- WARN(msgbuf[0], "initcall %pS returned with %s\n", fn, msgbuf);
+
+ WARN(preempt_imbalanced || irqs_left_disabled, "initcall %pS returned with %s%s\n", fn,
+ preempt_imbalanced ? "preemption imbalance " : "",
+ irqs_left_disabled ? "disabled interrupts " : "");
add_latent_entropy();
return ret;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-14 11:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 11:05 [PATCH] init: Remove strlcat() and sprintf() from do_one_initcall() Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox