libbpf: Initialize *nl_pid so gcc 10 is happy
authorJeremy Cline <jcline@redhat.com>
Sat, 4 Apr 2020 05:14:30 +0000 (01:14 -0400)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 6 Apr 2020 19:51:54 +0000 (21:51 +0200)
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 <jcline@redhat.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200404051430.698058-1-jcline@redhat.com
tools/lib/bpf/netlink.c

index 18b5319..9a14694 100644 (file)
@@ -142,7 +142,7 @@ static int __bpf_set_link_xdp_fd_replace(int ifindex, int fd, int old_fd,
                struct ifinfomsg ifinfo;
                char             attrbuf[64];
        } req;
-       __u32 nl_pid;
+       __u32 nl_pid = 0;
 
        sock = libbpf_netlink_open(&nl_pid);
        if (sock < 0)
@@ -288,7 +288,7 @@ int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
 {
        struct xdp_id_md xdp_id = {};
        int sock, ret;
-       __u32 nl_pid;
+       __u32 nl_pid = 0;
        __u32 mask;
 
        if (flags & ~XDP_FLAGS_MASK || !info_size)