diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h index da7e230f2781e..a8f206f4fdb9c 100644 --- a/tools/testing/selftests/bpf/bpf_experimental.h +++ b/tools/testing/selftests/bpf/bpf_experimental.h @@ -8,6 +8,10 @@ #define __contains(name, node) __attribute__((btf_decl_tag("contains:" #name ":" #node))) +#ifndef __must_check +#define __must_check __attribute__((__warn_unused_result__)) +#endif + /* Description * Allocates an object of the type represented by 'local_type_id' in * program BTF. User may use the bpf_core_type_id_local macro to pass the @@ -20,7 +24,7 @@ * A pointer to an object of the type corresponding to the passed in * 'local_type_id', or NULL on failure. */ -extern void *bpf_obj_new_impl(__u64 local_type_id, void *meta) __ksym; +extern __must_check void *bpf_obj_new_impl(__u64 local_type_id, void *meta) __ksym; /* Convenience macro to wrap over bpf_obj_new_impl */ #define bpf_obj_new(type) ((type *)bpf_obj_new_impl(bpf_core_type_id_local(type), NULL)) diff --git a/tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h b/tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h index d67466c1ff775..f90531cf3ee59 100644 --- a/tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h +++ b/tools/testing/selftests/bpf/progs/bpf_arena_spin_lock.h @@ -302,7 +302,7 @@ int arena_spin_lock_slowpath(arena_spinlock_t __arena __arg_arena *lock, u32 val * barriers. */ if (val & _Q_LOCKED_MASK) - smp_cond_load_acquire_label(&lock->locked, !VAL, release_err); + (void)smp_cond_load_acquire_label(&lock->locked, !VAL, release_err); /* * take ownership and clear the pending bit. @@ -380,7 +380,7 @@ int arena_spin_lock_slowpath(arena_spinlock_t __arena __arg_arena *lock, u32 val /* Link @node into the waitqueue. */ WRITE_ONCE(prev->next, node); - arch_mcs_spin_lock_contended_label(&node->locked, release_node_err); + (void)arch_mcs_spin_lock_contended_label(&node->locked, release_node_err); /* * While waiting for the MCS lock, the next pointer may have diff --git a/tools/testing/selftests/bpf/progs/linked_list_fail.c b/tools/testing/selftests/bpf/progs/linked_list_fail.c index 6438982b928bd..1e30d103e1c72 100644 --- a/tools/testing/selftests/bpf/progs/linked_list_fail.c +++ b/tools/testing/selftests/bpf/progs/linked_list_fail.c @@ -212,22 +212,33 @@ int map_compat_raw_tp_w(void *ctx) SEC("?tc") int obj_type_id_oor(void *ctx) { - bpf_obj_new_impl(~0UL, NULL); + void *f; + + f = bpf_obj_new_impl(~0UL, NULL); + (void)f; + return 0; } SEC("?tc") int obj_new_no_composite(void *ctx) { - bpf_obj_new_impl(bpf_core_type_id_local(int), (void *)42); + void *f; + + f = bpf_obj_new_impl(bpf_core_type_id_local(int), (void *)42); + (void)f; + return 0; } SEC("?tc") int obj_new_no_struct(void *ctx) { + void *f; + + f = bpf_obj_new(union { int data; unsigned udata; }); + (void)f; - bpf_obj_new(union { int data; unsigned udata; }); return 0; } @@ -252,7 +263,11 @@ int new_null_ret(void *ctx) SEC("?tc") int obj_new_acq(void *ctx) { - bpf_obj_new(struct foo); + void *f; + + f = bpf_obj_new(struct foo); + (void)f; + return 0; }