Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Peter Oskolkov <posk@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>

authored by

Peter Oskolkov and committed by
Daniel Borkmann
d0b2818e 4edc01b8

+2 -1
+2 -1
kernel/bpf/verifier.c
··· 4997 4997 const union bpf_attr *attr, 4998 4998 union bpf_attr __user *uattr) 4999 4999 { 5000 - u32 i, nfuncs, urec_size, min_size, prev_offset; 5000 + u32 i, nfuncs, urec_size, min_size; 5001 5001 u32 krec_size = sizeof(struct bpf_func_info); 5002 5002 struct bpf_func_info *krecord; 5003 5003 const struct btf_type *type; 5004 5004 struct bpf_prog *prog; 5005 5005 const struct btf *btf; 5006 5006 void __user *urecord; 5007 + u32 prev_offset = 0; 5007 5008 int ret = 0; 5008 5009 5009 5010 nfuncs = attr->func_info_cnt;