[PATCH bpf-next] bpf: Add __printf attribute to bpf_diag_source()

From: Adrián García Casado

Date: Mon Oct 19 2026 - 15:59:58 EST


Building kernel/bpf/diagnostics.o with W=1 triggers the following
compiler warning:

kernel/bpf/diagnostics.c:828:9: warning: function 'bpf_diag_source'
might be a candidate for 'gnu_printf' format attribute
[-Wsuggest-attribute=format]

bpf_diag_source() forwards its format string and variadic arguments to
bpf_diag_vfmt(), which is annotated with __printf(2, 0).

Add the missing __printf(4, 5) attribute to bpf_diag_source() to silence
the W=1 warning and enable compile-time format string checking for its
callers.

Signed-off-by: Adrián García Casado <adriangarciacasado42@xxxxxxxxx>
---
kernel/bpf/diagnostics.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/bpf/diagnostics.c b/kernel/bpf/diagnostics.c
index 0abbbe177e..2421f52eec 100644
--- a/kernel/bpf/diagnostics.c
+++ b/kernel/bpf/diagnostics.c
@@ -794,6 +794,7 @@ static void diag_print_insn_context(struct bpf_verifier_env *env, u32 insn_idx,
}
}

+__printf(4, 5)
static void bpf_diag_source(struct bpf_verifier_env *env, u32 insn_idx, const char *label,
const char *fmt, ...)
{
--
2.39.5