On Mon, Jun 03, 2024 at 04:17:16PM -0700, Andrii Nakryiko wrote: > Switch all BPF linker code dealing with iterating BTF type ID and string > offset fields to new btf_field_iter facilities. > > Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx> > --- > tools/lib/bpf/linker.c | 60 ++++++++++++++++++++++++++---------------- > 1 file changed, 38 insertions(+), 22 deletions(-) > > diff --git a/tools/lib/bpf/linker.c b/tools/lib/bpf/linker.c > index 0d4be829551b..be6539e59cf6 100644 > --- a/tools/lib/bpf/linker.c > +++ b/tools/lib/bpf/linker.c > @@ -957,19 +957,35 @@ static int check_btf_str_off(__u32 *str_off, void *ctx) > static int linker_sanity_check_btf(struct src_obj *obj) > { > struct btf_type *t; > - int i, n, err = 0; > + int i, n, err; > > if (!obj->btf) > return 0; > > n = btf__type_cnt(obj->btf); > for (i = 1; i < n; i++) { > + struct btf_field_iter it; > + __u32 *type_id, *str_off; > + const char *s; > + > t = btf_type_by_id(obj->btf, i); > > - err = err ?: btf_type_visit_type_ids(t, check_btf_type_id, obj->btf); > - err = err ?: btf_type_visit_str_offs(t, check_btf_str_off, obj->btf); > + err = btf_field_iter_init(&it, t, BTF_FIELD_ITER_IDS); > if (err) > return err; > + while ((type_id = btf_field_iter_next(&it))) { > + if (*type_id >= n) > + return -EINVAL; > + } > + > + err = btf_field_iter_init(&it, t, BTF_FIELD_ITER_STRS); > + if (err) > + return err; > + while ((str_off = btf_field_iter_next(&it))) { > + s = btf__str_by_offset(obj->btf, *str_off); > + if (!s) > + return -EINVAL; nit, we could drop 's' and just do (!btf__str_by_offset(obj->btf, *str_off)) otherwise the patchset lgtm Acked-by: Jiri Olsa <jolsa@xxxxxxxxxx> jirka > + } > } > > return 0; > @@ -2234,26 +2250,10 @@ static int linker_fixup_btf(struct src_obj *obj) > return 0; > } SNIP