Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

libbpf: bpf__find_by_name[_kind] should use btf__get_nr_types()

When operating on split BTF, btf__find_by_name[_kind] will not
iterate over all types since they use btf->nr_types to show
the number of types to iterate over. For split BTF this is
the number of types _on top of base BTF_, so it will
underestimate the number of types to iterate over, especially
for vmlinux + module BTF, where the latter is much smaller.

Use btf__get_nr_types() instead.

Fixes: ba451366bf44 ("libbpf: Implement basic split BTF support")
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1605437195-2175-1-git-send-email-alan.maguire@oracle.com

authored by

Alan Maguire and committed by
Andrii Nakryiko
de91e631 b93ef089

+4 -4
+4 -4
tools/lib/bpf/btf.c
··· 674 674 675 675 __s32 btf__find_by_name(const struct btf *btf, const char *type_name) 676 676 { 677 - __u32 i; 677 + __u32 i, nr_types = btf__get_nr_types(btf); 678 678 679 679 if (!strcmp(type_name, "void")) 680 680 return 0; 681 681 682 - for (i = 1; i <= btf->nr_types; i++) { 682 + for (i = 1; i <= nr_types; i++) { 683 683 const struct btf_type *t = btf__type_by_id(btf, i); 684 684 const char *name = btf__name_by_offset(btf, t->name_off); 685 685 ··· 693 693 __s32 btf__find_by_name_kind(const struct btf *btf, const char *type_name, 694 694 __u32 kind) 695 695 { 696 - __u32 i; 696 + __u32 i, nr_types = btf__get_nr_types(btf); 697 697 698 698 if (kind == BTF_KIND_UNKN || !strcmp(type_name, "void")) 699 699 return 0; 700 700 701 - for (i = 1; i <= btf->nr_types; i++) { 701 + for (i = 1; i <= nr_types; i++) { 702 702 const struct btf_type *t = btf__type_by_id(btf, i); 703 703 const char *name; 704 704