diff mbox series

[bpf-next,v3] selftests/bpf: replace fall through comment by fallthrough pseudo-keyword

Message ID 20230801094833.4146816-1-ruanjinjie@huawei.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next,v3] selftests/bpf: replace fall through comment by fallthrough pseudo-keyword | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/cc_maintainers warning 17 maintainers not CCed: awkrail01@gmail.com daniel@iogearbox.net kpsingh@kernel.org joannelkoong@gmail.com benjamin.tissoires@redhat.com john.fastabend@gmail.com sdf@google.com andrii@kernel.org yonghong.song@linux.dev martin.lau@linux.dev mykolal@fb.com shuah@kernel.org song@kernel.org jolsa@kernel.org haoluo@google.com ast@kernel.org rdunlap@infradead.org
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 47 lines checked
netdev/kdoc success Errors and warnings before: 4 this patch: 4
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }}
bpf/vmtest-bpf-next-VM_Test-2 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-5 fail Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 fail Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-8 success Logs for veristat

Commit Message

Jinjie Ruan Aug. 1, 2023, 9:48 a.m. UTC
Replace the existing /* fall through */ comments with the
new pseudo-keyword macro fallthrough[1].

[1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
---
v3:
- Update the subject prefix and fix the 'fallthrough' undeclared build error.
---
v2:
- Update the subject and commit message.
---
 tools/testing/selftests/bpf/prog_tests/kfunc_call.c          | 4 ++--
 tools/testing/selftests/bpf/progs/test_cls_redirect.c        | 2 +-
 tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c | 2 +-
 tools/testing/selftests/bpf/test_verifier.c                  | 3 ++-
 4 files changed, 6 insertions(+), 5 deletions(-)

Comments

Yonghong Song Aug. 1, 2023, 3:40 p.m. UTC | #1
On 8/1/23 2:48 AM, Ruan Jinjie wrote:
> Replace the existing /* fall through */ comments with the
> new pseudo-keyword macro fallthrough[1].
> 
> [1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through
> 
> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
> ---
> v3:
> - Update the subject prefix and fix the 'fallthrough' undeclared build error.
> ---
> v2:
> - Update the subject and commit message.
> ---
>   tools/testing/selftests/bpf/prog_tests/kfunc_call.c          | 4 ++--
>   tools/testing/selftests/bpf/progs/test_cls_redirect.c        | 2 +-
>   tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c | 2 +-
>   tools/testing/selftests/bpf/test_verifier.c                  | 3 ++-
>   4 files changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
> index a543742cd7bd..0fd08172965a 100644
> --- a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
> +++ b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
> @@ -101,7 +101,7 @@ static void verify_success(struct kfunc_test_params *param)
>   	case syscall_test:
>   		topts.ctx_in = &args;
>   		topts.ctx_size_in = sizeof(args);
> -		/* fallthrough */
> +		fallthrough;

This won't work for clang built kernel/selftests:

In file included from progs/test_cls_redirect_subprogs.c:2:
progs/test_cls_redirect.c:303:4: error: use of undeclared identifier 
'fallthrough'
   303 |                         fallthrough;
       |                         ^
   CLNG-BPF [test_maps] netns_cookie_prog.bpf.o
   CLNG-BPF [test_maps] test_skmsg_load_helpers.bpf.o
   CLNG-BPF [test_maps] bpf_iter_setsockopt.bpf.o
   CLNG-BPF [test_maps] timer.bpf.o
progs/test_cls_redirect.c:303:4: error: use of undeclared identifier 
'fallthrough'
   303 |                         fallthrough;
       |                         ^

Try to build the kernel with:
   make -j LLVM=1
   make headers_install

and then build the selftests with
   make -C tools/testing/selftests/bpf -j LLVM=1

[~/work/bpf-next/tools/include (master)]$ egrep -r fallthrough
egrep: warning: egrep is obsolescent; using grep -E
linux/compiler-gcc.h:#if __has_attribute(__fallthrough__)
linux/compiler-gcc.h:# define fallthrough 
__attribute__((__fallthrough__))
linux/compiler-gcc.h:# define fallthrough                    do {} while 
(0)  /* fallthrough */
[~/work/bpf-next/tools/include (master)]$

Looks like 'fallthrough' is not defined for clang build tools/selftests.

>   	case syscall_null_ctx_test:
>   		break;
>   	case tc_test:
> @@ -167,7 +167,7 @@ static void verify_fail(struct kfunc_test_params *param)
>   	case syscall_test:
>   		topts.ctx_in = &args;
>   		topts.ctx_size_in = sizeof(args);
> -		/* fallthrough */
> +		fallthrough;
>   	case syscall_null_ctx_test:
>   		break;
>   	case tc_test:
[...]
Jinjie Ruan Aug. 2, 2023, 1:30 a.m. UTC | #2
On 2023/8/1 23:40, Yonghong Song wrote:
> 
> 
> On 8/1/23 2:48 AM, Ruan Jinjie wrote:
>> Replace the existing /* fall through */ comments with the
>> new pseudo-keyword macro fallthrough[1].
>>
>> [1]
>> https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through
>>
>> Signed-off-by: Ruan Jinjie <ruanjinjie@huawei.com>
>> ---
>> v3:
>> - Update the subject prefix and fix the 'fallthrough' undeclared build
>> error.
>> ---
>> v2:
>> - Update the subject and commit message.
>> ---
>>   tools/testing/selftests/bpf/prog_tests/kfunc_call.c          | 4 ++--
>>   tools/testing/selftests/bpf/progs/test_cls_redirect.c        | 2 +-
>>   tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c | 2 +-
>>   tools/testing/selftests/bpf/test_verifier.c                  | 3 ++-
>>   4 files changed, 6 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
>> b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
>> index a543742cd7bd..0fd08172965a 100644
>> --- a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
>> +++ b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
>> @@ -101,7 +101,7 @@ static void verify_success(struct
>> kfunc_test_params *param)
>>       case syscall_test:
>>           topts.ctx_in = &args;
>>           topts.ctx_size_in = sizeof(args);
>> -        /* fallthrough */
>> +        fallthrough;
> 
> This won't work for clang built kernel/selftests:
> 
> In file included from progs/test_cls_redirect_subprogs.c:2:
> progs/test_cls_redirect.c:303:4: error: use of undeclared identifier
> 'fallthrough'
>   303 |                         fallthrough;
>       |                         ^
>   CLNG-BPF [test_maps] netns_cookie_prog.bpf.o
>   CLNG-BPF [test_maps] test_skmsg_load_helpers.bpf.o
>   CLNG-BPF [test_maps] bpf_iter_setsockopt.bpf.o
>   CLNG-BPF [test_maps] timer.bpf.o
> progs/test_cls_redirect.c:303:4: error: use of undeclared identifier
> 'fallthrough'
>   303 |                         fallthrough;
Thank you very much! I'll fix it in v4.

>       |                         ^
> 
> Try to build the kernel with:
>   make -j LLVM=1
>   make headers_install
> 
> and then build the selftests with
>   make -C tools/testing/selftests/bpf -j LLVM=1
> 
> [~/work/bpf-next/tools/include (master)]$ egrep -r fallthrough
> egrep: warning: egrep is obsolescent; using grep -E
> linux/compiler-gcc.h:#if __has_attribute(__fallthrough__)
> linux/compiler-gcc.h:# define fallthrough __attribute__((__fallthrough__))
> linux/compiler-gcc.h:# define fallthrough                    do {} while
> (0)  /* fallthrough */
> [~/work/bpf-next/tools/include (master)]$
> 
> Looks like 'fallthrough' is not defined for clang build tools/selftests.
> 
>>       case syscall_null_ctx_test:
>>           break;
>>       case tc_test:
>> @@ -167,7 +167,7 @@ static void verify_fail(struct kfunc_test_params
>> *param)
>>       case syscall_test:
>>           topts.ctx_in = &args;
>>           topts.ctx_size_in = sizeof(args);
>> -        /* fallthrough */
>> +        fallthrough;
>>       case syscall_null_ctx_test:
>>           break;
>>       case tc_test:
> [...]
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
index a543742cd7bd..0fd08172965a 100644
--- a/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
+++ b/tools/testing/selftests/bpf/prog_tests/kfunc_call.c
@@ -101,7 +101,7 @@  static void verify_success(struct kfunc_test_params *param)
 	case syscall_test:
 		topts.ctx_in = &args;
 		topts.ctx_size_in = sizeof(args);
-		/* fallthrough */
+		fallthrough;
 	case syscall_null_ctx_test:
 		break;
 	case tc_test:
@@ -167,7 +167,7 @@  static void verify_fail(struct kfunc_test_params *param)
 	case syscall_test:
 		topts.ctx_in = &args;
 		topts.ctx_size_in = sizeof(args);
-		/* fallthrough */
+		fallthrough;
 	case syscall_null_ctx_test:
 		break;
 	case tc_test:
diff --git a/tools/testing/selftests/bpf/progs/test_cls_redirect.c b/tools/testing/selftests/bpf/progs/test_cls_redirect.c
index 66b304982245..f97960759558 100644
--- a/tools/testing/selftests/bpf/progs/test_cls_redirect.c
+++ b/tools/testing/selftests/bpf/progs/test_cls_redirect.c
@@ -300,7 +300,7 @@  bool pkt_skip_ipv6_extension_headers(buf_t *pkt,
 		case IPPROTO_FRAGMENT:
 			*is_fragment = true;
 			/* NB: We don't check that hdrlen == 0 as per spec. */
-			/* fallthrough; */
+			fallthrough;
 
 		case IPPROTO_HOPOPTS:
 		case IPPROTO_ROUTING:
diff --git a/tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c b/tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c
index f41c81212ee9..54dbf307c692 100644
--- a/tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c
+++ b/tools/testing/selftests/bpf/progs/test_cls_redirect_dynptr.c
@@ -204,7 +204,7 @@  static bool pkt_skip_ipv6_extension_headers(struct bpf_dynptr *dynptr, __u64 *of
 		case IPPROTO_FRAGMENT:
 			*is_fragment = true;
 			/* NB: We don't check that hdrlen == 0 as per spec. */
-			/* fallthrough; */
+			fallthrough;
 
 		case IPPROTO_HOPOPTS:
 		case IPPROTO_ROUTING:
diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c
index 31f1c935cd07..8f2e3852c207 100644
--- a/tools/testing/selftests/bpf/test_verifier.c
+++ b/tools/testing/selftests/bpf/test_verifier.c
@@ -28,6 +28,7 @@ 
 #include <linux/bpf.h>
 #include <linux/if_ether.h>
 #include <linux/btf.h>
+#include <linux/compiler.h>
 
 #include <bpf/btf.h>
 #include <bpf/bpf.h>
@@ -1289,7 +1290,7 @@  static int do_prog_test_run(int fd_prog, bool unpriv, uint32_t expected_val,
 				printf("Did not run the program (no permission) ");
 				return 0;
 			}
-			/* fallthrough; */
+			fallthrough;
 		default:
 			printf("FAIL: Unexpected bpf_prog_test_run error (%s) ",
 				strerror(saved_errno));