Skip to content

Commit 196a062

Browse files
andy-shevpmladek
authored andcommitted
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>
1 parent 6b2c1e3 commit 196a062

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

include/linux/trace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ static inline int unregister_ftrace_export(struct trace_export *export)
7272
static inline void trace_printk_init_buffers(void)
7373
{
7474
}
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, ...)
7777
{
7878
return 0;
7979
}

include/linux/trace_seq.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ extern __printf(2, 3)
8888
void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
8989
extern __printf(2, 0)
9090
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);
9393
extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
9494
extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
9595
int cnt);
@@ -113,8 +113,8 @@ static inline __printf(2, 3)
113113
void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
114114
{
115115
}
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)
118118
{
119119
}
120120

kernel/trace/trace.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3340,10 +3340,9 @@ int trace_vbprintk(unsigned long ip, const char *fmt, va_list args)
33403340
}
33413341
EXPORT_SYMBOL_GPL(trace_vbprintk);
33423342

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)
33473346
{
33483347
struct ring_buffer_event *event;
33493348
int len = 0, size;
@@ -3393,7 +3392,6 @@ __trace_array_vprintk(struct trace_buffer *buffer,
33933392
return len;
33943393
}
33953394

3396-
__printf(3, 0)
33973395
int trace_array_vprintk(struct trace_array *tr,
33983396
unsigned long ip, const char *fmt, va_list args)
33993397
{
@@ -3423,7 +3421,6 @@ int trace_array_vprintk(struct trace_array *tr,
34233421
* Note, trace_array_init_printk() must be called on @tr before this
34243422
* can be used.
34253423
*/
3426-
__printf(3, 0)
34273424
int trace_array_printk(struct trace_array *tr,
34283425
unsigned long ip, const char *fmt, ...)
34293426
{
@@ -3468,7 +3465,6 @@ int trace_array_init_printk(struct trace_array *tr)
34683465
}
34693466
EXPORT_SYMBOL_GPL(trace_array_init_printk);
34703467

3471-
__printf(3, 4)
34723468
int trace_array_printk_buf(struct trace_buffer *buffer,
34733469
unsigned long ip, const char *fmt, ...)
34743470
{
@@ -3484,7 +3480,6 @@ int trace_array_printk_buf(struct trace_buffer *buffer,
34843480
return ret;
34853481
}
34863482

3487-
__printf(2, 0)
34883483
int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
34893484
{
34903485
return trace_array_vprintk(printk_trace, ip, fmt, args);

kernel/trace/trace.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -838,13 +838,15 @@ static inline void __init disable_tracing_selftest(const char *reason)
838838

839839
extern void *head_page(struct trace_array_cpu *data);
840840
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)
848850
int trace_array_printk_buf(struct trace_buffer *buffer,
849851
unsigned long ip, const char *fmt, ...);
850852
void trace_printk_seq(struct trace_seq *s);

0 commit comments

Comments
 (0)