* [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c
@ 2019-03-01 6:19 Yonghong Song
2019-03-01 17:17 ` Jonathan Lemon
2019-03-02 0:11 ` Daniel Borkmann
0 siblings, 2 replies; 4+ messages in thread
From: Yonghong Song @ 2019-03-01 6:19 UTC (permalink / raw)
To: netdev; +Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team, Yonghong Song
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: 248c7f9c0e21 ("samples/bpf: convert xdpsock to use libbpf for AF_XDP access")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
samples/bpf/xdpsock_user.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index 9c76d6d43deb..d08ee1ab7bb4 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -446,7 +446,7 @@ static void kick_tx(struct xsk_socket_info *xsk)
static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk)
{
- u32 idx_cq, idx_fq;
+ u32 idx_cq = 0, idx_fq = 0;
unsigned int rcvd;
size_t ndescs;
@@ -503,7 +503,7 @@ static inline void complete_tx_only(struct xsk_socket_info *xsk)
static void rx_drop(struct xsk_socket_info *xsk)
{
unsigned int rcvd, i;
- u32 idx_rx, idx_fq = 0;
+ u32 idx_rx = 0, idx_fq = 0;
int ret;
rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx);
@@ -603,7 +603,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
{
for (;;) {
unsigned int rcvd, i;
- u32 idx_rx, idx_tx = 0;
+ u32 idx_rx = 0, idx_tx = 0;
int ret;
for (;;) {
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c
2019-03-01 6:19 [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c Yonghong Song
@ 2019-03-01 17:17 ` Jonathan Lemon
2019-03-01 23:10 ` Song Liu
2019-03-02 0:11 ` Daniel Borkmann
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Lemon @ 2019-03-01 17:17 UTC (permalink / raw)
To: Yonghong Song; +Cc: netdev, Alexei Starovoitov, Daniel Borkmann, kernel-team
On 28 Feb 2019, at 22:19, Yonghong Song wrote:
> 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: 248c7f9c0e21 ("samples/bpf: convert xdpsock to use libbpf for
> AF_XDP access")
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
> samples/bpf/xdpsock_user.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
> index 9c76d6d43deb..d08ee1ab7bb4 100644
> --- a/samples/bpf/xdpsock_user.c
> +++ b/samples/bpf/xdpsock_user.c
> @@ -446,7 +446,7 @@ static void kick_tx(struct xsk_socket_info *xsk)
>
> static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk)
> {
> - u32 idx_cq, idx_fq;
> + u32 idx_cq = 0, idx_fq = 0;
> unsigned int rcvd;
> size_t ndescs;
>
> @@ -503,7 +503,7 @@ static inline void complete_tx_only(struct
> xsk_socket_info *xsk)
> static void rx_drop(struct xsk_socket_info *xsk)
> {
> unsigned int rcvd, i;
> - u32 idx_rx, idx_fq = 0;
> + u32 idx_rx = 0, idx_fq = 0;
> int ret;
>
> rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx);
> @@ -603,7 +603,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
> {
> for (;;) {
> unsigned int rcvd, i;
> - u32 idx_rx, idx_tx = 0;
> + u32 idx_rx = 0, idx_tx = 0;
> int ret;
>
> for (;;) {
> --
> 2.17.1
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c
2019-03-01 17:17 ` Jonathan Lemon
@ 2019-03-01 23:10 ` Song Liu
0 siblings, 0 replies; 4+ messages in thread
From: Song Liu @ 2019-03-01 23:10 UTC (permalink / raw)
To: Jonathan Lemon
Cc: Yonghong Song, Networking, Alexei Starovoitov, Daniel Borkmann,
kernel-team
On Fri, Mar 1, 2019 at 11:10 AM Jonathan Lemon <jlemon@flugsvamp.com> wrote:
>
> On 28 Feb 2019, at 22:19, Yonghong Song wrote:
>
> > 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: 248c7f9c0e21 ("samples/bpf: convert xdpsock to use libbpf for
> > AF_XDP access")
> > Signed-off-by: Yonghong Song <yhs@fb.com>
> > ---
> > samples/bpf/xdpsock_user.c | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
> > index 9c76d6d43deb..d08ee1ab7bb4 100644
> > --- a/samples/bpf/xdpsock_user.c
> > +++ b/samples/bpf/xdpsock_user.c
> > @@ -446,7 +446,7 @@ static void kick_tx(struct xsk_socket_info *xsk)
> >
> > static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk)
> > {
> > - u32 idx_cq, idx_fq;
> > + u32 idx_cq = 0, idx_fq = 0;
> > unsigned int rcvd;
> > size_t ndescs;
> >
> > @@ -503,7 +503,7 @@ static inline void complete_tx_only(struct
> > xsk_socket_info *xsk)
> > static void rx_drop(struct xsk_socket_info *xsk)
> > {
> > unsigned int rcvd, i;
> > - u32 idx_rx, idx_fq = 0;
> > + u32 idx_rx = 0, idx_fq = 0;
> > int ret;
> >
> > rcvd = xsk_ring_cons__peek(&xsk->rx, BATCH_SIZE, &idx_rx);
> > @@ -603,7 +603,7 @@ static void l2fwd(struct xsk_socket_info *xsk)
> > {
> > for (;;) {
> > unsigned int rcvd, i;
> > - u32 idx_rx, idx_tx = 0;
> > + u32 idx_rx = 0, idx_tx = 0;
> > int ret;
> >
> > for (;;) {
> > --
> > 2.17.1
>
> Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Acked-by: Song Liu <songliubraving@fb.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c
2019-03-01 6:19 [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c Yonghong Song
2019-03-01 17:17 ` Jonathan Lemon
@ 2019-03-02 0:11 ` Daniel Borkmann
1 sibling, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2019-03-02 0:11 UTC (permalink / raw)
To: Yonghong Song, netdev; +Cc: Alexei Starovoitov, kernel-team
On 03/01/2019 07:19 AM, Yonghong Song wrote:
> 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: 248c7f9c0e21 ("samples/bpf: convert xdpsock to use libbpf for AF_XDP access")
> Signed-off-by: Yonghong Song <yhs@fb.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-03-02 0:11 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-01 6:19 [PATCH bpf-next] samples/bpf: silence compiler warning for xdpsock_user.c Yonghong Song
2019-03-01 17:17 ` Jonathan Lemon
2019-03-01 23:10 ` Song Liu
2019-03-02 0:11 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.