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

bpftool: Switch to new btf__type_cnt API

Replace the call to btf__get_nr_types with new API btf__type_cnt.
The old API will be deprecated in libbpf v0.7+. No functionality
change.

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211022130623.1548429-5-hengqi.chen@gmail.com

authored by

Hengqi Chen and committed by
Andrii Nakryiko
58fc155b 2d8f09fa

+8 -8
+6 -6
tools/bpf/bpftool/btf.c
··· 329 329 printf("\n\ttype_id=%u offset=%u size=%u", 330 330 v->type, v->offset, v->size); 331 331 332 - if (v->type <= btf__get_nr_types(btf)) { 332 + if (v->type < btf__type_cnt(btf)) { 333 333 vt = btf__type_by_id(btf, v->type); 334 334 printf(" (%s '%s')", 335 335 btf_kind_str[btf_kind_safe(btf_kind(vt))], ··· 390 390 } 391 391 } else { 392 392 const struct btf *base; 393 - int cnt = btf__get_nr_types(btf); 393 + int cnt = btf__type_cnt(btf); 394 394 int start_id = 1; 395 395 396 396 base = btf__base_btf(btf); 397 397 if (base) 398 - start_id = btf__get_nr_types(base) + 1; 398 + start_id = btf__type_cnt(base); 399 399 400 - for (i = start_id; i <= cnt; i++) { 400 + for (i = start_id; i < cnt; i++) { 401 401 t = btf__type_by_id(btf, i); 402 402 dump_btf_type(btf, i, t); 403 403 } ··· 440 440 goto done; 441 441 } 442 442 } else { 443 - int cnt = btf__get_nr_types(btf); 443 + int cnt = btf__type_cnt(btf); 444 444 445 - for (i = 1; i <= cnt; i++) { 445 + for (i = 1; i < cnt; i++) { 446 446 err = btf_dump__dump_type(d, i); 447 447 if (err) 448 448 goto done;
+2 -2
tools/bpf/bpftool/gen.c
··· 211 211 static int codegen_datasecs(struct bpf_object *obj, const char *obj_name) 212 212 { 213 213 struct btf *btf = bpf_object__btf(obj); 214 - int n = btf__get_nr_types(btf); 214 + int n = btf__type_cnt(btf); 215 215 struct btf_dump *d; 216 216 struct bpf_map *map; 217 217 const struct btf_type *sec; ··· 233 233 continue; 234 234 235 235 sec = NULL; 236 - for (i = 1; i <= n; i++) { 236 + for (i = 1; i < n; i++) { 237 237 const struct btf_type *t = btf__type_by_id(btf, i); 238 238 const char *name; 239 239