diff mbox series

samples/bpf: xdpsock: Use swap() instead of open coding it

Message ID 20220113162228.5576-1-jiapeng.chong@linux.alibaba.com (mailing list archive)
State Rejected
Delegated to: BPF
Headers show
Series samples/bpf: xdpsock: Use swap() instead of open coding it | expand

Checks

Context Check Description
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Not a local patch

Commit Message

Jiapeng Chong Jan. 13, 2022, 4:22 p.m. UTC
Clean the following coccicheck warning:

./samples/bpf/xdpsock_user.c:632:22-23: WARNING opportunity for swap().

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 samples/bpf/xdpsock_user.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Song Liu Jan. 13, 2022, 6:59 p.m. UTC | #1
> On Jan 13, 2022, at 8:22 AM, Jiapeng Chong <jiapeng.chong@linux.alibaba.com> wrote:
> 
> Clean the following coccicheck warning:
> 
> ./samples/bpf/xdpsock_user.c:632:22-23: WARNING opportunity for swap().
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>

Acked-by: Song Liu <songliubraving@fb.com>
Andrii Nakryiko Jan. 15, 2022, 1:29 a.m. UTC | #2
On Thu, Jan 13, 2022 at 8:22 AM Jiapeng Chong
<jiapeng.chong@linux.alibaba.com> wrote:
>
> Clean the following coccicheck warning:
>
> ./samples/bpf/xdpsock_user.c:632:22-23: WARNING opportunity for swap().
>
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>  samples/bpf/xdpsock_user.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
> index aa50864e4415..30065c703c77 100644
> --- a/samples/bpf/xdpsock_user.c
> +++ b/samples/bpf/xdpsock_user.c
> @@ -626,11 +626,8 @@ static void swap_mac_addresses(void *data)
>         struct ether_header *eth = (struct ether_header *)data;
>         struct ether_addr *src_addr = (struct ether_addr *)&eth->ether_shost;
>         struct ether_addr *dst_addr = (struct ether_addr *)&eth->ether_dhost;
> -       struct ether_addr tmp;
>
> -       tmp = *src_addr;
> -       *src_addr = *dst_addr;
> -       *dst_addr = tmp;
> +       swap(*src_addr, *dst_addr);

Don't mindlessly apply any suggestion of any robot/script without at
least compile-testing:

/data/users/andriin/linux/samples/bpf/xdpsock_user.c: In function
‘swap_mac_addresses’:
/data/users/andriin/linux/samples/bpf/xdpsock_user.c:630:2: warning:
implicit declaration of function ‘swap’; did you mean ‘mmap’?
[-Wimplicit-function-declaration]
  swap(*src_addr, *dst_addr);
  ^~~~
  mmap

I think this exact change was accidentally applied recently and backed
out. Please stop sending such "improvements".


>  }
>
>  static void hex_dump(void *pkt, size_t length, u64 addr)
> --
> 2.20.1.7.g153144c
>
diff mbox series

Patch

diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index aa50864e4415..30065c703c77 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -626,11 +626,8 @@  static void swap_mac_addresses(void *data)
 	struct ether_header *eth = (struct ether_header *)data;
 	struct ether_addr *src_addr = (struct ether_addr *)&eth->ether_shost;
 	struct ether_addr *dst_addr = (struct ether_addr *)&eth->ether_dhost;
-	struct ether_addr tmp;
 
-	tmp = *src_addr;
-	*src_addr = *dst_addr;
-	*dst_addr = tmp;
+	swap(*src_addr, *dst_addr);
 }
 
 static void hex_dump(void *pkt, size_t length, u64 addr)