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

tracing: Mark binary printing functions with __printf() attribute

Binary printing functions are using printf() type of format, and compiler
is not happy about them as is:

kernel/trace/trace.c:3292:9: error: function ‘trace_vbprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
kernel/trace/trace_seq.c:182:9: error: function ‘trace_seq_bprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

Fix the compilation errors by adding __printf() attribute.

While at it, move existing __printf() attributes from the implementations
to the declarations. IT also fixes incorrect attribute parameters that are
used for trace_array_printk().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Kees Cook <kees@kernel.org>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20250321144822.324050-4-andriy.shevchenko@linux.intel.com
Signed-off-by: Petr Mladek <pmladek@suse.com>

authored by

Andy Shevchenko and committed by
Petr Mladek
196a0626 6b2c1e30

+18 -21
+2 -2
include/linux/trace.h
··· 72 72 static inline void trace_printk_init_buffers(void) 73 73 { 74 74 } 75 - static inline int trace_array_printk(struct trace_array *tr, unsigned long ip, 76 - const char *fmt, ...) 75 + static inline __printf(3, 4) 76 + int trace_array_printk(struct trace_array *tr, unsigned long ip, const char *fmt, ...) 77 77 { 78 78 return 0; 79 79 }
+4 -4
include/linux/trace_seq.h
··· 88 88 void trace_seq_printf(struct trace_seq *s, const char *fmt, ...); 89 89 extern __printf(2, 0) 90 90 void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args); 91 - extern void 92 - trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary); 91 + extern __printf(2, 0) 92 + void trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary); 93 93 extern int trace_print_seq(struct seq_file *m, struct trace_seq *s); 94 94 extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, 95 95 int cnt); ··· 113 113 void trace_seq_printf(struct trace_seq *s, const char *fmt, ...) 114 114 { 115 115 } 116 - static inline void 117 - trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary) 116 + static inline __printf(2, 0) 117 + void trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary) 118 118 { 119 119 } 120 120
+3 -8
kernel/trace/trace.c
··· 3340 3340 } 3341 3341 EXPORT_SYMBOL_GPL(trace_vbprintk); 3342 3342 3343 - __printf(3, 0) 3344 - static int 3345 - __trace_array_vprintk(struct trace_buffer *buffer, 3346 - unsigned long ip, const char *fmt, va_list args) 3343 + static __printf(3, 0) 3344 + int __trace_array_vprintk(struct trace_buffer *buffer, 3345 + unsigned long ip, const char *fmt, va_list args) 3347 3346 { 3348 3347 struct ring_buffer_event *event; 3349 3348 int len = 0, size; ··· 3392 3393 return len; 3393 3394 } 3394 3395 3395 - __printf(3, 0) 3396 3396 int trace_array_vprintk(struct trace_array *tr, 3397 3397 unsigned long ip, const char *fmt, va_list args) 3398 3398 { ··· 3421 3423 * Note, trace_array_init_printk() must be called on @tr before this 3422 3424 * can be used. 3423 3425 */ 3424 - __printf(3, 0) 3425 3426 int trace_array_printk(struct trace_array *tr, 3426 3427 unsigned long ip, const char *fmt, ...) 3427 3428 { ··· 3465 3468 } 3466 3469 EXPORT_SYMBOL_GPL(trace_array_init_printk); 3467 3470 3468 - __printf(3, 4) 3469 3471 int trace_array_printk_buf(struct trace_buffer *buffer, 3470 3472 unsigned long ip, const char *fmt, ...) 3471 3473 { ··· 3480 3484 return ret; 3481 3485 } 3482 3486 3483 - __printf(2, 0) 3484 3487 int trace_vprintk(unsigned long ip, const char *fmt, va_list args) 3485 3488 { 3486 3489 return trace_array_vprintk(printk_trace, ip, fmt, args);
+9 -7
kernel/trace/trace.h
··· 838 838 839 839 extern void *head_page(struct trace_array_cpu *data); 840 840 extern unsigned long long ns2usecs(u64 nsec); 841 - extern int 842 - trace_vbprintk(unsigned long ip, const char *fmt, va_list args); 843 - extern int 844 - trace_vprintk(unsigned long ip, const char *fmt, va_list args); 845 - extern int 846 - trace_array_vprintk(struct trace_array *tr, 847 - unsigned long ip, const char *fmt, va_list args); 841 + 842 + __printf(2, 0) 843 + int trace_vbprintk(unsigned long ip, const char *fmt, va_list args); 844 + __printf(2, 0) 845 + int trace_vprintk(unsigned long ip, const char *fmt, va_list args); 846 + __printf(3, 0) 847 + int trace_array_vprintk(struct trace_array *tr, 848 + unsigned long ip, const char *fmt, va_list args); 849 + __printf(3, 4) 848 850 int trace_array_printk_buf(struct trace_buffer *buffer, 849 851 unsigned long ip, const char *fmt, ...); 850 852 void trace_printk_seq(struct trace_seq *s);