Skip to content

Commit

Permalink
libbpf: Initialize *nl_pid so gcc 10 is happy
Browse files Browse the repository at this point in the history
[ Upstream commit 4734b0f ]

Builds of Fedora's kernel-tools package started to fail with "may be
used uninitialized" warnings for nl_pid in bpf_set_link_xdp_fd() and
bpf_get_link_xdp_info() on the s390 architecture.

Although libbpf_netlink_open() always returns a negative number when it
does not set *nl_pid, the compiler does not determine this and thus
believes the variable might be used uninitialized. Assuage gcc's fears
by explicitly initializing nl_pid.

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1807781

Signed-off-by: Jeremy Cline <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
jeremycline authored and gregkh committed May 2, 2020
1 parent 3c9bbe7 commit 316ad98
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/lib/bpf/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
struct ifinfomsg ifinfo;
char attrbuf[64];
} req;
__u32 nl_pid;
__u32 nl_pid = 0;

sock = libbpf_netlink_open(&nl_pid);
if (sock < 0)
Expand Down Expand Up @@ -254,7 +254,7 @@ int bpf_get_link_xdp_id(int ifindex, __u32 *prog_id, __u32 flags)
{
struct xdp_id_md xdp_id = {};
int sock, ret;
__u32 nl_pid;
__u32 nl_pid = 0;
__u32 mask;

if (flags & ~XDP_FLAGS_MASK)
Expand Down

0 comments on commit 316ad98

Please sign in to comment.