The bpf_btf_get_fd_by_id_opts() function allows setting the token fd in the opts, but leaves it to the caller to set the BPF_F_TOKEN_FD flag. This is error-prone, and there's no reason we can't just set it on the caller's behalf when an fd is supplied, so let's just do that. Signed-off-by: Toke Høiland-Jørgensen --- tools/lib/bpf/bpf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 059c358c9744..3331524344a3 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -1276,6 +1276,8 @@ int bpf_btf_get_fd_by_id_opts(__u32 id, attr.btf_id = id; attr.open_flags = OPTS_GET(opts, open_flags, 0); attr.fd_by_id_token_fd = OPTS_GET(opts, token_fd, 0); + if (attr.fd_by_id_token_fd) + attr.open_flags |= BPF_F_TOKEN_FD; fd = sys_bpf_fd(BPF_BTF_GET_FD_BY_ID, &attr, attr_sz); return libbpf_err_errno(fd); -- 2.56.1