diff mbox series

[net-next] net: dev_addr_list: Introduce __dev_addr_add() and __dev_addr_del()

Message ID 20211008085354.9961-1-yajun.deng@linux.dev (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: dev_addr_list: Introduce __dev_addr_add() and __dev_addr_del() | expand

Checks

Context Check Description
netdev/cover_letter success Single patches do not need cover letters
netdev/fixes_present success Fixes tag not required for -next series
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 3 maintainers not CCed: luwei32@huawei.com gnaaman@drivenets.com wangxiongfeng2@huawei.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success No Fixes tag
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 178 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success No static functions without inline keyword in header files

Commit Message

Yajun Deng Oct. 8, 2021, 8:53 a.m. UTC
Introduce helper functions __dev_addr_add() and __dev_addr_del() for
the same code, make the code more concise.

Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
---
 net/core/dev_addr_lists.c | 117 ++++++++++++++++----------------------
 1 file changed, 48 insertions(+), 69 deletions(-)

Comments

Yajun Deng Oct. 8, 2021, 9:02 a.m. UTC | #1
Sorry, There are still some problems with this patch.


October 8, 2021 4:53 PM, "Yajun Deng" <yajun.deng@linux.dev> 写到:

> Introduce helper functions __dev_addr_add() and __dev_addr_del() for
> the same code, make the code more concise.
> 
> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>
> ---
> net/core/dev_addr_lists.c | 117 ++++++++++++++++----------------------
> 1 file changed, 48 insertions(+), 69 deletions(-)
> 
> diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
> index f0cb38344126..f6e33bdc0a30 100644
> --- a/net/core/dev_addr_lists.c
> +++ b/net/core/dev_addr_lists.c
> @@ -614,6 +614,38 @@ int dev_addr_del(struct net_device *dev, const unsigned char *addr,
> }
> EXPORT_SYMBOL(dev_addr_del);
> 
> +static int __dev_addr_add(struct net_device *dev, const unsigned char *addr,
> + unsigned char addr_type, bool global, bool sync,
> + bool exclusive)
> +{
> + int err;
> +
> + netif_addr_lock_bh(dev);
> + err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
> + addr_type, global, sync,
> + 0, exclusive);
> + if (!err)
> + __dev_set_rx_mode(dev);
> + netif_addr_unlock_bh(dev);
> +
> + return err;
> +}
> +
> +static int __dev_addr_del(struct net_device *dev, const unsigned char *addr,
> + unsigned char addr_type, bool global, bool sync)
> +{
> + int err;
> +
> + netif_addr_lock_bh(dev);
> + err = __hw_addr_del_ex(&dev->uc, addr, dev->addr_len,
> + addr_type, global, sync);
> + if (!err)
> + __dev_set_rx_mode(dev);
> + netif_addr_unlock_bh(dev);
> +
> + return err;
> +}
> +
> /*
> * Unicast list handling functions
> */
> @@ -625,16 +657,9 @@ EXPORT_SYMBOL(dev_addr_del);
> */
> int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr)
> {
> - int err;
> 
> - netif_addr_lock_bh(dev);
> - err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
> - NETDEV_HW_ADDR_T_UNICAST, true, false,
> - 0, true);
> - if (!err)
> - __dev_set_rx_mode(dev);
> - netif_addr_unlock_bh(dev);
> - return err;
> + return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_UNICAST,
> + true, false, true);
> }
> EXPORT_SYMBOL(dev_uc_add_excl);
> 
> @@ -648,15 +673,8 @@ EXPORT_SYMBOL(dev_uc_add_excl);
> */
> int dev_uc_add(struct net_device *dev, const unsigned char *addr)
> {
> - int err;
> -
> - netif_addr_lock_bh(dev);
> - err = __hw_addr_add(&dev->uc, addr, dev->addr_len,
> - NETDEV_HW_ADDR_T_UNICAST);
> - if (!err)
> - __dev_set_rx_mode(dev);
> - netif_addr_unlock_bh(dev);
> - return err;
> + return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_UNICAST,
> + false, false, false);
> }
> EXPORT_SYMBOL(dev_uc_add);
> 
> @@ -670,15 +688,8 @@ EXPORT_SYMBOL(dev_uc_add);
> */
> int dev_uc_del(struct net_device *dev, const unsigned char *addr)
> {
> - int err;
> -
> - netif_addr_lock_bh(dev);
> - err = __hw_addr_del(&dev->uc, addr, dev->addr_len,
> - NETDEV_HW_ADDR_T_UNICAST);
> - if (!err)
> - __dev_set_rx_mode(dev);
> - netif_addr_unlock_bh(dev);
> - return err;
> + return __dev_addr_del(dev, addr, NETDEV_HW_ADDR_T_UNICAST,
> + false, false);
> }
> EXPORT_SYMBOL(dev_uc_del);
> 
> @@ -810,33 +821,11 @@ EXPORT_SYMBOL(dev_uc_init);
> */
> int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr)
> {
> - int err;
> -
> - netif_addr_lock_bh(dev);
> - err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
> - NETDEV_HW_ADDR_T_MULTICAST, true, false,
> - 0, true);
> - if (!err)
> - __dev_set_rx_mode(dev);
> - netif_addr_unlock_bh(dev);
> - return err;
> + return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
> + true, false, true);
> }
> EXPORT_SYMBOL(dev_mc_add_excl);
> 
> -static int __dev_mc_add(struct net_device *dev, const unsigned char *addr,
> - bool global)
> -{
> - int err;
> -
> - netif_addr_lock_bh(dev);
> - err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
> - NETDEV_HW_ADDR_T_MULTICAST, global, false,
> - 0, false);
> - if (!err)
> - __dev_set_rx_mode(dev);
> - netif_addr_unlock_bh(dev);
> - return err;
> -}
> /**
> * dev_mc_add - Add a multicast address
> * @dev: device
> @@ -847,7 +836,8 @@ static int __dev_mc_add(struct net_device *dev, const unsigned char *addr,
> */
> int dev_mc_add(struct net_device *dev, const unsigned char *addr)
> {
> - return __dev_mc_add(dev, addr, false);
> + return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
> + false, false, false);
> }
> EXPORT_SYMBOL(dev_mc_add);
> 
> @@ -860,24 +850,11 @@ EXPORT_SYMBOL(dev_mc_add);
> */
> int dev_mc_add_global(struct net_device *dev, const unsigned char *addr)
> {
> - return __dev_mc_add(dev, addr, true);
> + return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
> + true, false, false);
> }
> EXPORT_SYMBOL(dev_mc_add_global);
> 
> -static int __dev_mc_del(struct net_device *dev, const unsigned char *addr,
> - bool global)
> -{
> - int err;
> -
> - netif_addr_lock_bh(dev);
> - err = __hw_addr_del_ex(&dev->mc, addr, dev->addr_len,
> - NETDEV_HW_ADDR_T_MULTICAST, global, false);
> - if (!err)
> - __dev_set_rx_mode(dev);
> - netif_addr_unlock_bh(dev);
> - return err;
> -}
> -
> /**
> * dev_mc_del - Delete a multicast address.
> * @dev: device
> @@ -888,7 +865,8 @@ static int __dev_mc_del(struct net_device *dev, const unsigned char *addr,
> */
> int dev_mc_del(struct net_device *dev, const unsigned char *addr)
> {
> - return __dev_mc_del(dev, addr, false);
> + return __dev_addr_del(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
> + false, false);
> }
> EXPORT_SYMBOL(dev_mc_del);
> 
> @@ -902,7 +880,8 @@ EXPORT_SYMBOL(dev_mc_del);
> */
> int dev_mc_del_global(struct net_device *dev, const unsigned char *addr)
> {
> - return __dev_mc_del(dev, addr, true);
> + return __dev_addr_del(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
> + true, false);
> }
> EXPORT_SYMBOL(dev_mc_del_global);
> 
> -- 
> 2.32.0
Jakub Kicinski Oct. 8, 2021, 6:25 p.m. UTC | #2
On Fri,  8 Oct 2021 16:53:54 +0800 Yajun Deng wrote:
> Introduce helper functions __dev_addr_add() and __dev_addr_del() for
> the same code, make the code more concise.
> 
> Signed-off-by: Yajun Deng <yajun.deng@linux.dev>

