Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1261388 > unrolled thread
| Started by | Wang Nan <wangnan0@huawei.com> |
|---|---|
| First post | 2015-11-03 12:10 +0100 |
| Last post | 2015-11-03 16:30 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 3/5] perf tools: Parsing libbpf return value using err.h Wang Nan <wangnan0@huawei.com> - 2015-11-03 12:10 +0100
Re: [PATCH 3/5] perf tools: Parsing libbpf return value using err.h Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-11-03 16:20 +0100
Re: [PATCH 3/5] perf tools: Parsing libbpf return value using err.h Arnaldo Carvalho de Melo <acme@kernel.org> - 2015-11-03 16:30 +0100
| From | Wang Nan <wangnan0@huawei.com> |
|---|---|
| Date | 2015-11-03 12:10 +0100 |
| Subject | [PATCH 3/5] perf tools: Parsing libbpf return value using err.h |
| Message-ID | <qqHDr-1VD-1@gated-at.bofh.it> |
In following patches libbpf would encode error code using return
pointer instead of returnning a NULL pointer to indicate error. This
patch makes a preperation to enable perf correctly receive error code
from libbpf.
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/tests/llvm.c | 2 +-
tools/perf/util/bpf-loader.c | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
index 512d362..38e0d9a 100644
--- a/tools/perf/tests/llvm.c
+++ b/tools/perf/tests/llvm.c
@@ -27,7 +27,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
struct bpf_object *obj;
obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL);
- if (!obj)
+ if (IS_ERR(obj) || !obj)
return -1;
bpf_object__close(obj);
return 0;
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 0c5d174..dd6fa27 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -59,9 +59,9 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
} else
obj = bpf_object__open(filename);
- if (!obj) {
+ if (IS_ERR(obj) || !obj) {
pr_debug("bpf: failed to load %s\n", filename);
- return ERR_PTR(-EINVAL);
+ return !obj ? ERR_PTR(-EINVAL) : obj;
}
return obj;
@@ -96,9 +96,9 @@ config_bpf_program(struct bpf_program *prog)
int err;
config_str = bpf_program__title(prog, false);
- if (!config_str) {
+ if (IS_ERR(config_str) || !config_str) {
pr_debug("bpf: unable to get title for program\n");
- return -EINVAL;
+ return !config_str ? -EINVAL : PTR_ERR(config_str);
}
priv = calloc(sizeof(*priv), 1);
--
1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2015-11-03 16:20 +0100 |
| Message-ID | <qqLxo-4or-1@gated-at.bofh.it> |
| In reply to | #1261388 |
Em Tue, Nov 03, 2015 at 10:44:44AM +0000, Wang Nan escreveu:
> In following patches libbpf would encode error code using return
> pointer instead of returnning a NULL pointer to indicate error. This
> patch makes a preperation to enable perf correctly receive error code
> from libbpf.
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/tests/llvm.c | 2 +-
> tools/perf/util/bpf-loader.c | 8 ++++----
> 2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c
> index 512d362..38e0d9a 100644
> --- a/tools/perf/tests/llvm.c
> +++ b/tools/perf/tests/llvm.c
> @@ -27,7 +27,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz)
> struct bpf_object *obj;
>
> obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL);
> - if (!obj)
> + if (IS_ERR(obj) || !obj)
Well, since we've adopted IS_ERR() from the kernel, we better try to
follow how it is used there, no?
Since you move to use ERR_PTR(), you probably will never return NULL,
right? So whay the (|| !obj) part?
The kernel has an IS_ERR_OR_NULL() interface tho, trying to figure out
when that would be appropriate...
- Arnaldo
> return -1;
> bpf_object__close(obj);
> return 0;
> diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
> index 0c5d174..dd6fa27 100644
> --- a/tools/perf/util/bpf-loader.c
> +++ b/tools/perf/util/bpf-loader.c
> @@ -59,9 +59,9 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
> } else
> obj = bpf_object__open(filename);
>
> - if (!obj) {
> + if (IS_ERR(obj) || !obj) {
> pr_debug("bpf: failed to load %s\n", filename);
> - return ERR_PTR(-EINVAL);
> + return !obj ? ERR_PTR(-EINVAL) : obj;
> }
>
> return obj;
> @@ -96,9 +96,9 @@ config_bpf_program(struct bpf_program *prog)
> int err;
>
> config_str = bpf_program__title(prog, false);
> - if (!config_str) {
> + if (IS_ERR(config_str) || !config_str) {
> pr_debug("bpf: unable to get title for program\n");
> - return -EINVAL;
> + return !config_str ? -EINVAL : PTR_ERR(config_str);
> }
>
> priv = calloc(sizeof(*priv), 1);
> --
> 1.8.3.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2015-11-03 16:30 +0100 |
| Message-ID | <qqLH4-4sG-15@gated-at.bofh.it> |
| In reply to | #1261571 |
Em Tue, Nov 03, 2015 at 12:17:16PM -0300, Arnaldo Carvalho de Melo escreveu: > Em Tue, Nov 03, 2015 at 10:44:44AM +0000, Wang Nan escreveu: > > +++ b/tools/perf/tests/llvm.c > > @@ -27,7 +27,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz) > > struct bpf_object *obj; > > obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL); > > - if (!obj) > > + if (IS_ERR(obj) || !obj) > Well, since we've adopted IS_ERR() from the kernel, we better try to > follow how it is used there, no? > Since you move to use ERR_PTR(), you probably will never return NULL, > right? So whay the (|| !obj) part? > The kernel has an IS_ERR_OR_NULL() interface tho, trying to figure out > when that would be appropriate... I think you should change the error reporting convention _and_ the users at the same time, i.e. please merge this patch with the next and use plain: if (IS_ERR(obj)) Instead, ok? - Arnaldo -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web