Skip to content

Commit

Permalink
bonding: add rtnl protection for bonding_store_fail_over_mac
Browse files Browse the repository at this point in the history
We need rtnl protection while reading slave_cnt and updating
the .fail_over_mac, and it also follows the logic "don't change
anything slave-related without rtnl". :)

Signed-off-by: Ding Tianhong <dingtianhong@huawei.com>
Cc: Jay Vosburgh <fubar@us.ibm.com>
Cc: Andy Gospodarek <andy@greyhouse.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
dingtianhong authored and David S. Miller committed Jul 25, 2013
1 parent 38c4916 commit 9402b74
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions drivers/net/bonding/bond_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,28 +501,35 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
struct device_attribute *attr,
const char *buf, size_t count)
{
int new_value;
int new_value, ret = count;
struct bonding *bond = to_bond(d);

if (!rtnl_trylock())
return restart_syscall();

if (bond->slave_cnt != 0) {
pr_err("%s: Can't alter fail_over_mac with slaves in bond.\n",
bond->dev->name);
return -EPERM;
ret = -EPERM;
goto out;
}

new_value = bond_parse_parm(buf, fail_over_mac_tbl);
if (new_value < 0) {
pr_err("%s: Ignoring invalid fail_over_mac value %s.\n",
bond->dev->name, buf);
return -EINVAL;
ret = -EINVAL;
goto out;
}

bond->params.fail_over_mac = new_value;
pr_info("%s: Setting fail_over_mac to %s (%d).\n",
bond->dev->name, fail_over_mac_tbl[new_value].modename,
new_value);

return count;
out:
rtnl_unlock();
return ret;
}

static DEVICE_ATTR(fail_over_mac, S_IRUGO | S_IWUSR,
Expand Down

0 comments on commit 9402b74

Please sign in to comment.