• Andrii Nakryiko's avatar
    selftests/bpf: Fix maybe-uninitialized warning in xdpxceiver test · 105b842b
    Andrii Nakryiko authored
    
    
    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: default avatarAndrii Nakryiko <andrii@kernel.org>
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20210313210920.1959628-4-andrii@kernel.org
    105b842b
xdpxceiver.c 31.6 KB