On Thu, Nov 3, 2022 at 12:11 PM Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> wrote: > static int bpf_map_alloc_off_arr(struct bpf_map *map) > { > - bool has_spin_lock = map_value_has_spin_lock(map); > - bool has_timer = map_value_has_timer(map); > bool has_fields = !IS_ERR_OR_NULL(map); > struct btf_field_offs *fo; > - u32 i; > + struct btf_record *rec; > + u32 i, *off; > + u8 *sz; > > - if (!has_spin_lock && !has_timer && !has_fields) { > + if (!has_fields) { > map->field_offs = NULL; > return 0; > } > @@ -970,32 +987,14 @@ static int bpf_map_alloc_off_arr(struct bpf_map *map) > return -ENOMEM; > map->field_offs = fo; > > - fo->cnt = 0; > - if (has_spin_lock) { > - i = fo->cnt; > - > - fo->field_off[i] = map->spin_lock_off; > - fo->field_sz[i] = sizeof(struct bpf_spin_lock); > - fo->cnt++; > - } > - if (has_timer) { > - i = fo->cnt; > - > - fo->field_off[i] = map->timer_off; > - fo->field_sz[i] = sizeof(struct bpf_timer); > - fo->cnt++; > - } > - if (has_fields) { > - struct btf_record *rec = map->record; > - u32 *off = &fo->field_off[fo->cnt]; > - u8 *sz = &fo->field_sz[fo->cnt]; > - > - for (i = 0; i < rec->cnt; i++) { > - *off++ = rec->fields[i].offset; > - *sz++ = btf_field_type_size(rec->fields[i].type); > - } > - fo->cnt += rec->cnt; > + rec = map->record; > + off = &fo->field_off[fo->cnt]; > + sz = &fo->field_sz[fo->cnt]; Another bug that would have been obvious if you run any tests. (fo->cnt contains garbage) I'm surprised by the amount of issues in the series. > + for (i = 0; i < rec->cnt; i++) { > + *off++ = rec->fields[i].offset; > + *sz++ = btf_field_type_size(rec->fields[i].type); > } Anyway, pushed this patch as well after fixing this bug.