Skip to content

Commit 066d885

Browse files
arndbKernel Patches Daemon
authored andcommitted
bpf: avoid warning for unused register_bpf_struct_ops()
The macro originally introduced in commit f6be98d ("bpf, net: switch to dynamic registration") causes a warning in the new smc code because of the way it evaluates the arguments: In file included from include/linux/bpf_verifier.h:7, from net/smc/smc_hs_bpf.c:13: net/smc/smc_hs_bpf.c: In function 'bpf_smc_hs_ctrl_init': include/linux/bpf.h:2076:50: error: statement with no effect [-Werror=unused-value] 2076 | #define register_bpf_struct_ops(st_ops, type) ({ (void *)(st_ops); 0; }) | ^~~~~~~~~~~~~~~~ net/smc/smc_hs_bpf.c:139:16: note: in expansion of macro 'register_bpf_struct_ops' 139 | return register_bpf_struct_ops(&bpf_smc_hs_ctrl_ops, smc_hs_ctrl); | ^~~~~~~~~~~~~~~~~~~~~~~ Work around this using an inline function that takes the argument, the same way as the normal implementation. Since the second argument to register_bpf_struct_ops() is a type rather than an object, this still has to be a macro, but it can call a new inline helper internally like the normal one does. Fixes: 15f295f ("net/smc: bpf: Introduce generic hook for handshake flow") Cc: Kui-Feng Lee <[email protected]> Cc: Martin KaFai Lau <[email protected]> Signed-off-by: Arnd Bergmann <[email protected]>
1 parent 03e2ed2 commit 066d885

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

include/linux/bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,7 @@ int bpf_struct_ops_desc_init(struct bpf_struct_ops_desc *st_ops_desc,
20652065
void bpf_map_struct_ops_info_fill(struct bpf_map_info *info, struct bpf_map *map);
20662066
void bpf_struct_ops_desc_release(struct bpf_struct_ops_desc *st_ops_desc);
20672067
#else
2068-
#define register_bpf_struct_ops(st_ops, type) ({ (void *)(st_ops); 0; })
2068+
#define register_bpf_struct_ops(st_ops, type) __register_bpf_struct_ops(st_ops)
20692069
static inline bool bpf_try_module_get(const void *data, struct module *owner)
20702070
{
20712071
return try_module_get(owner);

include/linux/btf.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops);
535535
const struct bpf_struct_ops_desc *bpf_struct_ops_find_value(struct btf *btf, u32 value_id);
536536
const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id);
537537
#else
538+
struct bpf_struct_ops;
539+
static inline int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops)
540+
{
541+
return 0;
542+
}
538543
static inline const struct bpf_struct_ops_desc *bpf_struct_ops_find(struct btf *btf, u32 type_id)
539544
{
540545
return NULL;

0 commit comments

Comments
 (0)