Skip to content

Commit c8ed668

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
selftests/bpf: fix lots of silly mistakes pointed out by compiler
Once we enable -Wall for BPF sources, compiler will complain about lots of unused variables, variables that are set but never read, etc. Fix all these issues first before enabling -Wall in Makefile. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/r/20230309054015.4068562-4-andrii@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 713461b commit c8ed668

File tree

81 files changed

+90
-187
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+90
-187
lines changed

tools/testing/selftests/bpf/progs/bpf_iter_ksym.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ int dump_ksym(struct bpf_iter__ksym *ctx)
3333
__u32 seq_num = ctx->meta->seq_num;
3434
unsigned long value;
3535
char type;
36-
int ret;
3736

3837
if (!iter)
3938
return 0;

tools/testing/selftests/bpf/progs/bpf_iter_setsockopt.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ int change_tcp_cc(struct bpf_iter__tcp *ctx)
4242
char cur_cc[TCP_CA_NAME_MAX];
4343
struct tcp_sock *tp;
4444
struct sock *sk;
45-
int ret;
4645

4746
if (!bpf_tcp_sk(ctx->sk_common))
4847
return 0;

tools/testing/selftests/bpf/progs/bpf_loop.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ static int callback_set_0f(int i, void *ctx)
138138
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
139139
int prog_non_constant_callback(void *ctx)
140140
{
141-
struct callback_ctx data = {};
142-
143141
if (bpf_get_current_pid_tgid() >> 32 != pid)
144142
return 0;
145143

tools/testing/selftests/bpf/progs/cb_refs.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ int leak_prog(void *ctx)
5252
{
5353
struct prog_test_ref_kfunc *p;
5454
struct map_value *v;
55-
unsigned long sl;
5655

5756
v = bpf_map_lookup_elem(&array_map, &(int){0});
5857
if (!v)

tools/testing/selftests/bpf/progs/cgroup_skb_sk_lookup_kern.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ static inline int is_allowed_peer_cg(struct __sk_buff *skb,
6666
SEC("cgroup_skb/ingress")
6767
int ingress_lookup(struct __sk_buff *skb)
6868
{
69-
__u32 serv_port_key = 0;
7069
struct ipv6hdr ip6h;
7170
struct tcphdr tcph;
7271

tools/testing/selftests/bpf/progs/cgrp_kfunc_failure.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ int BPF_PROG(cgrp_kfunc_acquire_unreleased, struct cgroup *cgrp, const char *pat
109109
acquired = bpf_cgroup_acquire(cgrp);
110110

111111
/* Acquired cgroup is never released. */
112+
__sink(acquired);
112113

113114
return 0;
114115
}

tools/testing/selftests/bpf/progs/cgrp_ls_attach_cgroup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ int BPF_PROG(update_cookie_tracing, struct socket *sock,
8484
struct sockaddr *uaddr, int addr_len, int flags)
8585
{
8686
struct socket_cookie *p;
87-
struct tcp_sock *tcp_sk;
8887

8988
if (uaddr->sa_family != AF_INET6)
9089
return 0;

tools/testing/selftests/bpf/progs/cgrp_ls_sleepable.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void bpf_rcu_read_unlock(void) __ksym;
2424
SEC("?iter.s/cgroup")
2525
int cgroup_iter(struct bpf_iter__cgroup *ctx)
2626
{
27-
struct seq_file *seq = ctx->meta->seq;
2827
struct cgroup *cgrp = ctx->cgroup;
2928
long *ptr;
3029

tools/testing/selftests/bpf/progs/core_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ int balancer_ingress(struct __sk_buff *ctx)
7777
void *data_end = (void *)(long)ctx->data_end;
7878
void *data = (void *)(long)ctx->data;
7979
void *ptr;
80-
int ret = 0, nh_off, i = 0;
80+
int nh_off, i = 0;
8181

8282
nh_off = 14;
8383

tools/testing/selftests/bpf/progs/cpumask_failure.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int BPF_PROG(test_alloc_no_release, struct task_struct *task, u64 clone_flags)
2323
struct bpf_cpumask *cpumask;
2424

2525
cpumask = create_cpumask();
26+
__sink(cpumask);
2627

2728
/* cpumask is never released. */
2829
return 0;
@@ -51,6 +52,7 @@ int BPF_PROG(test_acquire_wrong_cpumask, struct task_struct *task, u64 clone_fla
5152

5253
/* Can't acquire a non-struct bpf_cpumask. */
5354
cpumask = bpf_cpumask_acquire((struct bpf_cpumask *)task->cpus_ptr);
55+
__sink(cpumask);
5456

5557
return 0;
5658
}
@@ -63,6 +65,7 @@ int BPF_PROG(test_mutate_cpumask, struct task_struct *task, u64 clone_flags)
6365

6466
/* Can't set the CPU of a non-struct bpf_cpumask. */
6567
bpf_cpumask_set_cpu(0, (struct bpf_cpumask *)task->cpus_ptr);
68+
__sink(cpumask);
6669

6770
return 0;
6871
}

0 commit comments

Comments
 (0)