init: Remove strlcat() and sprintf() from do_one_initcall()
PATCH 1/1 init: Remove strlcat() and sprintf() from do_one_initcall()
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.
Signed-off-by Thorsten Blum <[email protected]>
--- init/main.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
init/main.c +11 -10
@@ -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;
Quoted 6 lines · On Sat, 14 Nov 2026 12:05:31 +0100 Thorsten Blum <[email protected]> wrote:
In preparation for removing
strlcat()from the kernel [1], format the warning directly inWARN(). This also removes the temporary 64-byte buffer and thesprintf()call while preserving the warning text.Signed-off-by Thorsten Blum <[email protected]>
This one actually makes sense!
I might have used 'const char *' variables and removed the ' ' before the '\n'. But:
Reviewed-by David Laight <[email protected]>
Quoted 46 lines
--- init/main.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)init/main.c +11
-10@@ -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;