Skip to contentSkip to conversation

selftests/bpf: Fix check in global_data_init.

PATCH Applied Hao Luo 3 participants 3 messages Sep 3, 2020 – Sep 4, 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 libbpf_get_error() rather than NULL. This fix prevents test_progs from crash when test_global_data.o is not present.

---
 tools/testing/selftests/bpf/prog_tests/global_data_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/global_data_init.c +2 -1
index 3bdaa5a40744..ee46b11f1f9a 100644
@@ -12,7 +12,8 @@ void test_global_data_init(void)
 	size_t sz;
 
 	obj = bpf_object__open_file(file, NULL);
-	if (CHECK_FAIL(!obj))
+	err = libbpf_get_error(obj);
+	if (CHECK_FAIL(err))
 		return;
 
 	map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
Signature · 1 line
2.28.0.526.ge36021eeef-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Hao Luo

The returned value of bpf_object__open_file() should be checked with libbpf_get_error() rather than NULL. This fix prevents test_progs from crash when test_global_data.o is not present.

---

thanks!

Quoted 20 lines
 tools/testing/selftests/bpf/prog_tests/global_data_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/global_data_init.c +2 -2
index 3bdaa5a40744..ee46b11f1f9a 100644
@@ -12,7 +12,8 @@ void test_global_data_init(void)
        size_t sz;
 
        obj = bpf_object__open_file(file, NULL);
-       if (CHECK_FAIL(!obj))
+       err = libbpf_get_error(obj);
+       if (CHECK_FAIL(err))
                return;
 
        map = bpf_object__find_map_by_name(obj, "test_glo.rodata");
--

2.28.0.526.ge36021eeef-goog