All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions
@ 2022-07-14  1:56 xiaolinkui
  2022-07-14  3:37 ` Stanislav Fomichev
  2022-07-14  6:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: xiaolinkui @ 2022-07-14  1:56 UTC (permalink / raw)
  To: ast, daniel, davem, kuba, hawk, john.fastabend, andrii,
	martin.lau, song, yhs, kpsingh, sdf, haoluo, jolsa, mykolal,
	shuah, nathan, ndesaulniers, trix, xiaolinkui, xiaolinkui
  Cc: netdev, bpf, linux-kselftest, linux-kernel, llvm

From: Linkui Xiao <xiaolinkui@kylinos.cn>

Return boolean values ("true" or "false") instead of 1 or 0 from bool
functions.  This fixes the following warnings from coccicheck:

tools/testing/selftests/bpf/progs/test_xdp_noinline.c:407:9-10: WARNING:
return of 0/1 in function 'decap_v4' with return type bool
tools/testing/selftests/bpf/progs/test_xdp_noinline.c:389:9-10: WARNING:
return of 0/1 in function 'decap_v6' with return type bool
tools/testing/selftests/bpf/progs/test_xdp_noinline.c:290:9-10: WARNING:
return of 0/1 in function 'encap_v6' with return type bool
tools/testing/selftests/bpf/progs/test_xdp_noinline.c:264:9-10: WARNING:
return of 0/1 in function 'parse_tcp' with return type bool
tools/testing/selftests/bpf/progs/test_xdp_noinline.c:242:9-10: WARNING:
return of 0/1 in function 'parse_udp' with return type bool

Generated by: scripts/coccinelle/misc/boolreturn.cocci

Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
Suggested-by: Stanislav Fomichev <sdf@google.com>
---
 .../selftests/bpf/progs/test_xdp_noinline.c   | 30 +++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
index 125d872d7981..ba48fcb98ab2 100644
--- a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
+++ b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
@@ -239,7 +239,7 @@ bool parse_udp(void *data, void *data_end,
 	udp = data + off;
 
 	if (udp + 1 > data_end)
-		return 0;
+		return false;
 	if (!is_icmp) {
 		pckt->flow.port16[0] = udp->source;
 		pckt->flow.port16[1] = udp->dest;
@@ -247,7 +247,7 @@ bool parse_udp(void *data, void *data_end,
 		pckt->flow.port16[0] = udp->dest;
 		pckt->flow.port16[1] = udp->source;
 	}
-	return 1;
+	return true;
 }
 
 static __attribute__ ((noinline))
@@ -261,7 +261,7 @@ bool parse_tcp(void *data, void *data_end,
 
 	tcp = data + off;
 	if (tcp + 1 > data_end)
-		return 0;
+		return false;
 	if (tcp->syn)
 		pckt->flags |= (1 << 1);
 	if (!is_icmp) {
@@ -271,7 +271,7 @@ bool parse_tcp(void *data, void *data_end,
 		pckt->flow.port16[0] = tcp->dest;
 		pckt->flow.port16[1] = tcp->source;
 	}
-	return 1;
+	return true;
 }
 
 static __attribute__ ((noinline))
@@ -287,7 +287,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
 	void *data;
 
 	if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct ipv6hdr)))
-		return 0;
+		return false;
 	data = (void *)(long)xdp->data;
 	data_end = (void *)(long)xdp->data_end;
 	new_eth = data;
@@ -295,7 +295,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
 	old_eth = data + sizeof(struct ipv6hdr);
 	if (new_eth + 1 > data_end ||
 	    old_eth + 1 > data_end || ip6h + 1 > data_end)
-		return 0;
+		return false;
 	memcpy(new_eth->eth_dest, cval->mac, 6);
 	memcpy(new_eth->eth_source, old_eth->eth_dest, 6);
 	new_eth->eth_proto = 56710;
@@ -314,7 +314,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
 	ip6h->saddr.in6_u.u6_addr32[2] = 3;
 	ip6h->saddr.in6_u.u6_addr32[3] = ip_suffix;
 	memcpy(ip6h->daddr.in6_u.u6_addr32, dst->dstv6, 16);
-	return 1;
+	return true;
 }
 
 static __attribute__ ((noinline))
@@ -335,7 +335,7 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
 	ip_suffix <<= 15;
 	ip_suffix ^= pckt->flow.src;
 	if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct iphdr)))
-		return 0;
+		return false;
 	data = (void *)(long)xdp->data;
 	data_end = (void *)(long)xdp->data_end;
 	new_eth = data;
@@ -343,7 +343,7 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
 	old_eth = data + sizeof(struct iphdr);
 	if (new_eth + 1 > data_end ||
 	    old_eth + 1 > data_end || iph + 1 > data_end)
-		return 0;
+		return false;
 	memcpy(new_eth->eth_dest, cval->mac, 6);
 	memcpy(new_eth->eth_source, old_eth->eth_dest, 6);
 	new_eth->eth_proto = 8;
@@ -367,8 +367,8 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
 		csum += *next_iph_u16++;
 	iph->check = ~((csum & 0xffff) + (csum >> 16));
 	if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct iphdr)))
-		return 0;
-	return 1;
+		return false;
+	return true;
 }
 
 static __attribute__ ((noinline))
@@ -386,10 +386,10 @@ bool decap_v6(struct xdp_md *xdp, void **data, void **data_end, bool inner_v4)
 	else
 		new_eth->eth_proto = 56710;
 	if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct ipv6hdr)))
-		return 0;
+		return false;
 	*data = (void *)(long)xdp->data;
 	*data_end = (void *)(long)xdp->data_end;
-	return 1;
+	return true;
 }
 
 static __attribute__ ((noinline))
@@ -404,10 +404,10 @@ bool decap_v4(struct xdp_md *xdp, void **data, void **data_end)
 	memcpy(new_eth->eth_dest, old_eth->eth_dest, 6);
 	new_eth->eth_proto = 8;
 	if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct iphdr)))
-		return 0;
+		return false;
 	*data = (void *)(long)xdp->data;
 	*data_end = (void *)(long)xdp->data_end;
-	return 1;
+	return true;
 }
 
 static __attribute__ ((noinline))
-- 
2.17.1


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

* Re: [PATCH bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions
  2022-07-14  1:56 [PATCH bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions xiaolinkui
@ 2022-07-14  3:37 ` Stanislav Fomichev
  2022-07-14  6:21   ` Andrii Nakryiko
  2022-07-14  6:30 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Stanislav Fomichev @ 2022-07-14  3:37 UTC (permalink / raw)
  To: xiaolinkui
  Cc: ast, daniel, davem, kuba, hawk, john.fastabend, andrii,
	martin.lau, song, yhs, kpsingh, haoluo, jolsa, mykolal, shuah,
	nathan, ndesaulniers, trix, xiaolinkui, netdev, bpf,
	linux-kselftest, linux-kernel, llvm

On Wed, Jul 13, 2022 at 6:57 PM xiaolinkui <xiaolinkui@gmail.com> wrote:
>
> From: Linkui Xiao <xiaolinkui@kylinos.cn>
>
> Return boolean values ("true" or "false") instead of 1 or 0 from bool
> functions.  This fixes the following warnings from coccicheck:
>
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:407:9-10: WARNING:
> return of 0/1 in function 'decap_v4' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:389:9-10: WARNING:
> return of 0/1 in function 'decap_v6' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:290:9-10: WARNING:
> return of 0/1 in function 'encap_v6' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:264:9-10: WARNING:
> return of 0/1 in function 'parse_tcp' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:242:9-10: WARNING:
> return of 0/1 in function 'parse_udp' with return type bool
>
> Generated by: scripts/coccinelle/misc/boolreturn.cocci
>
> Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
Reviewed-by: Stanislav Fomichev <sdf@google.com>

> Suggested-by: Stanislav Fomichev <sdf@google.com>
That shouldn't be here :-) I didn't suggest the patch, you're
suggesting it, I'm just suggesting to properly format it.
Probably not worth a respin, I hope whoever gets to apply it can drop
that line (or maybe keep it, I don't mind).

> ---
>  .../selftests/bpf/progs/test_xdp_noinline.c   | 30 +++++++++----------
>  1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
> index 125d872d7981..ba48fcb98ab2 100644
> --- a/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
> +++ b/tools/testing/selftests/bpf/progs/test_xdp_noinline.c
> @@ -239,7 +239,7 @@ bool parse_udp(void *data, void *data_end,
>         udp = data + off;
>
>         if (udp + 1 > data_end)
> -               return 0;
> +               return false;
>         if (!is_icmp) {
>                 pckt->flow.port16[0] = udp->source;
>                 pckt->flow.port16[1] = udp->dest;
> @@ -247,7 +247,7 @@ bool parse_udp(void *data, void *data_end,
>                 pckt->flow.port16[0] = udp->dest;
>                 pckt->flow.port16[1] = udp->source;
>         }
> -       return 1;
> +       return true;
>  }
>
>  static __attribute__ ((noinline))
> @@ -261,7 +261,7 @@ bool parse_tcp(void *data, void *data_end,
>
>         tcp = data + off;
>         if (tcp + 1 > data_end)
> -               return 0;
> +               return false;
>         if (tcp->syn)
>                 pckt->flags |= (1 << 1);
>         if (!is_icmp) {
> @@ -271,7 +271,7 @@ bool parse_tcp(void *data, void *data_end,
>                 pckt->flow.port16[0] = tcp->dest;
>                 pckt->flow.port16[1] = tcp->source;
>         }
> -       return 1;
> +       return true;
>  }
>
>  static __attribute__ ((noinline))
> @@ -287,7 +287,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
>         void *data;
>
>         if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct ipv6hdr)))
> -               return 0;
> +               return false;
>         data = (void *)(long)xdp->data;
>         data_end = (void *)(long)xdp->data_end;
>         new_eth = data;
> @@ -295,7 +295,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
>         old_eth = data + sizeof(struct ipv6hdr);
>         if (new_eth + 1 > data_end ||
>             old_eth + 1 > data_end || ip6h + 1 > data_end)
> -               return 0;
> +               return false;
>         memcpy(new_eth->eth_dest, cval->mac, 6);
>         memcpy(new_eth->eth_source, old_eth->eth_dest, 6);
>         new_eth->eth_proto = 56710;
> @@ -314,7 +314,7 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
>         ip6h->saddr.in6_u.u6_addr32[2] = 3;
>         ip6h->saddr.in6_u.u6_addr32[3] = ip_suffix;
>         memcpy(ip6h->daddr.in6_u.u6_addr32, dst->dstv6, 16);
> -       return 1;
> +       return true;
>  }
>
>  static __attribute__ ((noinline))
> @@ -335,7 +335,7 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
>         ip_suffix <<= 15;
>         ip_suffix ^= pckt->flow.src;
>         if (bpf_xdp_adjust_head(xdp, 0 - (int)sizeof(struct iphdr)))
> -               return 0;
> +               return false;
>         data = (void *)(long)xdp->data;
>         data_end = (void *)(long)xdp->data_end;
>         new_eth = data;
> @@ -343,7 +343,7 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
>         old_eth = data + sizeof(struct iphdr);
>         if (new_eth + 1 > data_end ||
>             old_eth + 1 > data_end || iph + 1 > data_end)
> -               return 0;
> +               return false;
>         memcpy(new_eth->eth_dest, cval->mac, 6);
>         memcpy(new_eth->eth_source, old_eth->eth_dest, 6);
>         new_eth->eth_proto = 8;
> @@ -367,8 +367,8 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
>                 csum += *next_iph_u16++;
>         iph->check = ~((csum & 0xffff) + (csum >> 16));
>         if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct iphdr)))
> -               return 0;
> -       return 1;
> +               return false;
> +       return true;
>  }
>
>  static __attribute__ ((noinline))
> @@ -386,10 +386,10 @@ bool decap_v6(struct xdp_md *xdp, void **data, void **data_end, bool inner_v4)
>         else
>                 new_eth->eth_proto = 56710;
>         if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct ipv6hdr)))
> -               return 0;
> +               return false;
>         *data = (void *)(long)xdp->data;
>         *data_end = (void *)(long)xdp->data_end;
> -       return 1;
> +       return true;
>  }
>
>  static __attribute__ ((noinline))
> @@ -404,10 +404,10 @@ bool decap_v4(struct xdp_md *xdp, void **data, void **data_end)
>         memcpy(new_eth->eth_dest, old_eth->eth_dest, 6);
>         new_eth->eth_proto = 8;
>         if (bpf_xdp_adjust_head(xdp, (int)sizeof(struct iphdr)))
> -               return 0;
> +               return false;
>         *data = (void *)(long)xdp->data;
>         *data_end = (void *)(long)xdp->data_end;
> -       return 1;
> +       return true;
>  }
>
>  static __attribute__ ((noinline))
> --
> 2.17.1
>

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

* Re: [PATCH bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions
  2022-07-14  3:37 ` Stanislav Fomichev
