From: Yi Li <yilikernel@xxxxxxxxx> This patch introduces the use of the macro IS_ERR_OR_NULL in place of tests for NULL and IS_ERR. The following Coccinelle semantic patch was used for making the change: @@ expression e; @@ - !e || IS_ERR(e) + IS_ERR_OR_NULL(e) || ... Signed-off-by: Yi Li <yilikernel@xxxxxxxxx> --- tools/perf/util/bpf-loader.c | 13 +++++++------ tools/perf/util/parse-events.c | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 10c187b..b14d224 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -426,7 +426,7 @@ preproc_gen_prologue(struct bpf_program *prog, int n, size_t prologue_cnt = 0; int i, err; - if (IS_ERR(priv) || !priv || priv->is_tp) + if (IS_ERR_OR_NULL(priv) || priv->is_tp) goto errout; pev = &priv->pev; @@ -578,7 +578,7 @@ static int hook_load_preprocessor(struct bpf_program *prog) bool need_prologue = false; int err, i; - if (IS_ERR(priv) || !priv) { + if (IS_ERR_OR_NULL(priv)) { pr_debug("Internal error when hook preprocessor\n"); return -BPF_LOADER_ERRNO__INTERNAL; } @@ -650,8 +650,9 @@ int bpf__probe(struct bpf_object *obj) goto out; priv = bpf_program__priv(prog); - if (IS_ERR(priv) || !priv) { - err = PTR_ERR(priv); + if (IS_ERR_OR_NULL(priv)) { + pr_debug("bpf: failed to get private field\n"); + err = -BPF_LOADER_ERRNO__INTERNAL; goto out; } @@ -701,7 +702,7 @@ int bpf__unprobe(struct bpf_object *obj) struct bpf_prog_priv *priv = bpf_program__priv(prog); int i; - if (IS_ERR(priv) || !priv || priv->is_tp) + if (IS_ERR_OR_NULL(priv) || priv->is_tp) continue; for (i = 0; i < priv->pev.ntevs; i++) { @@ -759,7 +760,7 @@ int bpf__foreach_event(struct bpf_object *obj, struct perf_probe_event *pev; int i, fd; - if (IS_ERR(priv) || !priv) { + if (IS_ERR_OR_NULL(priv)) { pr_debug("bpf: failed to get private field\n"); return -BPF_LOADER_ERRNO__INTERNAL; } diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index b5e2ade..609c31f 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -690,7 +690,7 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state, struct __add_bpf_event_param param = {parse_state, list, head_config}; static bool registered_unprobe_atexit = false; - if (IS_ERR(obj) || !obj) { + if (IS_ERR_OR_NULL(obj)) { snprintf(errbuf, sizeof(errbuf), "Internal error: load bpf obj with NULL"); err = -EINVAL; -- 2.7.5