selftests/bpf: Fix check in global_data_init.
Subsystems (5)
PATCH 1/1 selftests/bpf: Fix check in global_data_init.
The returned value of bpf_object__open_file() should be checked with IS_ERR() rather than NULL. This fix makes test_progs not crash when test_global_data.o is not present.
--- tools/testing/selftests/bpf/prog_tests/global_data_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/global_data_init.c +1 -1
@@ -12,7 +12,7 @@ void test_global_data_init(void)size_t sz; obj =bpf_object__open_file (file,NULL ); -if (CHECK_FAIL (!obj)) +if (CHECK_FAIL (IS_ERR (obj)))return ; map =bpf_object__find_map_by_name (obj,"test_glo.rodata" );
Signature · 1 line
2.28.0.402.g5ffc5be6b7-goog
Quoted 15 lines · Hao Luo
The returned value of
bpf_object__open_file()should be checked withIS_ERR()rather than NULL. This fix makestest_progsnot crash when test_global_data.o is not present.Signed-off-by Hao Luo <[email protected]>--- tools/testing/selftests/bpf/prog_tests/global_data_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/global_data_init.c +0
-0
tools/testing/selftests/bpf/prog_tests/global_data_init.c void test_global_data_init(void) · line 15
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/global_data_init.c +1
-1@@ -12,7 +12,7 @@ void test_global_data_init(void)size_t sz; obj =bpf_object__open_file (file,NULL ); -if (CHECK_FAIL (!obj)) +if (CHECK_FAIL (IS_ERR (obj)))
Can you please use libbpf_get_error(obj) instead to set a good example or not relying on kernel internal macros?
Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/global_data_init.c +0
-1return ; map =bpf_object__find_map_by_name (obj,"test_glo.rodata" ); --2.28.0.402.g5ffc5be6b7-goog
No problem! Let me update and resend.
Quoted 32 lines · Andrii Nakryiko
Quoted 15 lines · Hao Luo
The returned value of
bpf_object__open_file()should be checked withIS_ERR()rather than NULL. This fix makestest_progsnot crash when test_global_data.o is not present.Signed-off-by Hao Luo <[email protected]>--- tools/testing/selftests/bpf/prog_tests/global_data_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/testing/selftests/bpf/prog_tests/global_data_init.c +0
-0tools/testing/selftests/bpf/prog_tests/global_data_init.c void test_global_data_init(void) · line 15
Quoted 5 lines
tools/testing/selftests/bpf/prog_tests/global_data_init.c +1
-1@@ -12,7 +12,7 @@ void test_global_data_init(void)size_t sz; obj =bpf_object__open_file (file,NULL ); -if (CHECK_FAIL (!obj)) +if (CHECK_FAIL (IS_ERR (obj)))Can you please use
libbpf_get_error(obj)instead to set a good example or not relying on kernel internal macros?Quoted 6 lines
tools/testing/selftests/bpf/prog_tests/global_data_init.c +0
-1return ; map =bpf_object__find_map_by_name (obj,"test_glo.rodata" ); --2.28.0.402.g5ffc5be6b7-goog