bonding: bond_slave_info_query() fix
authorEric Dumazet <dada1@cosmosbay.com>
Thu, 23 Apr 2009 03:39:04 +0000 (03:39 +0000)
committerDavid S. Miller <davem@davemloft.net>
Fri, 1 May 2009 22:18:19 +0000 (15:18 -0700)
bond_slave_info_query() should keep a read lock while accessing slave info,
or risk accessing stale data and corruption.

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: Jay Vosburgh <fubar@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bonding/bond_main.c

index 63369b6b14d4f17ef7b756d81ebf89db3d73e896..67515b78ff91a706cbf75720345bc5f384cebc86 100644 (file)
@@ -2213,33 +2213,24 @@ static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *in
 {
        struct bonding *bond = netdev_priv(bond_dev);
        struct slave *slave;
-       int i, found = 0;
-
-       if (info->slave_id < 0) {
-               return -ENODEV;
-       }
+       int i, res = -ENODEV;
 
        read_lock(&bond->lock);
 
        bond_for_each_slave(bond, slave, i) {
                if (i == (int)info->slave_id) {
-                       found = 1;
+                       res = 0;
+                       strcpy(info->slave_name, slave->dev->name);
+                       info->link = slave->link;
+                       info->state = slave->state;
+                       info->link_failure_count = slave->link_failure_count;
                        break;
                }
        }
 
        read_unlock(&bond->lock);
 
-       if (found) {
-               strcpy(info->slave_name, slave->dev->name);
-               info->link = slave->link;
-               info->state = slave->state;
-               info->link_failure_count = slave->link_failure_count;
-       } else {
-               return -ENODEV;
-       }
-
-       return 0;
+       return res;
 }
 
 /*-------------------------------- Monitoring -------------------------------*/