Skip to contentSkip to conversation

bpf: hide a possibly unused variable

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

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

PATCH 1/1 bpf: hide a possibly unused variable

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 adds the same #ifdef around the declaration.

Fixes b13d88072172 ("bpf: Adds field bpf_sock_ops_cb_flags to tcp_sock")
---
 net/core/filter.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/filter.c +2 -0
index 08ab4c65a998..c3dc6d60b4bb 100644
@@ -3379,7 +3379,9 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
 	   int, argval)
 {
 	struct sock *sk = bpf_sock->sk;
+#ifdef CONFIG_INET
 	int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;
+#endif
 
 	if (!sk_fullsock(sk))
 		return -EINVAL;
Signature · 1 line
2.9.0
maintainer
#1 lore raw

Hi Arnd,

Quoted 20 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;

This adds the same #ifdef around the declaration.

Fixes b13d88072172 ("bpf: Adds field bpf_sock_ops_cb_flags to tcp_sock")
---
 net/core/filter.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/filter.c +0 -0
index 08ab4c65a998..c3dc6d60b4bb 100644

net/core/filter.c BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock, · line 3384

Quoted 6 lines
net/core/filter.c +2 -0
@@ -3379,7 +3379,9 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
 	   int, argval)
 {
 	struct sock *sk = bpf_sock->sk;
+#ifdef CONFIG_INET
 	int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;
+#endif

Looks good, thanks for the fix!

Could you move the existing '#ifdef CONFIG_INET' to the beginning of the function given the only error in case of !CONFIG_INET is -EINVAL anyway? That would at least not increase the ifdef ugliness further.

Thanks a lot,
Daniel

Quoted 3 lines
net/core/filter.c +0 -0
 	if (!sk_fullsock(sk))
 		return -EINVAL;
 
#2 lore raw
Quoted 32 lines · Daniel Borkmann

Hi Arnd,

Quoted 20 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;

This adds the same #ifdef around the declaration.

Fixes b13d88072172 ("bpf: Adds field bpf_sock_ops_cb_flags to tcp_sock")
---
 net/core/filter.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/filter.c +0 -0
index 08ab4c65a998..c3dc6d60b4bb 100644

net/core/filter.c BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock, · line 3384

Quoted 6 lines
net/core/filter.c +2 -0
@@ -3379,7 +3379,9 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
         int, argval)
 {
      struct sock *sk = bpf_sock->sk;
+#ifdef CONFIG_INET
      int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;
+#endif

Looks good, thanks for the fix!

Quoted 3 lines

Could you move the existing '#ifdef CONFIG_INET' to the beginning of the function given the only error in case of !CONFIG_INET is -EINVAL anyway? That would at least not increase the ifdef ugliness further.

Sure, sent a new version now. I decided to clean up that #ifdef check as well, since a IS_ENABLED() check is nicer anway.

Arnd

maintainer
#3 lore raw
Quoted 33 lines · Arnd Bergmann
Quoted 32 lines · Daniel Borkmann

Hi Arnd,

Quoted 20 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;

This adds the same #ifdef around the declaration.

Fixes b13d88072172 ("bpf: Adds field bpf_sock_ops_cb_flags to tcp_sock")
---
 net/core/filter.c | 2 ++
 1 file changed, 2 insertions(+)
net/core/filter.c +0 -0
index 08ab4c65a998..c3dc6d60b4bb 100644

net/core/filter.c BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock, · line 3384

Quoted 6 lines
net/core/filter.c +2 -0
@@ -3379,7 +3379,9 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
         int, argval)
 {
      struct sock *sk = bpf_sock->sk;
+#ifdef CONFIG_INET
      int val = argval & BPF_SOCK_OPS_ALL_CB_FLAGS;
+#endif

Looks good, thanks for the fix!

Quoted 6 lines
Quoted 3 lines

Could you move the existing '#ifdef CONFIG_INET' to the beginning of the function given the only error in case of !CONFIG_INET is -EINVAL anyway? That would at least not increase the ifdef ugliness further.

Sure, sent a new version now. I decided to clean up that #ifdef check as well, since a IS_ENABLED() check is nicer anway.

Looks great, thanks! I'll get it into bpf once the pending pr got pulled.