summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorMartin KaFai Lau <kafai@fb.com>2018-05-23 20:32:36 +0200
committerDaniel Borkmann <daniel@iogearbox.net>2018-05-24 09:15:11 +0200
commita2889a4c2d3aefdf6f2a636fa1531243653a7633 (patch)
tree438d5921310c11392d0e4995d1f3e7b90fc0203a /kernel
parenttools/lib/libbpf.c: fix string format to allow build on arm32 (diff)
downloadlinux-a2889a4c2d3aefdf6f2a636fa1531243653a7633.tar.xz
linux-a2889a4c2d3aefdf6f2a636fa1531243653a7633.zip
bpf: btf: Avoid variable length array
Sparse warning: kernel/bpf/btf.c:1985:34: warning: Variable length array is used. This patch directly uses ARRAY_SIZE(). Fixes: f80442a4cd18 ("bpf: btf: Change how section is supported in btf_header") Signed-off-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/btf.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 9cbeabb5aca3..7e90fd13b5b5 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -1981,8 +1981,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[ARRAY_SIZE(btf_sec_info_offset)];
u32 total, expected_total, i;
const struct btf_header *hdr;
const struct btf *btf;
@@ -1991,17 +1990,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 < ARRAY_SIZE(btf_sec_info_offset); i++)
secs[i] = *(struct btf_sec_info *)((void *)hdr +
btf_sec_info_offset[i]);
- sort(secs, nr_secs, sizeof(struct btf_sec_info),
- btf_sec_info_cmp, NULL);
+ sort(secs, ARRAY_SIZE(btf_sec_info_offset),
+ 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 < ARRAY_SIZE(btf_sec_info_offset); i++) {
if (expected_total < secs[i].off) {
btf_verifier_log(env, "Invalid section offset");
return -EINVAL;