OSDN Git Service

samples: bpf: Fix uninitialized variable in xdp_redirect_cpu
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Thu, 26 Aug 2021 12:09:10 +0000 (17:39 +0530)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 26 Aug 2021 19:09:20 +0000 (12:09 -0700)
While at it, also improve help output when CPU number is greater than
possible.

Fixes: e531a220cc59 ("samples: bpf: Convert xdp_redirect_cpu to XDP samples helper")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20210826120910.454081-1-memxor@gmail.com
samples/bpf/xdp_redirect_cpu_user.c

index 631700a..6e25fba 100644 (file)
@@ -141,7 +141,7 @@ static int create_cpu_entry(__u32 cpu, struct bpf_cpumap_val *value,
 static int mark_cpus_unavailable(void)
 {
        int ret, i, n_cpus = libbpf_num_possible_cpus();
-       __u32 invalid_cpu;
+       __u32 invalid_cpu = n_cpus;
 
        for (i = 0; i < n_cpus; i++) {
                ret = bpf_map_update_elem(avail_fd, &i,
@@ -449,8 +449,9 @@ int main(int argc, char **argv)
                        add_cpu = strtoul(optarg, NULL, 0);
                        if (add_cpu >= n_cpus) {
                                fprintf(stderr,
-                               "--cpu nr too large for cpumap err(%d):%s\n",
+                               "--cpu nr too large for cpumap err (%d):%s\n",
                                        errno, strerror(errno));
+                               usage(argv, long_options, __doc__, mask, true, skel->obj);
                                goto end_cpu;
                        }
                        cpu[added_cpus++] = add_cpu;