2019-05-25 09:05:03

by Hariprasad Kelam

[permalink] [raw]
Subject: [PATCH] libbpf: fix warning PTR_ERR_OR_ZERO can be used

fix below warning reported by coccicheck

/tools/lib/bpf/libbpf.c:3461:1-3: WARNING: PTR_ERR_OR_ZERO can be used

Signed-off-by: Hariprasad Kelam <[email protected]>
---
tools/lib/bpf/libbpf.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 197b574..33c25b6 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -3458,9 +3458,7 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)

long libbpf_get_error(const void *ptr)
{
- if (IS_ERR(ptr))
- return PTR_ERR(ptr);
- return 0;
+ return PTR_ERR_OR_ZERO(ptr);
}

int bpf_prog_load(const char *file, enum bpf_prog_type type,
--
2.7.4


2019-05-25 19:38:54

by Yonghong Song

[permalink] [raw]
Subject: Re: [PATCH] libbpf: fix warning PTR_ERR_OR_ZERO can be used



On 5/25/19 2:02 AM, Hariprasad Kelam wrote:
> fix below warning reported by coccicheck
>
> /tools/lib/bpf/libbpf.c:3461:1-3: WARNING: PTR_ERR_OR_ZERO can be used
>
> Signed-off-by: Hariprasad Kelam <[email protected]>
Acked-by: Yonghong Song <[email protected]>

> ---
> tools/lib/bpf/libbpf.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 197b574..33c25b6 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -3458,9 +3458,7 @@ bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset)
>
> long libbpf_get_error(const void *ptr)
> {
> - if (IS_ERR(ptr))
> - return PTR_ERR(ptr);
> - return 0;
> + return PTR_ERR_OR_ZERO(ptr);
> }
>
> int bpf_prog_load(const char *file, enum bpf_prog_type type,
>

2019-05-28 09:28:08

by Daniel Borkmann

[permalink] [raw]
Subject: Re: [PATCH] libbpf: fix warning PTR_ERR_OR_ZERO can be used

On 05/25/2019 11:02 AM, Hariprasad Kelam wrote:
> fix below warning reported by coccicheck
>
> /tools/lib/bpf/libbpf.c:3461:1-3: WARNING: PTR_ERR_OR_ZERO can be used
>
> Signed-off-by: Hariprasad Kelam <[email protected]>

Applied, thanks!