[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211030093051.2609665-1-yangyingliang@huawei.com>
Date: Sat, 30 Oct 2021 17:30:51 +0800
From: Yang Yingliang <yangyingliang@...wei.com>
To: <linux-kernel@...r.kernel.org>, <bpf@...r.kernel.org>
CC: <linux-kselftest@...r.kernel.org>, <shuah@...nel.org>,
<ast@...nel.org>
Subject: [PATCH -next] bpf/benchs: Fix return value check of bpf_program__attach()
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@...wei.com>
Signed-off-by: Yang Yingliang <yangyingliang@...wei.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
Powered by blists - more mailing lists