Skip to contentSkip to conversation

bpf: Mark bpf_stream_vprintk_impl() with __printf() attribute

PATCH In review Andy Shevchenko 2 participants 2 messages Dec 8, 2025 – Dec 9, 2025 BPF

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Mark bpf_stream_vprintk_impl() with __printf() attribute

bpf_stream_vprintk_impl() is using printf() type of format, and compiler is not happy about them as is:

kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

  241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
      |         ^~~

Fix the compilation errors by adding __printf() attribute.

Fixes 5ab154f1463a ("bpf: Introduce BPF standard streams")
---
 kernel/bpf/stream.c | 1 +
 1 file changed, 1 insertion(+)
kernel/bpf/stream.c +1 -0
index 0b6bc3f30335..4bff72e3c16f 100644
@@ -212,6 +212,7 @@ __bpf_kfunc_start_defs();
  * Avoid using enum bpf_stream_id so that kfunc users don't have to pull in the
  * enum in headers.
  */
+__printf(2, 0)
 __bpf_kfunc int bpf_stream_vprintk_impl(int stream_id, const char *fmt__str, const void *args,
 					u32 len__sz, void *aux__prog)
 {
Signature · 1 line
2.50.1
#1 lore raw
Quoted 21 lines · Andy Shevchenko

bpf_stream_vprintk_impl() is using printf() type of format, and compiler is not happy about them as is:

kernel/bpf/stream.c:241:9: error: function ‘bpf_stream_vprintk_impl’ might be a candidate for ‘gnu_printf’ format attribute [-Werror=suggest-attribute=format]

  241 |         ret = bstr_printf(data.buf, MAX_BPRINTF_BUF, fmt__str, data.bin_args);
      |         ^~~

Fix the compilation errors by adding __printf() attribute.

Fixes 5ab154f1463a ("bpf: Introduce BPF standard streams")
---
 kernel/bpf/stream.c | 1 +
 1 file changed, 1 insertion(+)
kernel/bpf/stream.c +0 -0
index 0b6bc3f30335..4bff72e3c16f 100644

kernel/bpf/stream.c __bpf_kfunc_start_defs(); · line 216

Quoted 5 lines
kernel/bpf/stream.c +1 -0
@@ -212,6 +212,7 @@ __bpf_kfunc_start_defs();
  * Avoid using enum bpf_stream_id so that kfunc users don't have to pull in the
  * enum in headers.
  */
+__printf(2, 0)
 __bpf_kfunc int bpf_stream_vprintk_impl(int stream_id, const char *fmt__str, const void *args,

same issue.
The addition of this attribute doesn't make any difference, since kfunc protos are autogenerated from BTF and it's not there.

pw-bot: cr