]> Pileus Git - ~andy/linux/commitdiff
bonding: trivial: make alb use bond_slave_has_mac()
authorVeaceslav Falico <vfalico@redhat.com>
Tue, 18 Jun 2013 11:44:52 +0000 (13:44 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 20 Jun 2013 05:20:08 +0000 (22:20 -0700)
Also, cleanup bond_alb_handle_active_change() from 2 identical ifs.

Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_alb.c

index 27fe329bdf8350cad97ab6850a7e2eb7e6195e0f..4ea8ed150d469d55c741d63c09fa4fc7f7a29fa5 100644 (file)
@@ -1129,6 +1129,7 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla
 {
        int perm_curr_diff;
        int perm_bond_diff;
+       struct slave *found_slave;
 
        perm_curr_diff = !ether_addr_equal_64bits(slave->perm_hwaddr,
                                                  slave->dev->dev_addr);
@@ -1136,21 +1137,12 @@ static void alb_change_hw_addr_on_detach(struct bonding *bond, struct slave *sla
                                                  bond->dev->dev_addr);
 
        if (perm_curr_diff && perm_bond_diff) {
-               struct slave *tmp_slave;
-               int i, found = 0;
-
-               bond_for_each_slave(bond, tmp_slave, i) {
-                       if (ether_addr_equal_64bits(slave->perm_hwaddr,
-                                                   tmp_slave->dev->dev_addr)) {
-                               found = 1;
-                               break;
-                       }
-               }
+               found_slave = bond_slave_has_mac(bond, slave->perm_hwaddr);
 
-               if (found) {
+               if (found_slave) {
                        /* locking: needs RTNL and nothing else */
-                       alb_swap_mac_addr(slave, tmp_slave);
-                       alb_fasten_mac_swap(bond, slave, tmp_slave);
+                       alb_swap_mac_addr(slave, found_slave);
+                       alb_fasten_mac_swap(bond, slave, found_slave);
                }
        }
 }
@@ -1668,7 +1660,6 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
        __acquires(&bond->curr_slave_lock)
 {
        struct slave *swap_slave;
-       int i;
 
        if (bond->curr_active_slave == new_slave) {
                return;
@@ -1690,17 +1681,8 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
        /* set the new curr_active_slave to the bonds mac address
         * i.e. swap mac addresses of old curr_active_slave and new curr_active_slave
         */
-       if (!swap_slave) {
-               struct slave *tmp_slave;
-               /* find slave that is holding the bond's mac address */
-               bond_for_each_slave(bond, tmp_slave, i) {
-                       if (ether_addr_equal_64bits(tmp_slave->dev->dev_addr,
-                                                   bond->dev->dev_addr)) {
-                               swap_slave = tmp_slave;
-                               break;
-                       }
-               }
-       }
+       if (!swap_slave)
+               swap_slave = bond_slave_has_mac(bond, bond->dev->dev_addr);
 
        /*
         * Arrange for swap_slave and new_slave to temporarily be
@@ -1721,15 +1703,11 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slave
        if (swap_slave) {
                /* swap mac address */
                alb_swap_mac_addr(swap_slave, new_slave);
-       } else {
-               /* set the new_slave to the bond mac address */
-               alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr);
-       }
-
-       if (swap_slave) {
                alb_fasten_mac_swap(bond, swap_slave, new_slave);
                read_lock(&bond->lock);
        } else {
+               /* set the new_slave to the bond mac address */
+               alb_set_slave_mac_addr(new_slave, bond->dev->dev_addr);
                read_lock(&bond->lock);
                alb_send_learning_packets(new_slave, bond->dev->dev_addr);
        }
@@ -1746,9 +1724,8 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
 {
        struct bonding *bond = netdev_priv(bond_dev);
        struct sockaddr *sa = addr;
-       struct slave *slave, *swap_slave;
+       struct slave *swap_slave;
        int res;
-       int i;
 
        if (!is_valid_ether_addr(sa->sa_data)) {
                return -EADDRNOTAVAIL;
@@ -1769,15 +1746,7 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)
                return 0;
        }
 
-       swap_slave = NULL;
-
-       bond_for_each_slave(bond, slave, i) {
-               if (ether_addr_equal_64bits(slave->dev->dev_addr,
-                                           bond_dev->dev_addr)) {
-                       swap_slave = slave;
-                       break;
-               }
-       }
+       swap_slave = bond_slave_has_mac(bond, bond_dev->dev_addr);
 
        if (swap_slave) {
                alb_swap_mac_addr(swap_slave, bond->curr_active_slave);