Commit a2889a4c authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by Daniel Borkmann

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: f80442a4 ("bpf: btf: Change how section is supported in btf_header")
Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent a1c81810
...@@ -1981,8 +1981,7 @@ static int btf_sec_info_cmp(const void *a, const void *b) ...@@ -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, static int btf_check_sec_info(struct btf_verifier_env *env,
u32 btf_data_size) u32 btf_data_size)
{ {
const unsigned int nr_secs = ARRAY_SIZE(btf_sec_info_offset); struct btf_sec_info secs[ARRAY_SIZE(btf_sec_info_offset)];
struct btf_sec_info secs[nr_secs];
u32 total, expected_total, i; u32 total, expected_total, i;
const struct btf_header *hdr; const struct btf_header *hdr;
const struct btf *btf; const struct btf *btf;
...@@ -1991,17 +1990,17 @@ static int btf_check_sec_info(struct btf_verifier_env *env, ...@@ -1991,17 +1990,17 @@ static int btf_check_sec_info(struct btf_verifier_env *env,
hdr = &btf->hdr; hdr = &btf->hdr;
/* Populate the secs from 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 + secs[i] = *(struct btf_sec_info *)((void *)hdr +
btf_sec_info_offset[i]); btf_sec_info_offset[i]);
sort(secs, nr_secs, sizeof(struct btf_sec_info), sort(secs, ARRAY_SIZE(btf_sec_info_offset),
btf_sec_info_cmp, NULL); sizeof(struct btf_sec_info), btf_sec_info_cmp, NULL);
/* Check for gaps and overlap among sections */ /* Check for gaps and overlap among sections */
total = 0; total = 0;
expected_total = btf_data_size - hdr->hdr_len; 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) { if (expected_total < secs[i].off) {
btf_verifier_log(env, "Invalid section offset"); btf_verifier_log(env, "Invalid section offset");
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment