linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] lib/bpf/libbpf: Simplify the code by using PTR_ERR_OR_ZERO
@ 2018-07-31 16:30 zhong jiang
  2018-07-31 21:11 ` Daniel Borkmann
  2018-08-01  1:18 ` zhong jiang
  0 siblings, 2 replies; 3+ messages in thread
From: zhong jiang @ 2018-07-31 16:30 UTC (permalink / raw)
  To: ast, daniel, davem; +Cc: netdev, linux-kernel

Use PTR_ERR_OR_ZERO is better than the open code.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 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 40211b5..9b61468 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -2271,9 +2271,7 @@ struct bpf_map *
 
 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,
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/bpf/libbpf: Simplify the code by using PTR_ERR_OR_ZERO
  2018-07-31 16:30 [PATCH] lib/bpf/libbpf: Simplify the code by using PTR_ERR_OR_ZERO zhong jiang
@ 2018-07-31 21:11 ` Daniel Borkmann
  2018-08-01  1:18 ` zhong jiang
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2018-07-31 21:11 UTC (permalink / raw)
  To: zhong jiang, ast, davem; +Cc: netdev, linux-kernel

On 07/31/2018 06:30 PM, zhong jiang wrote:
> Use PTR_ERR_OR_ZERO is better than the open code.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  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 40211b5..9b61468 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -2271,9 +2271,7 @@ struct bpf_map *
>  
>  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,
> 

Looks like you didn't even bother to try to compile your change ...

# make
Warning: Kernel ABI header at 'tools/include/uapi/linux/if_link.h' differs from latest version at 'include/uapi/linux/if_link.h'
  CC       libbpf.o
  CC       nlattr.o
  CC       btf.o
  CC       bpf.o
  CC       libbpf_errno.o
libbpf.c: In function ‘libbpf_get_error’:
libbpf.c:2269:9: error: implicit declaration of function ‘PTR_ERR_OR_ZERO’ [-Werror=implicit-function-declaration]
  return PTR_ERR_OR_ZERO(ptr);
         ^~~~~~~~~~~~~~~
libbpf.c:2269:2: error: nested extern declaration of ‘PTR_ERR_OR_ZERO’ [-Werror=nested-externs]
  return PTR_ERR_OR_ZERO(ptr);
  ^~~~~~
cc1: all warnings being treated as errors


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] lib/bpf/libbpf: Simplify the code by using PTR_ERR_OR_ZERO
  2018-07-31 16:30 [PATCH] lib/bpf/libbpf: Simplify the code by using PTR_ERR_OR_ZERO zhong jiang
  2018-07-31 21:11 ` Daniel Borkmann
@ 2018-08-01  1:18 ` zhong jiang
  1 sibling, 0 replies; 3+ messages in thread
From: zhong jiang @ 2018-08-01  1:18 UTC (permalink / raw)
  To: ast, daniel, davem; +Cc: netdev, linux-kernel

On 2018/8/1 0:30, zhong jiang wrote:
> Use PTR_ERR_OR_ZERO is better than the open code.
>
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  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 40211b5..9b61468 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -2271,9 +2271,7 @@ struct bpf_map *
>  
>  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,
I am so sorry for that.  I will repost it after check it correct carefully.

Thanks
zhong jiang


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-01  1:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-31 16:30 [PATCH] lib/bpf/libbpf: Simplify the code by using PTR_ERR_OR_ZERO zhong jiang
2018-07-31 21:11 ` Daniel Borkmann
2018-08-01  1:18 ` zhong jiang

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).