Skip to content

Commit 7a36a28

Browse files
YueHaibingacmel
authored andcommitted
perf bpf: Fix NULL return handling in bpf__prepare_load()
bpf_object__open()/bpf_object__open_buffer can return error pointer or NULL, check the return values with IS_ERR_OR_NULL() in bpf__prepare_load and bpf__prepare_load_buffer Signed-off-by: YueHaibing <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 3cdc5c2 commit 7a36a28

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

tools/perf/util/bpf-loader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name)
6666
}
6767

6868
obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name);
69-
if (IS_ERR(obj)) {
69+
if (IS_ERR_OR_NULL(obj)) {
7070
pr_debug("bpf: failed to load buffer\n");
7171
return ERR_PTR(-EINVAL);
7272
}
@@ -102,14 +102,14 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
102102
pr_debug("bpf: successfull builtin compilation\n");
103103
obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename);
104104

105-
if (!IS_ERR(obj) && llvm_param.dump_obj)
105+
if (!IS_ERR_OR_NULL(obj) && llvm_param.dump_obj)
106106
llvm__dump_obj(filename, obj_buf, obj_buf_sz);
107107

108108
free(obj_buf);
109109
} else
110110
obj = bpf_object__open(filename);
111111

112-
if (IS_ERR(obj)) {
112+
if (IS_ERR_OR_NULL(obj)) {
113113
pr_debug("bpf: failed to load %s\n", filename);
114114
return obj;
115115
}

0 commit comments

Comments
 (0)