Re: [PATCH v1 1/1] bpf: Mark BPF printing functions with __printf() attribute

From: Alexei Starovoitov
Date: Tue Dec 09 2025 - 04:14:25 EST


On Tue, Dec 9, 2025 at 1:21 AM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
>
> The printing functions in BPF code are using printf() type of format,
> and compiler is not happy about them as is:
>
> kernel/bpf/helpers.c:1069:9: error: function ‘____bpf_snprintf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 1069 | err = bstr_printf(str, str_size, fmt, data.bin_args);
> | ^~~
>
> kernel/trace/bpf_trace.c:377:9: error: function ‘____bpf_trace_printk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 377 | ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> | ^~~
>
> kernel/trace/bpf_trace.c:433:9: error: function ‘____bpf_trace_vprintk’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 433 | ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt, data.bin_args);
> | ^~~
>
> kernel/trace/bpf_trace.c:475:9: error: function ‘____bpf_seq_printf’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]
> 475 | seq_bprintf(m, fmt, data.bin_args);
> | ^~~~~~~~~~~
>
> Fix the compilation errors by adding __printf() attribute. For that
> we need to pass it down to the BPF_CALL_x() and wrap into PRINTF_BPF_CALL_*()
> to make code neater.
>
> Reported-by: kernel test robot <lkp@xxxxxxxxx>
> Closes: https://lore.kernel.org/oe-kbuild-all/202512061425.x0qTt9ww-lkp@xxxxxxxxx/
> Closes: https://lore.kernel.org/oe-kbuild-all/202512061640.9hKTnB8p-lkp@xxxxxxxxx/
> Closes: https://lore.kernel.org/oe-kbuild-all/202512081321.2h9ThWTg-lkp@xxxxxxxxx/
> Fixes: 10aceb629e19 ("bpf: Add bpf_trace_vprintk helper")
> Fixes: 7b15523a989b ("bpf: Add a bpf_snprintf helper")
> Fixes: 492e639f0c22 ("bpf: Add bpf_seq_printf and bpf_seq_write helpers")
> Fixes: f3694e001238 ("bpf: add BPF_CALL_x macros for declaring helpers")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
>
> This is combined change and I think there is no need to split it, but if required
> I can do it in a four changes. Note, the culprits are older than 4 years and stable
> kernels anyway don't go that deep nowadays.

This is pointless churn to shut up a warning.
Teach syzbot to stop this spam instead.
At the end this patch doesn't make any visible difference,
since user declarations of these helpers are auto generated
from uapi/bpf.h file and __printf attribute is not there.

pw-bot: cr