From: Martin KaFai Lau <kafai@fb.com>
To: <netdev@vger.kernel.org>
Cc: Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>
Subject: [PATCH bpf-next] bpf: btf: Avoid variable length array
Date: Wed, 23 May 2018 10:46:59 -0700 [thread overview]
Message-ID: <20180523174659.354660-1-kafai@fb.com> (raw)
Sparse warning:
kernel/bpf/btf.c:1985:34: warning: Variable length array is used.
This patch moves the nr_secs from btf_check_sec_info() to a macro.
Fixes: f80442a4cd18 ("bpf: btf: Change how section is supported in btf_header")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
---
kernel/bpf/btf.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 9cbeabb5aca3..517296712774 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -1970,6 +1970,8 @@ static const size_t btf_sec_info_offset[] = {
offsetof(struct btf_header, str_off),
};
+#define NR_SECS ARRAY_SIZE(btf_sec_info_offset)
+
static int btf_sec_info_cmp(const void *a, const void *b)
{
const struct btf_sec_info *x = a;
@@ -1981,8 +1983,7 @@ static int btf_sec_info_cmp(const void *a, const void *b)
static int btf_check_sec_info(struct btf_verifier_env *env,
u32 btf_data_size)
{
- const unsigned int nr_secs = ARRAY_SIZE(btf_sec_info_offset);
- struct btf_sec_info secs[nr_secs];
+ struct btf_sec_info secs[NR_SECS];
u32 total, expected_total, i;
const struct btf_header *hdr;
const struct btf *btf;
@@ -1991,17 +1992,17 @@ static int btf_check_sec_info(struct btf_verifier_env *env,
hdr = &btf->hdr;
/* Populate the secs from hdr */
- for (i = 0; i < nr_secs; i++)
+ for (i = 0; i < NR_SECS; i++)
secs[i] = *(struct btf_sec_info *)((void *)hdr +
btf_sec_info_offset[i]);
- sort(secs, nr_secs, sizeof(struct btf_sec_info),
+ sort(secs, NR_SECS, sizeof(struct btf_sec_info),
btf_sec_info_cmp, NULL);
/* Check for gaps and overlap among sections */
total = 0;
expected_total = btf_data_size - hdr->hdr_len;
- for (i = 0; i < nr_secs; i++) {
+ for (i = 0; i < NR_SECS; i++) {
if (expected_total < secs[i].off) {
btf_verifier_log(env, "Invalid section offset");
return -EINVAL;
--
2.9.5
next reply other threads:[~2018-05-23 17:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-23 17:46 Martin KaFai Lau [this message]
2018-05-23 18:11 ` [PATCH bpf-next] bpf: btf: Avoid variable length array Joe Perches
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=20180523174659.354660-1-kafai@fb.com \
--to=kafai@fb.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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