diff mbox series

[bpf-next] bpf: verifier: avoid fall-through warnings

Message ID 20190711162233.GA6977@embeddedor
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] bpf: verifier: avoid fall-through warnings | expand

Commit Message

Gustavo A. R. Silva July 11, 2019, 4:22 p.m. UTC
In preparation to enabling -Wimplicit-fallthrough, this patch silences
the following warning:

kernel/bpf/verifier.c: In function ‘check_return_code’:
kernel/bpf/verifier.c:6106:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
   if (env->prog->expected_attach_type == BPF_CGROUP_UDP4_RECVMSG ||
      ^
kernel/bpf/verifier.c:6109:2: note: here
  case BPF_PROG_TYPE_CGROUP_SKB:
  ^~~~

Warning level 3 was used: -Wimplicit-fallthrough=3

Notice that is much clearer to explicitly add breaks in each case
statement (that actually contains some code), rather than letting
the code to fall through.

This patch is part of the ongoing efforts to enable
-Wimplicit-fallthrough.

Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---

NOTE: -Wimplicit-fallthrough will be enabled globally in v5.3. So, I
      suggest you to take this patch for 5.3-rc1.

 kernel/bpf/verifier.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Daniel Borkmann July 12, 2019, 1:41 p.m. UTC | #1
On 07/11/2019 06:22 PM, Gustavo A. R. Silva wrote:
> In preparation to enabling -Wimplicit-fallthrough, this patch silences
> the following warning:
> 
> kernel/bpf/verifier.c: In function ‘check_return_code’:
> kernel/bpf/verifier.c:6106:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
>    if (env->prog->expected_attach_type == BPF_CGROUP_UDP4_RECVMSG ||
>       ^
> kernel/bpf/verifier.c:6109:2: note: here
>   case BPF_PROG_TYPE_CGROUP_SKB:
>   ^~~~
> 
> Warning level 3 was used: -Wimplicit-fallthrough=3
> 
> Notice that is much clearer to explicitly add breaks in each case
> statement (that actually contains some code), rather than letting
> the code to fall through.
> 
> This patch is part of the ongoing efforts to enable
> -Wimplicit-fallthrough.
> 
> Acked-by: Andrii Nakryiko <andriin@fb.com>
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>

Looks good, applied to bpf, thanks.
Gustavo A. R. Silva July 12, 2019, 7:44 p.m. UTC | #2
On 7/12/19 8:41 AM, Daniel Borkmann wrote:

>>
>> This patch is part of the ongoing efforts to enable
>> -Wimplicit-fallthrough.
>>
>> Acked-by: Andrii Nakryiko <andriin@fb.com>
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> 
> Looks good, applied to bpf, thanks.
> 

Awesome. :)

Thanks, Daniel.
--
Gustavo
diff mbox series

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index a2e763703c30..44c3b947400e 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -6106,11 +6106,13 @@  static int check_return_code(struct bpf_verifier_env *env)
 		if (env->prog->expected_attach_type == BPF_CGROUP_UDP4_RECVMSG ||
 		    env->prog->expected_attach_type == BPF_CGROUP_UDP6_RECVMSG)
 			range = tnum_range(1, 1);
+		break;
 	case BPF_PROG_TYPE_CGROUP_SKB:
 		if (env->prog->expected_attach_type == BPF_CGROUP_INET_EGRESS) {
 			range = tnum_range(0, 3);
 			enforce_attach_type_range = tnum_range(2, 3);
 		}
+		break;
 	case BPF_PROG_TYPE_CGROUP_SOCK:
 	case BPF_PROG_TYPE_SOCK_OPS:
 	case BPF_PROG_TYPE_CGROUP_DEVICE: