* [PATCH -next] bpf/benchs: Fix return value check of bpf_program__attach()
@ 2021-10-30 9:30 Yang Yingliang
2021-11-01 4:13 ` Yonghong Song
0 siblings, 1 reply; 2+ messages in thread
From: Yang Yingliang @ 2021-10-30 9:30 UTC (permalink / raw)
To: linux-kernel, bpf; +Cc: linux-kselftest, shuah, ast
If bpf_program__attach() fails, it never returns NULL,
we should use libbpf_get_error() to check the return value.
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
.../bpf/benchs/bench_bloom_filter_map.c | 20 ++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
index 6eeeed2913e6..6879340b20c4 100644
--- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
+++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
@@ -296,6 +296,7 @@ static struct bloom_filter_bench *setup_skeleton(void)
static void bloom_lookup_setup(void)
{
struct bpf_link *link;
+ int err;
ctx.use_array_map = true;
@@ -304,7 +305,8 @@ static void bloom_lookup_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
- if (!link) {
+ err = libbpf_get_error(link);
+ if (err) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -313,6 +315,7 @@ static void bloom_lookup_setup(void)
static void bloom_update_setup(void)
{
struct bpf_link *link;
+ int err;
ctx.use_array_map = true;
@@ -321,7 +324,8 @@ static void bloom_update_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_update);
- if (!link) {
+ err = libbpf_get_error(link);
+ if (err) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -330,6 +334,7 @@ static void bloom_update_setup(void)
static void false_positive_setup(void)
{
struct bpf_link *link;
+ int err;
ctx.use_hashmap = true;
ctx.hashmap_use_bloom = true;
@@ -340,7 +345,8 @@ static void false_positive_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
- if (!link) {
+ err = libbpf_get_error(link);
+ if (err) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -349,6 +355,7 @@ static void false_positive_setup(void)
static void hashmap_with_bloom_setup(void)
{
struct bpf_link *link;
+ int err;
ctx.use_hashmap = true;
ctx.hashmap_use_bloom = true;
@@ -358,7 +365,8 @@ static void hashmap_with_bloom_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
- if (!link) {
+ err = libbpf_get_error(link);
+ if (err) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
@@ -367,6 +375,7 @@ static void hashmap_with_bloom_setup(void)
static void hashmap_no_bloom_setup(void)
{
struct bpf_link *link;
+ int err;
ctx.use_hashmap = true;
@@ -375,7 +384,8 @@ static void hashmap_no_bloom_setup(void)
populate_maps();
link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
- if (!link) {
+ err = libbpf_get_error(link);
+ if (err) {
fprintf(stderr, "failed to attach program!\n");
exit(1);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH -next] bpf/benchs: Fix return value check of bpf_program__attach()
2021-10-30 9:30 [PATCH -next] bpf/benchs: Fix return value check of bpf_program__attach() Yang Yingliang
@ 2021-11-01 4:13 ` Yonghong Song
0 siblings, 0 replies; 2+ messages in thread
From: Yonghong Song @ 2021-11-01 4:13 UTC (permalink / raw)
To: Yang Yingliang, linux-kernel, bpf; +Cc: linux-kselftest, shuah, ast
On 10/30/21 2:30 AM, Yang Yingliang wrote:
> If bpf_program__attach() fails, it never returns NULL,
> we should use libbpf_get_error() to check the return value.
>
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Thanks for the fix. LGTM with a nit below.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
> .../bpf/benchs/bench_bloom_filter_map.c | 20 ++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> index 6eeeed2913e6..6879340b20c4 100644
> --- a/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> +++ b/tools/testing/selftests/bpf/benchs/bench_bloom_filter_map.c
> @@ -296,6 +296,7 @@ static struct bloom_filter_bench *setup_skeleton(void)
> static void bloom_lookup_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_array_map = true;
>
> @@ -304,7 +305,8 @@ static void bloom_lookup_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
There is no need to define 'int err', you can just do
if (libbpf_get_error(link))
The same for a few 'int err' below.
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -313,6 +315,7 @@ static void bloom_lookup_setup(void)
> static void bloom_update_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_array_map = true;
>
> @@ -321,7 +324,8 @@ static void bloom_update_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_update);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -330,6 +334,7 @@ static void bloom_update_setup(void)
> static void false_positive_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_hashmap = true;
> ctx.hashmap_use_bloom = true;
> @@ -340,7 +345,8 @@ static void false_positive_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -349,6 +355,7 @@ static void false_positive_setup(void)
> static void hashmap_with_bloom_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_hashmap = true;
> ctx.hashmap_use_bloom = true;
> @@ -358,7 +365,8 @@ static void hashmap_with_bloom_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
> @@ -367,6 +375,7 @@ static void hashmap_with_bloom_setup(void)
> static void hashmap_no_bloom_setup(void)
> {
> struct bpf_link *link;
> + int err;
>
> ctx.use_hashmap = true;
>
> @@ -375,7 +384,8 @@ static void hashmap_no_bloom_setup(void)
> populate_maps();
>
> link = bpf_program__attach(ctx.skel->progs.bloom_hashmap_lookup);
> - if (!link) {
> + err = libbpf_get_error(link);
> + if (err) {
> fprintf(stderr, "failed to attach program!\n");
> exit(1);
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-01 4:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-30 9:30 [PATCH -next] bpf/benchs: Fix return value check of bpf_program__attach() Yang Yingliang
2021-11-01 4:13 ` Yonghong Song
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.