@ 2022-07-14  6:21   ` Andrii Nakryiko
  0 siblings, 0 replies; 4+ messages in thread
From: Andrii Nakryiko @ 2022-07-14  6:21 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: xiaolinkui, Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, john fastabend,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	KP Singh, Hao Luo, Jiri Olsa, Mykola Lysenko, Shuah Khan,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, xiaolinkui,
	Networking, bpf, open list:KERNEL SELFTEST FRAMEWORK, open list,
	llvm

On Wed, Jul 13, 2022 at 8:37 PM Stanislav Fomichev <sdf@google.com> wrote:
>
> On Wed, Jul 13, 2022 at 6:57 PM xiaolinkui <xiaolinkui@gmail.com> wrote:
> >
> > From: Linkui Xiao <xiaolinkui@kylinos.cn>
> >
> > Return boolean values ("true" or "false") instead of 1 or 0 from bool
> > functions.  This fixes the following warnings from coccicheck:
> >
> > tools/testing/selftests/bpf/progs/test_xdp_noinline.c:407:9-10: WARNING:
> > return of 0/1 in function 'decap_v4' with return type bool
> > tools/testing/selftests/bpf/progs/test_xdp_noinline.c:389:9-10: WARNING:
> > return of 0/1 in function 'decap_v6' with return type bool
> > tools/testing/selftests/bpf/progs/test_xdp_noinline.c:290:9-10: WARNING:
> > return of 0/1 in function 'encap_v6' with return type bool
> > tools/testing/selftests/bpf/progs/test_xdp_noinline.c:264:9-10: WARNING:
> > return of 0/1 in function 'parse_tcp' with return type bool
> > tools/testing/selftests/bpf/progs/test_xdp_noinline.c:242:9-10: WARNING:
> > return of 0/1 in function 'parse_udp' with return type bool
> >
> > Generated by: scripts/coccinelle/misc/boolreturn.cocci
> >
> > Signed-off-by: Linkui Xiao <xiaolinkui@kylinos.cn>
> Reviewed-by: Stanislav Fomichev <sdf@google.com>
>
> > Suggested-by: Stanislav Fomichev <sdf@google.com>
> That shouldn't be here :-) I didn't suggest the patch, you're
> suggesting it, I'm just suggesting to properly format it.
> Probably not worth a respin, I hope whoever gets to apply it can drop
> that line (or maybe keep it, I don't mind).

Dropped Suggested-by, applied to bpf-next.

>
> > ---
> >  .../selftests/bpf/progs/test_xdp_noinline.c   | 30 +++++++++----------
> >  1 file changed, 15 insertions(+), 15 deletions(-)
> >

[...]

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

* Re: [PATCH bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions
  2022-07-14  1:56 [PATCH bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions xiaolinkui
  2022-07-14  3:37 ` Stanislav Fomichev
