* [PATCH] bpftool: Fix NULL vs IS_ERR() checking for return value of hashmap__new
@ 2021-12-12 5:18 Miaoqian Lin
[not found] ` <CAH-r-ZGri414YWumUs7U_ktvcv+BWOYfPTsB7So6kz5PNcK5tw@mail.gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Miaoqian Lin @ 2021-12-12 5:18 UTC (permalink / raw)
Cc: linmq006, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Quentin Monnet, netdev, bpf, linux-kernel
The hashmap__new() function does not return NULL on errors. It returns
ERR_PTR(-ENOMEM). Using IS_ERR() to check the return value to fix this.
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
tools/bpf/bpftool/link.c | 2 +-
tools/bpf/bpftool/map.c | 2 +-
tools/bpf/bpftool/pids.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 2c258db0d352..0dc402a89cd8 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -306,7 +306,7 @@ static int do_show(int argc, char **argv)
if (show_pinned) {
link_table = hashmap__new(hash_fn_for_key_as_id,
equal_fn_for_key_as_id, NULL);
- if (!link_table) {
+ if (IS_ERR(link_table)) {
p_err("failed to create hashmap for pinned paths");
return -1;
}
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index cae1f1119296..af83ae37d247 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -698,7 +698,7 @@ static int do_show(int argc, char **argv)
if (show_pinned) {
map_table = hashmap__new(hash_fn_for_key_as_id,
equal_fn_for_key_as_id, NULL);
- if (!map_table) {
+ if (IS_ERR(map_table)) {
p_err("failed to create hashmap for pinned paths");
return -1;
}
diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c
index 56b598eee043..6c4767e97061 100644
--- a/tools/bpf/bpftool/pids.c
+++ b/tools/bpf/bpftool/pids.c
@@ -101,7 +101,7 @@ int build_obj_refs_table(struct hashmap **map, enum bpf_obj_type type)
libbpf_print_fn_t default_print;
*map = hashmap__new(hash_fn_for_key_as_id, equal_fn_for_key_as_id, NULL);
- if (!*map) {
+ if (IS_ERR(*map)) {
p_err("failed to create hashmap for PID references");
return -1;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] bpftool: Fix NULL vs IS_ERR() checking for return value of hashmap__new
[not found] ` <CAH-r-ZGri414YWumUs7U_ktvcv+BWOYfPTsB7So6kz5PNcK5tw@mail.gmail.com>
@ 2021-12-13 19:33 ` Andrii Nakryiko
0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2021-12-13 19:33 UTC (permalink / raw)
To: 林妙倩
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Quentin Monnet, Networking, bpf, open list
On Mon, Dec 13, 2021 at 7:07 AM 林妙倩 <linmq006@gmail.com> wrote:
>
> Sorry, I forgot to do compile testing. I will test it and let you know.
>
> Miaoqian Lin <linmq006@gmail.com> 于2021年12月12日周日 13:18写道:
>>
>> The hashmap__new() function does not return NULL on errors. It returns
>> ERR_PTR(-ENOMEM). Using IS_ERR() to check the return value to fix this.
>>
>> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
>> ---
Please do test (not just compile test) and re-send all three patches
as one patch set instead of three independent patches. Thanks.
>> tools/bpf/bpftool/link.c | 2 +-
>> tools/bpf/bpftool/map.c | 2 +-
>> tools/bpf/bpftool/pids.c | 2 +-
>> 3 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
>> index 2c258db0d352..0dc402a89cd8 100644
>> --- a/tools/bpf/bpftool/link.c
>> +++ b/tools/bpf/bpftool/link.c
>> @@ -306,7 +306,7 @@ static int do_show(int argc, char **argv)
>> if (show_pinned) {
>> link_table = hashmap__new(hash_fn_for_key_as_id,
>> equal_fn_for_key_as_id, NULL);
>> - if (!link_table) {
>> + if (IS_ERR(link_table)) {
>> p_err("failed to create hashmap for pinned paths");
>> return -1;
>> }
>> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
>> index cae1f1119296..af83ae37d247 100644
>> --- a/tools/bpf/bpftool/map.c
>> +++ b/tools/bpf/bpftool/map.c
>> @@ -698,7 +698,7 @@ static int do_show(int argc, char **argv)
>> if (show_pinned) {
>> map_table = hashmap__new(hash_fn_for_key_as_id,
>> equal_fn_for_key_as_id, NULL);
>> - if (!map_table) {
>> + if (IS_ERR(map_table)) {
>> p_err("failed to create hashmap for pinned paths");
>> return -1;
>> }
>> diff --git a/tools/bpf/bpftool/pids.c b/tools/bpf/bpftool/pids.c
>> index 56b598eee043..6c4767e97061 100644
>> --- a/tools/bpf/bpftool/pids.c
>> +++ b/tools/bpf/bpftool/pids.c
>> @@ -101,7 +101,7 @@ int build_obj_refs_table(struct hashmap **map, enum bpf_obj_type type)
>> libbpf_print_fn_t default_print;
>>
>> *map = hashmap__new(hash_fn_for_key_as_id, equal_fn_for_key_as_id, NULL);
>> - if (!*map) {
>> + if (IS_ERR(*map)) {
>> p_err("failed to create hashmap for PID references");
>> return -1;
>> }
>> --
>> 2.17.1
>>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-12-13 19:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-12 5:18 [PATCH] bpftool: Fix NULL vs IS_ERR() checking for return value of hashmap__new Miaoqian Lin
[not found] ` <CAH-r-ZGri414YWumUs7U_ktvcv+BWOYfPTsB7So6kz5PNcK5tw@mail.gmail.com>
2021-12-13 19:33 ` Andrii Nakryiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).