From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
Andrii Nakryiko <andriin@fb.com>, Yonghong Song <yhs@fb.com>,
Martin KaFai Lau <kafai@fb.com>
Subject: [PATCH 4/7] libbpf: Return const btf_member from btf_members inline function
Date: Fri, 6 Sep 2019 09:31:41 +0200 [thread overview]
Message-ID: <20190906073144.31068-5-jolsa@kernel.org> (raw)
In-Reply-To: <20190906073144.31068-1-jolsa@kernel.org>
I'm getting following errors when compiling with -Wcast-qual:
bpf/btf.h: In function ‘btf_member* btf_members(const btf_type*)’:
bpf/btf.h:264:36: warning: cast from type ‘const btf_type*’ to type
‘btf_member*’ casts away qualifiers [-Wcast-qual]
264 | return (struct btf_member *)(t + 1);
| ^
The argument is const so the cast to following struct btf_member
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@kernel.org>
---
tools/lib/bpf/btf.c | 4 ++--
tools/lib/bpf/btf.h | 4 ++--
tools/lib/bpf/libbpf.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 5a39e9506760..560d1ae33675 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -1463,7 +1463,7 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx)
switch (btf_kind(t)) {
case BTF_KIND_STRUCT:
case BTF_KIND_UNION: {
- struct btf_member *m = btf_members(t);
+ struct btf_member *m = (struct btf_member *) btf_members(t);
__u16 vlen = btf_vlen(t);
for (j = 0; j < vlen; j++) {
@@ -2797,7 +2797,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
case BTF_KIND_STRUCT:
case BTF_KIND_UNION: {
- struct btf_member *member = btf_members(t);
+ struct btf_member *member = (struct btf_member *) btf_members(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 3b3216fa348f..cd1bd018ba8b 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -259,9 +259,9 @@ static inline const struct btf_enum *btf_enum(const struct btf_type *t)
return (const struct btf_enum *)(t + 1);
}
-static inline struct btf_member *btf_members(const struct btf_type *t)
+static inline const struct btf_member *btf_members(const struct btf_type *t)
{
- return (struct btf_member *)(t + 1);
+ return (const struct btf_member *)(t + 1);
}
/* Get bit offset of a member with specified index. */
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 2233f919dd88..7d3d6284dd2e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1389,7 +1389,7 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj)
} else if (!has_datasec && btf_is_datasec(t)) {
/* replace DATASEC with STRUCT */
const struct btf_var_secinfo *v = btf_var_secinfos(t);
- struct btf_member *m = btf_members(t);
+ struct btf_member *m = (struct btf_member *) btf_members(t);
struct btf_type *vt;
char *name;
--
2.21.0
next prev parent reply other threads:[~2019-09-06 7:31 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-06 7:31 [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Jiri Olsa
2019-09-06 7:31 ` [PATCH 1/7] libbpf: Use const cast for btf_int_* functions Jiri Olsa
2019-09-06 7:31 ` [PATCH 2/7] libbpf: Return const btf_array from btf_array inline function Jiri Olsa
2019-09-06 7:31 ` [PATCH 3/7] libbpf: Return const btf_enum from btf_enum " Jiri Olsa
2019-09-06 7:31 ` Jiri Olsa [this message]
2019-09-06 7:31 ` [PATCH 5/7] libbpf: Return const btf_param from btf_params " Jiri Olsa
2019-09-06 7:31 ` [PATCH 6/7] libbpf: Return const btf_var from btf_var " Jiri Olsa
2019-09-06 7:31 ` [PATCH 7/7] libbpf: Return const struct btf_var_secinfo from btf_var_secinfos " Jiri Olsa
2019-09-06 9:09 ` [PATCH 0/7] libbpf: Fix cast away const qualifiers in btf.h Andrii Nakryiko
2019-09-06 17:03 ` Alexei Starovoitov
2019-09-07 6:54 ` Jiri Olsa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190906073144.31068-5-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).