2018-11-27 12:52:01

by Wen Yang

[permalink] [raw]
Subject: [PATCH] perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR())

Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...)).
This makes it more readable and also fix this warning detected
by err_cast.cocci:
tools/perf/util/bpf-loader.c:1606:11-18: WARNING: ERR_CAST can be used with op

Signed-off-by: Wen Yang <[email protected]>
CC: Peter Zijlstra <[email protected]>
CC: Arnaldo Carvalho de Melo <[email protected]>
CC: Alexander Shishkin <[email protected]>
CC: Jiri Olsa <[email protected]>
CC: Namhyung Kim <[email protected]>
CC: Julia Lawall <[email protected]>
CC: Wen Yang <[email protected]>
CC: [email protected]
---
tools/perf/util/bpf-loader.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index f9ae1a993806..9a280647d829 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1603,7 +1603,7 @@ struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const cha

op = bpf_map__add_newop(map, NULL);
if (IS_ERR(op))
- return ERR_PTR(PTR_ERR(op));
+ return ERR_CAST(op);
op->op_type = BPF_MAP_OP_SET_EVSEL;
op->v.evsel = evsel;
}
--
2.19.1



2018-11-27 13:58:35

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH] perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR())

Em Tue, Nov 27, 2018 at 05:06:10PM +0800, Wen Yang escreveu:
> Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...)).
> This makes it more readable and also fix this warning detected
> by err_cast.cocci:
> tools/perf/util/bpf-loader.c:1606:11-18: WARNING: ERR_CAST can be used with op

Have you tried building perf with this patch applied?

[acme@quaco perf]$ find tools/include/ -name "*.h" | xargs grep ERR_CAST
[acme@quaco perf]$

Its not there, you first have to grab a copy of ERR_CAST() from
include/linux/err.h and put it in tools/include/linux/err.h to then be
able to apply this patch and keep the tools building:

So, applying your patch I get:

[acme@quaco perf]$ make O=/tmp/build/perf -C tools/perf install-bin
make: Entering directory '/home/acme/git/perf/tools/perf'
BUILD: Doing 'make -j8' parallel build
INSTALL trace_plugins
CC /tmp/build/perf/util/bpf-loader.o
util/bpf-loader.c: In function ‘bpf__setup_output_event’:
util/bpf-loader.c:1606:12: error: implicit declaration of function ‘ERR_CAST’; did you mean ‘ERR_PTR’? [-Werror=implicit-function-declaration]
return ERR_CAST(op);
^~~~~~~~
ERR_PTR
util/bpf-loader.c:1606:12: error: nested extern declaration of ‘ERR_CAST’ [-Werror=nested-externs]
util/bpf-loader.c:1606:12: error: returning ‘int’ from a function with return type ‘struct perf_evsel *’ makes pointer from integer without a cast [-Werror=int-conversion]
return ERR_CAST(op);
^~~~~~~~~~~~
cc1: all warnings being treated as errors
mv: cannot stat '/tmp/build/perf/util/.bpf-loader.o.tmp': No such file or directory
make[4]: *** [/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/util/bpf-loader.o] Error 1
make[3]: *** [/home/acme/git/perf/tools/build/Makefile.build:139: util] Error 2
make[2]: *** [Makefile.perf:658: /tmp/build/perf/libperf-in.o] Error 2
make[1]: *** [Makefile.perf:215: sub-make] Error 2
make: *** [Makefile:110: install-bin] Error 2
make: Leaving directory '/home/acme/git/perf/tools/perf'
[acme@quaco perf]$ git log --oneline -1
82acac0da3ff (HEAD -> perf/core) perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR())
[acme@quaco perf]$


So I went on and added a prep patch adopting ERR_CAST(), then tools/perf
is back again building:

[acme@quaco perf]$ git log --oneline -2
2a371d30dc43 (HEAD -> perf/core) perf record: Extend trace writing to multi AIO
decc44122cf0 perf record: Enable asynchronous trace writing
[acme@quaco perf]$

Thanks, patch applied.

- Arnaldo


> Signed-off-by: Wen Yang <[email protected]>
> CC: Peter Zijlstra <[email protected]>
> CC: Arnaldo Carvalho de Melo <[email protected]>
> CC: Alexander Shishkin <[email protected]>
> CC: Jiri Olsa <[email protected]>
> CC: Namhyung Kim <[email protected]>
> CC: Julia Lawall <[email protected]>
> CC: Wen Yang <[email protected]>
> CC: [email protected]
> ---
> tools/perf/util/bpf-loader.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
> index f9ae1a993806..9a280647d829 100644
> --- a/tools/perf/util/bpf-loader.c
> +++ b/tools/perf/util/bpf-loader.c
> @@ -1603,7 +1603,7 @@ struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const cha
>
> op = bpf_map__add_newop(map, NULL);
> if (IS_ERR(op))
> - return ERR_PTR(PTR_ERR(op));
> + return ERR_CAST(op);
> op->op_type = BPF_MAP_OP_SET_EVSEL;
> op->v.evsel = evsel;
> }
> --
> 2.19.1

--

- Arnaldo

Subject: [tip:perf/core] perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR())

Commit-ID: 132efb95080bcf690bdfea1b6f0d57853ee4d48f
Gitweb: https://git.kernel.org/tip/132efb95080bcf690bdfea1b6f0d57853ee4d48f
Author: Wen Yang <[email protected]>
AuthorDate: Tue, 27 Nov 2018 17:06:10 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 29 Nov 2018 20:42:48 -0300

perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR())

Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...)). This
makes it more readable and also fix this warning detected by
err_cast.cocci:

tools/perf/util/bpf-loader.c:1606:11-18: WARNING: ERR_CAST can be used with op

Signed-off-by: Wen Yang <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Julia Lawall <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wen Yang <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/bpf-loader.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index f9ae1a993806..9a280647d829 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1603,7 +1603,7 @@ struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const cha

op = bpf_map__add_newop(map, NULL);
if (IS_ERR(op))
- return ERR_PTR(PTR_ERR(op));
+ return ERR_CAST(op);
op->op_type = BPF_MAP_OP_SET_EVSEL;
op->v.evsel = evsel;
}

Subject: [tip:perf/core] perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR())

Commit-ID: 19702894cd93d79c5b5a63f56f6f417595b1a57c
Gitweb: https://git.kernel.org/tip/19702894cd93d79c5b5a63f56f6f417595b1a57c
Author: Wen Yang <[email protected]>
AuthorDate: Tue, 27 Nov 2018 17:06:10 +0800
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 17 Dec 2018 14:54:36 -0300

perf bpf: Use ERR_CAST instead of ERR_PTR(PTR_ERR())

Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...)). This
makes it more readable and also fix this warning detected by
err_cast.cocci:

tools/perf/util/bpf-loader.c:1606:11-18: WARNING: ERR_CAST can be used with op

Signed-off-by: Wen Yang <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Julia Lawall <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Wen Yang <[email protected]>
Cc: [email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/util/bpf-loader.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index f9ae1a993806..9a280647d829 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1603,7 +1603,7 @@ struct perf_evsel *bpf__setup_output_event(struct perf_evlist *evlist, const cha

op = bpf_map__add_newop(map, NULL);
if (IS_ERR(op))
- return ERR_PTR(PTR_ERR(op));
+ return ERR_CAST(op);
op->op_type = BPF_MAP_OP_SET_EVSEL;
op->v.evsel = evsel;
}