Skip to content

Commit 3b0d858

Browse files
solbjornKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
samples: bpf: xdpsock: fix -Wmaybe-uninitialized
Fix two sort-of-false-positives in the xdpsock userspace part: samples/bpf/xdpsock_user.c: In function 'main': samples/bpf/xdpsock_user.c:1531:47: warning: 'tv_usec' may be used uninitialized in this function [-Wmaybe-uninitialized] 1531 | pktgen_hdr->tv_usec = htonl(tv_usec); | ^~~~~~~~~~~~~~ samples/bpf/xdpsock_user.c:1500:26: note: 'tv_usec' was declared here 1500 | u32 idx, tv_sec, tv_usec; | ^~~~~~~ samples/bpf/xdpsock_user.c:1530:46: warning: 'tv_sec' may be used uninitialized in this function [-Wmaybe-uninitialized] 1530 | pktgen_hdr->tv_sec = htonl(tv_sec); | ^~~~~~~~~~~~~ samples/bpf/xdpsock_user.c:1500:18: note: 'tv_sec' was declared here 1500 | u32 idx, tv_sec, tv_usec; | ^~~~~~ Both variables are always initialized when @opt_tstamp == true and they're being used also only when @opt_tstamp == true. However, that variable comes from the BSS and is being toggled from another function. They can't be executed simultaneously to actually trigger undefined behaviour, but purely technically it is a correct warning. Just initialize them with zeroes. Fixes: eb68db4 ("samples/bpf: xdpsock: Add timestamp for Tx-only operation") Signed-off-by: Alexander Lobakin <[email protected]> Acked-by: Maciej Fijalkowski <[email protected]>
1 parent 004fcae commit 3b0d858

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

samples/bpf/xdpsock_user.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ static void rx_drop_all(void)
14961496
static int tx_only(struct xsk_socket_info *xsk, u32 *frame_nb,
14971497
int batch_size, unsigned long tx_ns)
14981498
{
1499-
u32 idx, tv_sec, tv_usec;
1499+
u32 idx, tv_sec = 0, tv_usec = 0;
15001500
unsigned int i;
15011501

15021502
while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) <

0 commit comments

Comments
 (0)