I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_var_secinfo* btf_var_secinfos(const btf_type*)’: bpf/btf.h:302:41: warning: cast from type ‘const btf_type*’ to type ‘btf_var_secinfo*’ casts away qualifiers [-Wcast-qual] 302 | return (struct btf_var_secinfo *)(t + 1); | ^ The argument is const so the cast to following struct btf_var_secinfo pointer should be const as well. Casting the const away in btf.c call where it's correctly used without const in deduplication code. Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> --- tools/lib/bpf/btf.c | 5 +++-- tools/lib/bpf/btf.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index b5121c79fd9f..32527622792d 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -526,7 +526,8 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, t->size = size; - for (i = 0, vsi = btf_var_secinfos(t); i < vars; i++, vsi++) { + for (i = 0, vsi = (struct btf_var_secinfo *) btf_var_secinfos(t); + i < vars; i++, vsi++) { t_var = btf__type_by_id(btf, vsi->type); var = btf_var(t_var); @@ -2830,7 +2831,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) } case BTF_KIND_DATASEC: { - struct btf_var_secinfo *var = btf_var_secinfos(t); + struct btf_var_secinfo *var = (struct btf_var_secinfo *) btf_var_secinfos(t); __u16 vlen = btf_vlen(t); for (i = 0; i < vlen; i++) { diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 480dbe780fa7..ecccde0988b1 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -296,10 +296,10 @@ static inline const struct btf_var *btf_var(const struct btf_type *t) return (const struct btf_var *)(t + 1); } -static inline struct btf_var_secinfo * +static inline const struct btf_var_secinfo * btf_var_secinfos(const struct btf_type *t) { - return (struct btf_var_secinfo *)(t + 1); + return (const struct btf_var_secinfo *)(t + 1); } #ifdef __cplusplus -- 2.21.0