Commit 7a36a287 authored by YueHaibing's avatar YueHaibing Committed by Arnaldo Carvalho de Melo

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: default avatarYueHaibing <yuehaibing@huawei.com>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: netdev@vger.kernel.org
Link: https://lkml.kernel.org/n/tip-psf4xwc09n62al2cb9s33v9h@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3cdc5c2c
...@@ -66,7 +66,7 @@ bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name) ...@@ -66,7 +66,7 @@ bpf__prepare_load_buffer(void *obj_buf, size_t obj_buf_sz, const char *name)
} }
obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name); obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, name);
if (IS_ERR(obj)) { if (IS_ERR_OR_NULL(obj)) {
pr_debug("bpf: failed to load buffer\n"); pr_debug("bpf: failed to load buffer\n");
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -102,14 +102,14 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source) ...@@ -102,14 +102,14 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
pr_debug("bpf: successfull builtin compilation\n"); pr_debug("bpf: successfull builtin compilation\n");
obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename); obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, filename);
if (!IS_ERR(obj) && llvm_param.dump_obj) if (!IS_ERR_OR_NULL(obj) && llvm_param.dump_obj)
llvm__dump_obj(filename, obj_buf, obj_buf_sz); llvm__dump_obj(filename, obj_buf, obj_buf_sz);
free(obj_buf); free(obj_buf);
} else } else
obj = bpf_object__open(filename); obj = bpf_object__open(filename);
if (IS_ERR(obj)) { if (IS_ERR_OR_NULL(obj)) {
pr_debug("bpf: failed to load %s\n", filename); pr_debug("bpf: failed to load %s\n", filename);
return obj; return obj;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment