Skip to content

Commit b74e21a

Browse files
yonghong-songborkmann
authored andcommitted
samples/bpf: silence compiler warning for xdpsock_user.c
Compiling xdpsock_user.c with 4.8.5, I hit the following compilation warning: HOSTCC samples/bpf/xdpsock_user.o /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c: In function ‘main’: /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:449:6: warning: ‘idx_cq’ may be used unini tialized in this function [-Wmaybe-uninitialized] u32 idx_cq, idx_fq; ^ /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:606:7: warning: ‘idx_rx’ may be used unini tialized in this function [-Wmaybe-uninitialized] u32 idx_rx, idx_tx = 0; ^ /data/users/yhs/work/net-next/samples/bpf/xdpsock_user.c:506:6: warning: ‘idx_rx’ may be used unini tialized in this function [-Wmaybe-uninitialized] u32 idx_rx, idx_fq = 0; As an example, the code pattern looks like: u32 idx_cq; ... ret = xsk_ring_prod__reserve(&xsk->umem->fq, rcvd, &idx_fq); if (ret) { ... } ... idx_fq ... The compiler warns since it does not know whether &idx_fq is assigned or not inside the library function xsk_ring_prod__reserve(). Let us assign an initial value 0 to such auto variables to silence compiler warning. Fixes: 248c7f9 ("samples/bpf: convert xdpsock to use libbpf for AF_XDP access") Signed-off-by: Yonghong Song <yhs@fb.com> Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent a83de90 commit b74e21a

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎samples/bpf/xdpsock_user.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static void kick_tx(struct xsk_socket_info *xsk)
446446

447447
static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk)
448448
{
449-
u32 idx_cq, idx_fq;
449+
u32 idx_cq = 0, idx_fq = 0;
450450
unsigned int rcvd;
451451
size_t ndescs;
452452

@@ -503,7 +503,7 @@ static inline void complete_tx_only(struct xsk_socket_info *xsk)
503503
static void rx_drop(struct xsk_socket_info *xsk)
504504
{
505505
unsigned int rcvd, i;
506-
u32 idx_rx, idx_fq = 0;
506+
u32 idx_rx = 0, idx_fq = 0;
507507
int ret;
508508

509509
rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx);
@@ -603,7 +603,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
603603
{
604604
for (;;) {
605605
unsigned int rcvd, i;
606-
u32 idx_rx, idx_tx = 0;
606+
u32 idx_rx = 0, idx_tx = 0;
607607
int ret;
608608

609609
for (;;) {

0 commit comments

Comments
 (0)