summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorQuentin Monnet <quentin@isovalent.com>2021-07-29 17:20:21 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-09-15 10:02:16 +0200
commit3d79bc7e88a22371df575bb61fa2e18c61e08c58 (patch)
treeca00311b328585ec5e1016287f6b13296c0e8cbd /tools
parentb3bf0743a6cc4667931fae6551751ec23ed487d2 (diff)
libbpf: Return non-null error on failures in libbpf_find_prog_btf_id()
[ Upstream commit 6d2d73cdd673d493f9f3751188757129b1d23fb7 ] Variable "err" is initialised to -EINVAL so that this error code is returned when something goes wrong in libbpf_find_prog_btf_id(). However, a recent change in the function made use of the variable in such a way that it is set to 0 if retrieving linear information on the program is successful, and this 0 value remains if we error out on failures at later stages. Let's fix this by setting err to -EINVAL later in the function. Fixes: e9fc3ce99b34 ("libbpf: Streamline error reporting for high-level APIs") Signed-off-by: Quentin Monnet <quentin@isovalent.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20210729162028.29512-2-quentin@isovalent.com Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/lib/bpf/libbpf.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index aa5ad6fc5f40..2234d5c33177 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -9515,7 +9515,7 @@ static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd)
struct bpf_prog_info_linear *info_linear;
struct bpf_prog_info *info;
struct btf *btf = NULL;
- int err = -EINVAL;
+ int err;
info_linear = bpf_program__get_prog_info_linear(attach_prog_fd, 0);
err = libbpf_get_error(info_linear);
@@ -9524,6 +9524,8 @@ static int libbpf_find_prog_btf_id(const char *name, __u32 attach_prog_fd)
attach_prog_fd);
return err;
}
+
+ err = -EINVAL;
info = &info_linear->info;
if (!info->btf_id) {
pr_warn("The target program doesn't have BTF\n");