I'm getting following errors when compiling with -Wcast-qual: bpf/btf.h: In function ‘btf_enum* btf_enum(const btf_type*)’: bpf/btf.h:259:34: warning: cast from type ‘const btf_type*’ to type ‘btf_enum*’ casts away qualifier 259 | return (struct btf_enum *)(t + 1); | ^ The argument is const so the cast to following struct btf_enum 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 | 2 +- tools/lib/bpf/btf.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index d6327bcc713a..5a39e9506760 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -1475,7 +1475,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx) break; } case BTF_KIND_ENUM: { - struct btf_enum *m = btf_enum(t); + struct btf_enum *m = (struct btf_enum *) btf_enum(t); __u16 vlen = btf_vlen(t); for (j = 0; j < vlen; j++) { diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h index 6bbf5772aa61..3b3216fa348f 100644 --- a/tools/lib/bpf/btf.h +++ b/tools/lib/bpf/btf.h @@ -254,9 +254,9 @@ static inline const struct btf_array *btf_array(const struct btf_type *t) return (const struct btf_array *)(t + 1); } -static inline struct btf_enum *btf_enum(const struct btf_type *t) +static inline const struct btf_enum *btf_enum(const struct btf_type *t) { - return (struct btf_enum *)(t + 1); + return (const struct btf_enum *)(t + 1); } static inline struct btf_member *btf_members(const struct btf_type *t) -- 2.21.0