Skip to contentSkip to conversation

selftests/bpf: Fix check in global_data_init.

PATCH In review Hao Luo 2 participants 3 messages Sep 3, 2020

Subsystems (5)
lore
Share & tools
lore

Hao Luo

author
#0 lore raw

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
index 3bdaa5a40744..1ece86d5c519 100644
@@ -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
#1 lore raw
Quoted 15 lines · Hao Luo

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 +0 -0
index 3bdaa5a40744..1ece86d5c519 100644

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 -1
                return;
 
        map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
--

2.28.0.402.g5ffc5be6b7-goog

author
#2 lore raw

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 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 +0 -0
index 3bdaa5a40744..1ece86d5c519 100644

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 -1
                return;
 
        map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
--

2.28.0.402.g5ffc5be6b7-goog