@ 2022-07-14  6:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-14  6:30 UTC (permalink / raw)
  To: xiaolinkui
  Cc: ast, daniel, davem, kuba, hawk, john.fastabend, andrii,
	martin.lau, song, yhs, kpsingh, sdf, haoluo, jolsa, mykolal,
	shuah, nathan, ndesaulniers, trix, xiaolinkui, netdev, bpf,
	linux-kselftest, linux-kernel, llvm

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu, 14 Jul 2022 09:56:47 +0800 you wrote:
> From: Linkui Xiao <xiaolinkui@kylinos.cn>
> 
> Return boolean values ("true" or "false") instead of 1 or 0 from bool
> functions.  This fixes the following warnings from coccicheck:
> 
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:407:9-10: WARNING:
> return of 0/1 in function 'decap_v4' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:389:9-10: WARNING:
> return of 0/1 in function 'decap_v6' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:290:9-10: WARNING:
> return of 0/1 in function 'encap_v6' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:264:9-10: WARNING:
> return of 0/1 in function 'parse_tcp' with return type bool
> tools/testing/selftests/bpf/progs/test_xdp_noinline.c:242:9-10: WARNING:
> return of 0/1 in function 'parse_udp' with return type bool
> 
> [...]

Here is the summary with links:
  - [bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions
    https://git.kernel.org/bpf/bpf-next/c/94bf6aad5dbe

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-07-14  6:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-14  1:56 [PATCH bpf-next] selftests/bpf: Return true/false (not 1/0) from bool functions xiaolinkui
2022-07-14  3:37 ` Stanislav Fomichev
2022-07-14  6:21   ` Andrii Nakryiko
2022-07-14  6:30 ` patchwork-bot+netdevbpf

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.