Skip to content

Commit

Permalink
Add return value check and handling for xattr loading
Browse files Browse the repository at this point in the history
libbpf_find_vmlinux_btf_id may return error code for different reasons. We
should check and report the error we have just got, rather than let it slip
down the path and give an ambiguous error later.

Signed-off-by: He Zhe <zhe.he@windriver.com>
  • Loading branch information
He Zhe authored and yonghong-song committed Jul 23, 2020
1 parent a02663b commit ba0bacf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/cc/libbpf.c
Expand Up @@ -588,8 +588,18 @@ int bcc_prog_load_xattr(struct bpf_load_program_attr *attr, int prog_len,

if (attr->prog_type == BPF_PROG_TYPE_TRACING ||
attr->prog_type == BPF_PROG_TYPE_LSM) {
attr->attach_btf_id = libbpf_find_vmlinux_btf_id(attr->name + name_offset,
expected_attach_type);
ret = libbpf_find_vmlinux_btf_id(attr->name + name_offset,
expected_attach_type);
if (ret == -EINVAL) {
fprintf(stderr, "bpf: vmlinux BTF is not found\n");
return ret;
} else if (ret < 0) {
fprintf(stderr, "bpf: %s is not found in vmlinux BTF\n",
attr->name + name_offset);
return ret;
}

attr->attach_btf_id = ret;
attr->expected_attach_type = expected_attach_type;
}

Expand Down

0 comments on commit ba0bacf

Please sign in to comment.