diff mbox series

[v1] selftests/bpf: fix application of sizeof to pointer

Message ID 20241117031838.161576-1-guanjing@cmss.chinamobile.com (mailing list archive)
State New
Headers show
Series [v1] selftests/bpf: fix application of sizeof to pointer | expand

Commit Message

guanjing Nov. 17, 2024, 3:18 a.m. UTC
sizeof when applied to a pointer typed expression gives the size of
the pointer.

tools/testing/selftests/bpf/progs/test_tunnel_kern.c:678:41-47: ERROR: application of sizeof to pointer

The proper fix in this particular case is to code sizeof(*gopt)
instead of sizeof(gopt).

This issue was detected with the help of Coccinelle.

Fixes: 5ddafcc377f9 ("selftests/bpf: Fix a few tests for GCC related warnings.")
Signed-off-by: guanjing <guanjing@cmss.chinamobile.com>
---
 tools/testing/selftests/bpf/progs/test_tunnel_kern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Cong Wang Nov. 19, 2024, 3:37 a.m. UTC | #1
On Sun, Nov 17, 2024 at 11:18:38AM +0800, guanjing wrote:
> sizeof when applied to a pointer typed expression gives the size of
> the pointer.
> 
> tools/testing/selftests/bpf/progs/test_tunnel_kern.c:678:41-47: ERROR: application of sizeof to pointer
> 
> The proper fix in this particular case is to code sizeof(*gopt)
> instead of sizeof(gopt).
> 
> This issue was detected with the help of Coccinelle.
> 
> Fixes: 5ddafcc377f9 ("selftests/bpf: Fix a few tests for GCC related warnings.")
> Signed-off-by: guanjing <guanjing@cmss.chinamobile.com>
> ---
>  tools/testing/selftests/bpf/progs/test_tunnel_kern.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> index 32127f1cd687..3a437cdc5c15 100644
> --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> @@ -675,7 +675,7 @@ int ip6geneve_set_tunnel(struct __sk_buff *skb)
>  	gopt->length = 2; /* 4-byte multiple */
>  	*(int *) &gopt->opt_data = bpf_htonl(0xfeedbeef);
>  
> -	ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(gopt));
> +	ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(*gopt));

Good catch!

I think sizeof(local_gopt) is better, to align with geneve_set_tunnel(),
what do you think?

Thanks.
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
index 32127f1cd687..3a437cdc5c15 100644
--- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
+++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
@@ -675,7 +675,7 @@  int ip6geneve_set_tunnel(struct __sk_buff *skb)
 	gopt->length = 2; /* 4-byte multiple */
 	*(int *) &gopt->opt_data = bpf_htonl(0xfeedbeef);
 
-	ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(gopt));
+	ret = bpf_skb_set_tunnel_opt(skb, gopt, sizeof(*gopt));
 	if (ret < 0) {
 		log_err(ret);
 		return TC_ACT_SHOT;