Skip to contentSkip to conversation

bpf: fix a (false) compiler warning

PATCH Applied Peter Oskolkov 3 participants 3 messages Jan 16, 2019 – Jan 17, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpf: fix a (false) compiler warning

An older GCC compiler complains:

kernel/bpf/verifier.c: In function 'bpf_check':
kernel/bpf/verifier.c:4***:13: error: 'prev_offset' may be used uninitialized
in this function [-Werror=maybe-uninitialized]

   } else if (krecord[i].insn_offset <= prev_offset) {
             ^

kernel/bpf/verifier.c:4***:38: note: 'prev_offset' was declared here
u32 i, nfuncs, urec_size, min_size, prev_offset;

Although the compiler is wrong here, the patch makes sure that prev_offset is always initialized, just to silence the warning.

v2: fix a spelling error in the commit message.

---
 kernel/bpf/verifier.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/verifier.c +2 -1
index 56674a7c3778..ce87198ecd01 100644
@@ -4997,13 +4997,14 @@ static int check_btf_func(struct bpf_verifier_env *env,
 			  const union bpf_attr *attr,
 			  union bpf_attr __user *uattr)
 {
-	u32 i, nfuncs, urec_size, min_size, prev_offset;
+	u32 i, nfuncs, urec_size, min_size;
 	u32 krec_size = sizeof(struct bpf_func_info);
 	struct bpf_func_info *krecord;
 	const struct btf_type *type;
 	struct bpf_prog *prog;
 	const struct btf *btf;
 	void __user *urecord;
+	u32 prev_offset = 0;
 	int ret = 0;
 
 	nfuncs = attr->func_info_cnt;
Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Peter Oskolkov

An older GCC compiler complains:

kernel/bpf/verifier.c: In function 'bpf_check':
kernel/bpf/verifier.c:4***:13: error: 'prev_offset' may be used uninitialized
in this function [-Werror=maybe-uninitialized]

   } else if (krecord[i].insn_offset <= prev_offset) {
             ^

kernel/bpf/verifier.c:4***:38: note: 'prev_offset' was declared here
u32 i, nfuncs, urec_size, min_size, prev_offset;

Quoted 6 lines

Although the compiler is wrong here, the patch makes sure that prev_offset is always initialized, just to silence the warning.

v2: fix a spelling error in the commit message.

maintainer Applied
#2 lore raw
In reply to Peter Oskolkov
Quoted 10 lines · Peter Oskolkov

An older GCC compiler complains:

kernel/bpf/verifier.c: In function 'bpf_check':
kernel/bpf/verifier.c:4***:13: error: 'prev_offset' may be used uninitialized
in this function [-Werror=maybe-uninitialized]

   } else if (krecord[i].insn_offset <= prev_offset) {
             ^

kernel/bpf/verifier.c:4***:38: note: 'prev_offset' was declared here
u32 i, nfuncs, urec_size, min_size, prev_offset;

Quoted 6 lines

Although the compiler is wrong here, the patch makes sure that prev_offset is always initialized, just to silence the warning.

v2: fix a spelling error in the commit message.

Applied, thanks!