Please leave net/core/dev_addr_lists.c alone for the time being. 
I have a lot of changes queued to add the main address the the rbtree.
diff mbox series

Patch

diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index f0cb38344126..f6e33bdc0a30 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -614,6 +614,38 @@  int dev_addr_del(struct net_device *dev, const unsigned char *addr,
 }
 EXPORT_SYMBOL(dev_addr_del);
 
+static int __dev_addr_add(struct net_device *dev, const unsigned char *addr,
+			  unsigned char addr_type, bool global, bool sync,
+			  bool exclusive)
+{
+	int err;
+
+	netif_addr_lock_bh(dev);
+	err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
+			       addr_type, global, sync,
+			       0, exclusive);
+	if (!err)
+		__dev_set_rx_mode(dev);
+	netif_addr_unlock_bh(dev);
+
+	return err;
+}
+
+static int __dev_addr_del(struct net_device *dev, const unsigned char *addr,
+			  unsigned char addr_type, bool global, bool sync)
+{
+	int err;
+
+	netif_addr_lock_bh(dev);
+	err = __hw_addr_del_ex(&dev->uc, addr, dev->addr_len,
+			       addr_type, global, sync);
+	if (!err)
+		__dev_set_rx_mode(dev);
+	netif_addr_unlock_bh(dev);
+
+	return err;
+}
+
 /*
  * Unicast list handling functions
  */
