[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAPhsuW7AV+RSqmH3WOSB6uvS2oiXH-Tgfx84H0rEC9_NyZ3SNA@mail.gmail.com>
Date: Fri, 15 Apr 2022 16:57:53 -0700
From: Song Liu <song@...nel.org>
To: Alexander Lobakin <alobakin@...me>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Martin KaFai Lau <kafai@...com>,
Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Jesper Dangaard Brouer <hawk@...nel.org>,
Björn Töpel <bjorn@...nel.org>,
Magnus Karlsson <magnus.karlsson@...el.com>,
Jonathan Lemon <jonathan.lemon@...il.com>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Dmitrii Dolgov <9erthalion6@...il.com>,
Quentin Monnet <quentin@...valent.com>,
Tiezhu Yang <yangtiezhu@...ngson.cn>,
Kumar Kartikeya Dwivedi <memxor@...il.com>,
Chenbo Feng <fengc@...gle.com>,
Willem de Bruijn <willemb@...gle.com>,
Daniel Wagner <daniel.wagner@...-carit.de>,
Thomas Graf <tgraf@...g.ch>,
Ong Boon Leong <boon.leong.ong@...el.com>,
linux-perf-users@...r.kernel.org,
open list <linux-kernel@...r.kernel.org>,
Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
llvm@...ts.linux.dev
Subject: Re: [PATCH bpf-next 11/11] samples: bpf: xdpsock: fix -Wmaybe-uninitialized
On Thu, Apr 14, 2022 at 3:47 PM Alexander Lobakin <alobakin@...me> wrote:
>
> 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: eb68db45b747 ("samples/bpf: xdpsock: Add timestamp for Tx-only operation")
> Signed-off-by: Alexander Lobakin <alobakin@...me>
Acked-by: Song Liu <songliubraving@...com>
> ---
> samples/bpf/xdpsock_user.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
> index 399b999fcec2..1dc7ad5dbef4 100644
> --- a/samples/bpf/xdpsock_user.c
> +++ b/samples/bpf/xdpsock_user.c
> @@ -1496,7 +1496,7 @@ static void rx_drop_all(void)
> static int tx_only(struct xsk_socket_info *xsk, u32 *frame_nb,
> int batch_size, unsigned long tx_ns)
> {
> - u32 idx, tv_sec, tv_usec;
> + u32 idx, tv_sec = 0, tv_usec = 0;
> unsigned int i;
>
> while (xsk_ring_prod__reserve(&xsk->tx, batch_size, &idx) <
> --
> 2.35.2
>
>
Powered by blists - more mailing lists