Skip to contentSkip to conversation

bpf: move warning in btf_load_into_kernel

PATCH New Jordan Rome 1 participant 1 message Feb 19, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: move warning in btf_load_into_kernel

When BTF fails to load, only show the warning for callers that didn't supply a log_buf. This will remove an unneeded warning for users loading BPF programs (via bpf_object__sanitize_and_load_btf) on kernels that don't require BTF.

This also assumes that callers providing a log_buf know what they're doing.

---
 tools/lib/bpf/btf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/lib/bpf/btf.c +3 -2
index eea99c766a20..e4a463bda0b8 100644
@@ -1447,10 +1447,11 @@ int btf_load_into_kernel(struct btf *btf,
 			goto retry_load;
 
 		err = -errno;
-		pr_warn("BTF loading error: %s\n", errstr(err));
 		/* don't print out contents of custom log_buf */
-		if (!log_buf && buf[0])
+		if (!log_buf && buf[0]) {
+			pr_warn("BTF loading error: %s\n", errstr(err));
 			pr_warn("-- BEGIN BTF LOAD LOG ---\n%s\n-- END BTF LOAD LOG --\n", buf);
+		}
 	}
 
 done:

--
2.43.5