@@ -625,16 +657,9 @@  EXPORT_SYMBOL(dev_addr_del);
  */
 int dev_uc_add_excl(struct net_device *dev, const unsigned char *addr)
 {
-	int err;
 
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_add_ex(&dev->uc, addr, dev->addr_len,
-			       NETDEV_HW_ADDR_T_UNICAST, true, false,
-			       0, true);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
+	return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_UNICAST,
+			      true, false, true);
 }
 EXPORT_SYMBOL(dev_uc_add_excl);
 
@@ -648,15 +673,8 @@  EXPORT_SYMBOL(dev_uc_add_excl);
  */
 int dev_uc_add(struct net_device *dev, const unsigned char *addr)
 {
-	int err;
-
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_add(&dev->uc, addr, dev->addr_len,
-			    NETDEV_HW_ADDR_T_UNICAST);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
+	return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_UNICAST,
+			      false, false, false);
 }
 EXPORT_SYMBOL(dev_uc_add);
 
@@ -670,15 +688,8 @@  EXPORT_SYMBOL(dev_uc_add);
  */
 int dev_uc_del(struct net_device *dev, const unsigned char *addr)
 {
-	int err;
-
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_del(&dev->uc, addr, dev->addr_len,
-			    NETDEV_HW_ADDR_T_UNICAST);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
+	return __dev_addr_del(dev, addr, NETDEV_HW_ADDR_T_UNICAST,
+			      false, false);
 }
 EXPORT_SYMBOL(dev_uc_del);
 
@@ -810,33 +821,11 @@  EXPORT_SYMBOL(dev_uc_init);
  */
 int dev_mc_add_excl(struct net_device *dev, const unsigned char *addr)
 {
-	int err;
-
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
-			       NETDEV_HW_ADDR_T_MULTICAST, true, false,
-			       0, true);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
+	return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
+			       true, false, true);
 }
 EXPORT_SYMBOL(dev_mc_add_excl);
 
-static int __dev_mc_add(struct net_device *dev, const unsigned char *addr,
-			bool global)
-{
-	int err;
-
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_add_ex(&dev->mc, addr, dev->addr_len,
-			       NETDEV_HW_ADDR_T_MULTICAST, global, false,
-			       0, false);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
-}
 /**
  *	dev_mc_add - Add a multicast address
  *	@dev: device
@@ -847,7 +836,8 @@  static int __dev_mc_add(struct net_device *dev, const unsigned char *addr,
  */
 int dev_mc_add(struct net_device *dev, const unsigned char *addr)
 {
-	return __dev_mc_add(dev, addr, false);
+	return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
+			      false, false, false);
 }
 EXPORT_SYMBOL(dev_mc_add);
 
@@ -860,24 +850,11 @@  EXPORT_SYMBOL(dev_mc_add);
  */
 int dev_mc_add_global(struct net_device *dev, const unsigned char *addr)
 {
-	return __dev_mc_add(dev, addr, true);
+	return __dev_addr_add(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
+			      true, false, false);
 }
 EXPORT_SYMBOL(dev_mc_add_global);
 
-static int __dev_mc_del(struct net_device *dev, const unsigned char *addr,
-			bool global)
-{
-	int err;
-
-	netif_addr_lock_bh(dev);
-	err = __hw_addr_del_ex(&dev->mc, addr, dev->addr_len,
-			       NETDEV_HW_ADDR_T_MULTICAST, global, false);
-	if (!err)
-		__dev_set_rx_mode(dev);
-	netif_addr_unlock_bh(dev);
-	return err;
-}
-
 /**
  *	dev_mc_del - Delete a multicast address.
  *	@dev: device
@@ -888,7 +865,8 @@  static int __dev_mc_del(struct net_device *dev, const unsigned char *addr,
  */
 int dev_mc_del(struct net_device *dev, const unsigned char *addr)
 {
-	return __dev_mc_del(dev, addr, false);
+	return __dev_addr_del(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
+			      false, false);
 }
 EXPORT_SYMBOL(dev_mc_del);
 
@@ -902,7 +880,8 @@  EXPORT_SYMBOL(dev_mc_del);
  */
 int dev_mc_del_global(struct net_device *dev, const unsigned char *addr)
 {
-	return __dev_mc_del(dev, addr, true);
+	return __dev_addr_del(dev, addr, NETDEV_HW_ADDR_T_MULTICAST,
+			      true, false);
 }
 EXPORT_SYMBOL(dev_mc_del_global);