All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: Use swap() instead of open coding it
@ 2022-05-12  3:24 Jiapeng Chong
  2022-05-12  5:07 ` Christophe JAILLET
  0 siblings, 1 reply; 2+ messages in thread
From: Jiapeng Chong @ 2022-05-12  3:24 UTC (permalink / raw)
  To: wellslutw
  Cc: davem, edumazet, kuba, pabeni, p.zabel, netdev, linux-kernel,
	Jiapeng Chong, Abaci Robot

Clean the following coccicheck warning:

./drivers/net/ethernet/sunplus/spl2sw_driver.c:217:27-28: WARNING
opportunity for swap().

./drivers/net/ethernet/sunplus/spl2sw_driver.c:222:27-28: WARNING
opportunity for swap().

Reported-by: Abaci Robot <abaci@linux.alibaba.com>
Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
---
 drivers/net/ethernet/sunplus/spl2sw_driver.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c
index 8320fa833d3e..cccf14325ba8 100644
--- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
@@ -204,8 +204,6 @@ static const struct net_device_ops netdev_ops = {
 
 static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
 {
-	u8 tmp;
-
 	/* Byte order of MAC address of some samples are reversed.
 	 * Check vendor id and convert byte order if it is wrong.
 	 * OUI of Sunplus: fc:4b:bc
@@ -213,19 +211,13 @@ static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
 	if (mac_addr[5] == 0xfc && mac_addr[4] == 0x4b && mac_addr[3] == 0xbc &&
 	    (mac_addr[0] != 0xfc || mac_addr[1] != 0x4b || mac_addr[2] != 0xbc)) {
 		/* Swap mac_addr[0] and mac_addr[5] */
-		tmp = mac_addr[0];
-		mac_addr[0] = mac_addr[5];
-		mac_addr[5] = tmp;
+		swap(mac_addr[0], mac_addr[5]);
 
 		/* Swap mac_addr[1] and mac_addr[4] */
-		tmp = mac_addr[1];
-		mac_addr[1] = mac_addr[4];
-		mac_addr[4] = tmp;
+		swap(mac_addr[1], mac_addr[4]);
 
 		/* Swap mac_addr[2] and mac_addr[3] */
-		tmp = mac_addr[2];
-		mac_addr[2] = mac_addr[3];
-		mac_addr[3] = tmp;
+		swap(mac_addr[2], mac_addr[3]);
 	}
 }
 
-- 
2.20.1.7.g153144c


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

* Re: [PATCH] net: ethernet: Use swap() instead of open coding it
  2022-05-12  3:24 [PATCH] net: ethernet: Use swap() instead of open coding it Jiapeng Chong
@ 2022-05-12  5:07 ` Christophe JAILLET
  0 siblings, 0 replies; 2+ messages in thread
From: Christophe JAILLET @ 2022-05-12  5:07 UTC (permalink / raw)
  To: Jiapeng Chong, wellslutw
  Cc: davem, edumazet, kuba, pabeni, p.zabel, netdev, linux-kernel,
	Abaci Robot

Le 12/05/2022 à 05:24, Jiapeng Chong a écrit :
> Clean the following coccicheck warning:
> 
> ./drivers/net/ethernet/sunplus/spl2sw_driver.c:217:27-28: WARNING
> opportunity for swap().
> 
> ./drivers/net/ethernet/sunplus/spl2sw_driver.c:222:27-28: WARNING
> opportunity for swap().
> 
> Reported-by: Abaci Robot <abaci@linux.alibaba.com>
> Signed-off-by: Jiapeng Chong <jiapeng.chong@linux.alibaba.com>
> ---
>   drivers/net/ethernet/sunplus/spl2sw_driver.c | 14 +++-----------
>   1 file changed, 3 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> index 8320fa833d3e..cccf14325ba8 100644
> --- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
> +++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> @@ -204,8 +204,6 @@ static const struct net_device_ops netdev_ops = {
>   
>   static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
>   {
> -	u8 tmp;
> -
>   	/* Byte order of MAC address of some samples are reversed.
>   	 * Check vendor id and convert byte order if it is wrong.
>   	 * OUI of Sunplus: fc:4b:bc
> @@ -213,19 +211,13 @@ static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
>   	if (mac_addr[5] == 0xfc && mac_addr[4] == 0x4b && mac_addr[3] == 0xbc &&
>   	    (mac_addr[0] != 0xfc || mac_addr[1] != 0x4b || mac_addr[2] != 0xbc)) {
>   		/* Swap mac_addr[0] and mac_addr[5] */
> -		tmp = mac_addr[0];
> -		mac_addr[0] = mac_addr[5];
> -		mac_addr[5] = tmp;
> +		swap(mac_addr[0], mac_addr[5]);

Hi,

nitpicking: the comment above the swap is now somehow useless, the code 
being clear by itself

CJ

>   
>   		/* Swap mac_addr[1] and mac_addr[4] */
> -		tmp = mac_addr[1];
> -		mac_addr[1] = mac_addr[4];
> -		mac_addr[4] = tmp;
> +		swap(mac_addr[1], mac_addr[4]);
>   
>   		/* Swap mac_addr[2] and mac_addr[3] */
> -		tmp = mac_addr[2];
> -		mac_addr[2] = mac_addr[3];
> -		mac_addr[3] = tmp;
> +		swap(mac_addr[2], mac_addr[3]);
>   	}
>   }
>   


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

end of thread, other threads:[~2022-05-12  5:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-12  3:24 [PATCH] net: ethernet: Use swap() instead of open coding it Jiapeng Chong
2022-05-12  5:07 ` Christophe JAILLET

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.