mirror of
https://github.com/armbian/linux-cix.git
synced 2026-01-06 12:30:45 -08:00
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>
This commit is contained in:
committed by
Alexei Starovoitov
parent
713461b895
commit
c8ed668593
@@ -33,7 +33,6 @@ int dump_ksym(struct bpf_iter__ksym *ctx)
|
||||
__u32 seq_num = ctx->meta->seq_num;
|
||||
unsigned long value;
|
||||
char type;
|
||||
int ret;
|
||||
|
||||
if (!iter)
|
||||
return 0;
|
||||
|
||||
@@ -42,7 +42,6 @@ int change_tcp_cc(struct bpf_iter__tcp *ctx)
|
||||
char cur_cc[TCP_CA_NAME_MAX];
|
||||
struct tcp_sock *tp;
|
||||
struct sock *sk;
|
||||
int ret;
|
||||
|
||||
if (!bpf_tcp_sk(ctx->sk_common))
|
||||
return 0;
|
||||
|
||||
@@ -138,8 +138,6 @@ static int callback_set_0f(int i, void *ctx)
|
||||
SEC("fentry/" SYS_PREFIX "sys_nanosleep")
|
||||
int prog_non_constant_callback(void *ctx)
|
||||
{
|
||||
struct callback_ctx data = {};
|
||||
|
||||
if (bpf_get_current_pid_tgid() >> 32 != pid)
|
||||
return 0;
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@ int leak_prog(void *ctx)
|
||||
{
|
||||
struct prog_test_ref_kfunc *p;
|
||||
struct map_value *v;
|
||||
unsigned long sl;
|
||||
|
||||
v = bpf_map_lookup_elem(&array_map, &(int){0});
|
||||
if (!v)
|
||||
|
||||
@@ -66,7 +66,6 @@ static inline int is_allowed_peer_cg(struct __sk_buff *skb,
|
||||
SEC("cgroup_skb/ingress")
|
||||
int ingress_lookup(struct __sk_buff *skb)
|
||||
{
|
||||
__u32 serv_port_key = 0;
|
||||
struct ipv6hdr ip6h;
|
||||
struct tcphdr tcph;
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ int BPF_PROG(cgrp_kfunc_acquire_unreleased, struct cgroup *cgrp, const char *pat
|
||||
acquired = bpf_cgroup_acquire(cgrp);
|
||||
|
||||
/* Acquired cgroup is never released. */
|
||||
__sink(acquired);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,6 @@ int BPF_PROG(update_cookie_tracing, struct socket *sock,
|
||||
struct sockaddr *uaddr, int addr_len, int flags)
|
||||
{
|
||||
struct socket_cookie *p;
|
||||
struct tcp_sock *tcp_sk;
|
||||
|
||||
if (uaddr->sa_family != AF_INET6)
|
||||
return 0;
|
||||
|
||||
@@ -24,7 +24,6 @@ void bpf_rcu_read_unlock(void) __ksym;
|
||||
SEC("?iter.s/cgroup")
|
||||
int cgroup_iter(struct bpf_iter__cgroup *ctx)
|
||||
{
|
||||
struct seq_file *seq = ctx->meta->seq;
|
||||
struct cgroup *cgrp = ctx->cgroup;
|
||||
long *ptr;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ int balancer_ingress(struct __sk_buff *ctx)
|
||||
void *data_end = (void *)(long)ctx->data_end;
|
||||
void *data = (void *)(long)ctx->data;
|
||||
void *ptr;
|
||||
int ret = 0, nh_off, i = 0;
|
||||
int nh_off, i = 0;
|
||||
|
||||
nh_off = 14;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ int BPF_PROG(test_alloc_no_release, struct task_struct *task, u64 clone_flags)
|
||||
struct bpf_cpumask *cpumask;
|
||||
|
||||
cpumask = create_cpumask();
|
||||
__sink(cpumask);
|
||||
|
||||
/* cpumask is never released. */
|
||||
return 0;
|
||||
@@ -51,6 +52,7 @@ int BPF_PROG(test_acquire_wrong_cpumask, struct task_struct *task, u64 clone_fla
|
||||
|
||||
/* Can't acquire a non-struct bpf_cpumask. */
|
||||
cpumask = bpf_cpumask_acquire((struct bpf_cpumask *)task->cpus_ptr);
|
||||
__sink(cpumask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -63,6 +65,7 @@ int BPF_PROG(test_mutate_cpumask, struct task_struct *task, u64 clone_flags)
|
||||
|
||||
/* Can't set the CPU of a non-struct bpf_cpumask. */
|
||||
bpf_cpumask_set_cpu(0, (struct bpf_cpumask *)task->cpus_ptr);
|
||||
__sink(cpumask);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -353,7 +353,6 @@ SEC("tp_btf/task_newtask")
|
||||
int BPF_PROG(test_insert_leave, struct task_struct *task, u64 clone_flags)
|
||||
{
|
||||
struct bpf_cpumask *cpumask;
|
||||
struct __cpumask_map_value *v;
|
||||
|
||||
cpumask = create_cpumask();
|
||||
if (!cpumask)
|
||||
|
||||
@@ -271,7 +271,7 @@ SEC("?raw_tp")
|
||||
__failure __msg("value is outside of the allowed memory range")
|
||||
int data_slice_out_of_bounds_map_value(void *ctx)
|
||||
{
|
||||
__u32 key = 0, map_val;
|
||||
__u32 map_val;
|
||||
struct bpf_dynptr ptr;
|
||||
void *data;
|
||||
|
||||
@@ -388,7 +388,6 @@ int data_slice_missing_null_check2(void *ctx)
|
||||
/* this should fail */
|
||||
*data2 = 3;
|
||||
|
||||
done:
|
||||
bpf_ringbuf_discard_dynptr(&ptr, 0);
|
||||
return 0;
|
||||
}
|
||||
@@ -440,6 +439,7 @@ int invalid_write1(void *ctx)
|
||||
|
||||
/* this should fail */
|
||||
data = bpf_dynptr_data(&ptr, 0, 1);
|
||||
__sink(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1374,6 +1374,7 @@ int invalid_slice_rdwr_rdonly(struct __sk_buff *skb)
|
||||
* changing packet data
|
||||
*/
|
||||
hdr = bpf_dynptr_slice_rdwr(&ptr, 0, buffer, sizeof(buffer));
|
||||
__sink(hdr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ SEC("?tp/syscalls/sys_enter_nanosleep")
|
||||
int test_read_write(void *ctx)
|
||||
{
|
||||
char write_data[64] = "hello there, world!!";
|
||||
char read_data[64] = {}, buf[64] = {};
|
||||
char read_data[64] = {};
|
||||
struct bpf_dynptr ptr;
|
||||
int i;
|
||||
|
||||
@@ -170,7 +170,6 @@ int test_skb_readonly(struct __sk_buff *skb)
|
||||
{
|
||||
__u8 write_data[2] = {1, 2};
|
||||
struct bpf_dynptr ptr;
|
||||
__u64 *data;
|
||||
int ret;
|
||||
|
||||
if (bpf_dynptr_from_skb(skb, 0, &ptr)) {
|
||||
@@ -191,10 +190,8 @@ int test_skb_readonly(struct __sk_buff *skb)
|
||||
SEC("?cgroup_skb/egress")
|
||||
int test_dynptr_skb_data(struct __sk_buff *skb)
|
||||
{
|
||||
__u8 write_data[2] = {1, 2};
|
||||
struct bpf_dynptr ptr;
|
||||
__u64 *data;
|
||||
int ret;
|
||||
|
||||
if (bpf_dynptr_from_skb(skb, 0, &ptr)) {
|
||||
err = 1;
|
||||
|
||||
@@ -120,8 +120,6 @@ int new_get_skb_ifindex(int val, struct __sk_buff *skb, int var)
|
||||
void *data = (void *)(long)skb->data;
|
||||
struct ipv6hdr ip6, *ip6p;
|
||||
int ifindex = skb->ifindex;
|
||||
__u32 eth_proto;
|
||||
__u32 nh_off;
|
||||
|
||||
/* check that BPF extension can read packet via direct packet access */
|
||||
if (data + 14 + sizeof(ip6) > data_end)
|
||||
|
||||
@@ -23,7 +23,7 @@ struct {
|
||||
SEC("freplace/handle_kprobe")
|
||||
int new_handle_kprobe(struct pt_regs *ctx)
|
||||
{
|
||||
struct hmap_elem zero = {}, *val;
|
||||
struct hmap_elem *val;
|
||||
int key = 0;
|
||||
|
||||
val = bpf_map_lookup_elem(&hash_map, &key);
|
||||
|
||||
@@ -45,7 +45,6 @@ __failure __msg("unbounded memory access")
|
||||
int iter_err_unsafe_asm_loop(const void *ctx)
|
||||
{
|
||||
struct bpf_iter_num it;
|
||||
int *v, i = 0;
|
||||
|
||||
MY_PID_GUARD();
|
||||
|
||||
@@ -88,7 +87,7 @@ __success
|
||||
int iter_while_loop(const void *ctx)
|
||||
{
|
||||
struct bpf_iter_num it;
|
||||
int *v, i;
|
||||
int *v;
|
||||
|
||||
MY_PID_GUARD();
|
||||
|
||||
@@ -106,7 +105,7 @@ __success
|
||||
int iter_while_loop_auto_cleanup(const void *ctx)
|
||||
{
|
||||
__attribute__((cleanup(bpf_iter_num_destroy))) struct bpf_iter_num it;
|
||||
int *v, i;
|
||||
int *v;
|
||||
|
||||
MY_PID_GUARD();
|
||||
|
||||
@@ -124,7 +123,7 @@ __success
|
||||
int iter_for_loop(const void *ctx)
|
||||
{
|
||||
struct bpf_iter_num it;
|
||||
int *v, i;
|
||||
int *v;
|
||||
|
||||
MY_PID_GUARD();
|
||||
|
||||
@@ -192,7 +191,7 @@ __success
|
||||
int iter_manual_unroll_loop(const void *ctx)
|
||||
{
|
||||
struct bpf_iter_num it;
|
||||
int *v, i;
|
||||
int *v;
|
||||
|
||||
MY_PID_GUARD();
|
||||
|
||||
@@ -621,7 +620,7 @@ __success
|
||||
int iter_stack_array_loop(const void *ctx)
|
||||
{
|
||||
long arr1[16], arr2[16], sum = 0;
|
||||
int *v, i;
|
||||
int i;
|
||||
|
||||
MY_PID_GUARD();
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
#include "bpf_misc.h"
|
||||
|
||||
/* weak and shared between two files */
|
||||
const volatile int my_tid __weak;
|
||||
@@ -51,6 +52,7 @@ __weak int set_output_weak(int x)
|
||||
* cause problems for BPF static linker
|
||||
*/
|
||||
whatever = bpf_core_type_size(struct task_struct);
|
||||
__sink(whatever);
|
||||
|
||||
output_weak1 = x;
|
||||
return x;
|
||||
@@ -71,6 +73,7 @@ int BPF_PROG(handler1, struct pt_regs *regs, long id)
|
||||
|
||||
/* make sure we have CO-RE relocations in main program */
|
||||
whatever = bpf_core_type_size(struct task_struct);
|
||||
__sink(whatever);
|
||||
|
||||
set_output_val2(1000);
|
||||
set_output_ctx2(ctx); /* ctx definition is hidden in BPF_PROG macro */
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/bpf_tracing.h>
|
||||
#include <bpf/bpf_core_read.h>
|
||||
#include "bpf_misc.h"
|
||||
|
||||
/* weak and shared between both files */
|
||||
const volatile int my_tid __weak;
|
||||
@@ -51,6 +52,7 @@ __weak int set_output_weak(int x)
|
||||
* cause problems for BPF static linker
|
||||
*/
|
||||
whatever = 2 * bpf_core_type_size(struct task_struct);
|
||||
__sink(whatever);
|
||||
|
||||
output_weak2 = x;
|
||||
return 2 * x;
|
||||
@@ -71,6 +73,7 @@ int BPF_PROG(handler2, struct pt_regs *regs, long id)
|
||||
|
||||
/* make sure we have CO-RE relocations in main program */
|
||||
whatever = bpf_core_type_size(struct task_struct);
|
||||
__sink(whatever);
|
||||
|
||||
set_output_val1(2000);
|
||||
set_output_ctx1(ctx); /* ctx definition is hidden in BPF_PROG macro */
|
||||
|
||||
@@ -313,7 +313,6 @@ SEC("tc")
|
||||
int map_list_push_pop_multiple(void *ctx)
|
||||
{
|
||||
struct map_value *v;
|
||||
int ret;
|
||||
|
||||
v = bpf_map_lookup_elem(&array_map, &(int){0});
|
||||
if (!v)
|
||||
@@ -326,7 +325,6 @@ int inner_map_list_push_pop_multiple(void *ctx)
|
||||
{
|
||||
struct map_value *v;
|
||||
void *map;
|
||||
int ret;
|
||||
|
||||
map = bpf_map_lookup_elem(&map_of_maps, &(int){0});
|
||||
if (!map)
|
||||
@@ -352,7 +350,6 @@ SEC("tc")
|
||||
int map_list_in_list(void *ctx)
|
||||
{
|
||||
struct map_value *v;
|
||||
int ret;
|
||||
|
||||
v = bpf_map_lookup_elem(&array_map, &(int){0});
|
||||
if (!v)
|
||||
@@ -365,7 +362,6 @@ int inner_map_list_in_list(void *ctx)
|
||||
{
|
||||
struct map_value *v;
|
||||
void *map;
|
||||
int ret;
|
||||
|
||||
map = bpf_map_lookup_elem(&map_of_maps, &(int){0});
|
||||
if (!map)
|
||||
|
||||
@@ -557,7 +557,6 @@ SEC("?tc")
|
||||
int incorrect_head_off2(void *ctx)
|
||||
{
|
||||
struct foo *f;
|
||||
struct bar *b;
|
||||
|
||||
f = bpf_obj_new(typeof(*f));
|
||||
if (!f)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user