]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
selftests/bpf: Fix maybe-uninitialized warning in xdpxceiver test
authorAndrii Nakryiko <andrii@kernel.org>
Sat, 13 Mar 2021 21:09:19 +0000 (13:09 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 16 Mar 2021 19:26:49 +0000 (12:26 -0700)
commit105b842ba4ef2ddc287645cb33f90b960c16075b
treeaef07129a6876cee43548b03b211c1224f808e3a
parent4bbb3583687051ef99966ddaeb1730441b777d40
selftests/bpf: Fix maybe-uninitialized warning in xdpxceiver test

xsk_ring_prod__reserve() doesn't necessarily set idx in some conditions, so
from static analysis point of view compiler is right about the problems like:

In file included from xdpxceiver.c:92:
xdpxceiver.c: In function ‘xsk_populate_fill_ring’:
/data/users/andriin/linux/tools/testing/selftests/bpf/tools/include/bpf/xsk.h:119:20: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  return &addrs[idx & fill->mask];
                ~~~~^~~~~~~~~~~~
xdpxceiver.c:300:6: note: ‘idx’ was declared here
  u32 idx;
      ^~~
xdpxceiver.c: In function ‘tx_only’:
xdpxceiver.c:596:30: warning: ‘idx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   struct xdp_desc *tx_desc = xsk_ring_prod__tx_desc(&xsk->tx, idx + i);
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix two warnings reported by compiler by pre-initializing variable.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210313210920.1959628-4-andrii@kernel.org
tools/testing/selftests/bpf/xdpxceiver.c