[PATCH v2] perf tools: use PTR_ERR_OR_ZERO inetead of return code

From: Ding Xiang
Date: Thu Sep 06 2018 - 07:43:04 EST


use PTR_ERR_OR_ZERO for bpf__setup_stdout return code

v2: add macro PTR_ERR_OR_ZERO to err.h

Signed-off-by: Ding Xiang <dingxiang@xxxxxxxxxxxxxxxxxxxx>
---
tools/include/linux/err.h | 7 +++++++
tools/perf/util/bpf-loader.c | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/include/linux/err.h b/tools/include/linux/err.h
index 7a8b61a..0946496 100644
--- a/tools/include/linux/err.h
+++ b/tools/include/linux/err.h
@@ -52,4 +52,11 @@ static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
}

+static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
+{
+ if (IS_ERR(ptr))
+ return PTR_ERR(ptr);
+ else
+ return 0;
+}
#endif /* _LINUX_ERR_H */
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 47aac41..f9ae1a9 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1615,7 +1615,7 @@ struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const cha
int bpf__setup_stdout(struct perf_evlist *evlist)
{
struct perf_evsel *evsel = bpf__setup_output_event(evlist, "__bpf_stdout__");
- return IS_ERR(evsel) ? PTR_ERR(evsel) : 0;
+ return PTR_ERR_OR_ZERO(evsel);
}

#define ERRNO_OFFSET(e) ((e) - __BPF_LOADER_ERRNO__START)
--
1.9.1