]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
libbpf: Use pre-setup sec_def in libbpf_find_attach_btf_id()
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 16 Sep 2021 01:58:30 +0000 (18:58 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 17 Sep 2021 16:04:12 +0000 (09:04 -0700)
Don't perform another search for sec_def inside
libbpf_find_attach_btf_id(), as each recognized bpf_program already has
prog->sec_def set.

Also remove unnecessary NULL check for prog->sec_name, as it can never
be NULL.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20210916015836.1248906-2-andrii@kernel.org
tools/lib/bpf/libbpf.c

index 62a43c408d73890dea34397701b72819c6431030..5ba11b249e9b59c454fac1ff8f465d2e0f6fe742 100644 (file)
@@ -8461,19 +8461,15 @@ static int libbpf_find_attach_btf_id(struct bpf_program *prog, int *btf_obj_fd,
 {
        enum bpf_attach_type attach_type = prog->expected_attach_type;
        __u32 attach_prog_fd = prog->attach_prog_fd;
-       const char *name = prog->sec_name, *attach_name;
-       const struct bpf_sec_def *sec = NULL;
+       const char *attach_name;
        int err = 0;
 
-       if (!name)
-               return -EINVAL;
-
-       sec = find_sec_def(name);
-       if (!sec || !sec->is_attach_btf) {
-               pr_warn("failed to identify BTF ID based on ELF section name '%s'\n", name);
+       if (!prog->sec_def || !prog->sec_def->is_attach_btf) {
+               pr_warn("failed to identify BTF ID based on ELF section name '%s'\n",
+                       prog->sec_name);
                return -ESRCH;
        }
-       attach_name = name + sec->len;
+       attach_name = prog->sec_name + prog->sec_def->len;
 
        /* BPF program's BTF ID */
        if (attach_prog_fd) {