Skip to contentSkip to conversation

bpf: clean up unused-variable warning

PATCH In review Arnd Bergmann 2 participants 2 messages Feb 20, 2018 – Feb 22, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: clean up unused-variable warning

The only user of this variable is inside of an #ifdef, causing a warning without CONFIG_INET:

net/core/filter.c: In function '____bpf_sock_ops_cb_flags_set':
net/core/filter.c:3382:6: error: unused variable 'val' [-Werror=unused-variable]
int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;

This replaces the #ifdef with a nicer IS_ENABLED() check that makes the code more readable and avoids the warning.

Fixes b13d88072172 ("bpf: Adds field bpf_sock_ops_cb_flags to tcp_sock")
---
 net/core/filter.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
net/core/filter.c +1 -5
index 08ab4c65a998..0c121adbdbaa 100644
@@ -3381,17 +3381,13 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
 	struct sock *sk = bpf_sock->sk;
 	int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;
 
-	if (!sk_fullsock(sk))
+	if (!IS_ENABLED(CONFIG_INET) || !sk_fullsock(sk))
 		return -EINVAL;
 
-#ifdef CONFIG_INET
 	if (val)
 		tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
 
 	return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS);
-#else
-	return -EINVAL;
-#endif
 }
 
 static const struct bpf_func_proto bpf_sock_ops_cb_flags_set_proto = {
Signature · 1 line
2.9.0
maintainer
#1 lore raw
Quoted 7 lines · Arnd Bergmann

The only user of this variable is inside of an #ifdef, causing a warning without CONFIG_INET:

net/core/filter.c: In function '____bpf_sock_ops_cb_flags_set':
net/core/filter.c:3382:6: error: unused variable 'val' [-Werror=unused-variable]
int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;

Quoted 5 lines

This replaces the #ifdef with a nicer IS_ENABLED() check that makes the code more readable and avoids the warning.

Fixes b13d88072172 ("bpf: Adds field bpf_sock_ops_cb_flags to tcp_sock")

Now applied to bpf, thanks Arnd!