> On Nov 8, 2019, at 11:13 AM, Alexei Starovoitov <ast@xxxxxx> wrote: > > On 11/8/19 10:57 AM, Song Liu wrote: >> >> >>> On Nov 7, 2019, at 10:40 PM, Alexei Starovoitov <ast@xxxxxxxxxx> wrote: >>> >>> Extend libbpf api to pass attach_prog_fd into bpf_object__open. >>> >>> Signed-off-by: Alexei Starovoitov <ast@xxxxxxxxxx> >>> --- >> >> [...] >> >>> +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; >>> + >>> + info_linear = bpf_program__get_prog_info_linear(attach_prog_fd, 0); >>> + if (IS_ERR_OR_NULL(info_linear)) { >>> + pr_warn("failed get_prog_info_linear for FD %d\n", >>> + attach_prog_fd); >>> + return -EINVAL; >>> + } >>> + info = &info_linear->info; >>> + if (!info->btf_id) { >>> + pr_warn("The target program doesn't have BTF\n"); >>> + goto out; >>> + } >>> + if (btf__get_from_id(info->btf_id, &btf)) { >>> + pr_warn("Failed to get BTF of the program\n"); >>> + goto out; >>> + } >>> + err = btf__find_by_name_kind(btf, name, BTF_KIND_FUNC); >>> + btf__free(btf); >>> + if (err <= 0) { >>> + pr_warn("%s is not found in prog's BTF\n", name); >>> + goto out; >> ^^^ This goto doesn't really do much. > > yeah. it does look a bit weird. > I wanted to keep uniform error handling, but can remove it > if you insist. I think it is good as-is. Thanks, Song