* [PATCH] init: Remove strlcat() and sprintf() from do_one_initcall()
@ 2026-11-14 11:05 Thorsten Blum
2026-11-15 14:53 ` David Laight
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread
* Re: [PATCH] init: Remove strlcat() and sprintf() from do_one_initcall()
2026-11-14 11:05 [PATCH] init: Remove strlcat() and sprintf() from do_one_initcall() Thorsten Blum
@ 2026-11-15 14:53 ` David Laight
0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2026-11-15 14:53 UTC (permalink / raw)
To: Thorsten Blum
Cc: Andrew Morton, Masami Hiramatsu (Google), Christian Brauner,
Sang-Heon Jeon, Breno Leitao, Mike Rapoport (Microsoft),
Ryan Roberts, Wilson Felipe Pereira, linux-kernel
On Sat, 14 Nov 2026 12:05:31 +0100
Thorsten Blum <blum@kernel.org> wrote:
> 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>
This one actually makes sense!
I might have used 'const char *' variables and removed the ' ' before
the '\n'. But:
Reviewed-by: David Laight <david.laight.linux@gmail.com>
> ---
> 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 [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-15 14:53 UTC | newest]
Thread overview: 2+ messages (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
2026-11-15 14:53 ` David Laight
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.