netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/4 v2] bonding: add rtnl protection for bonding_store_fail_over_mac
@ 2013-07-23  7:25 Ding Tianhong
  2013-07-25  0:46 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Ding Tianhong @ 2013-07-23  7:25 UTC (permalink / raw)
  To: Jay Vosburgh, Andy Gospodarek, David S. Miller, Netdev

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>
---
 drivers/net/bonding/bond_sysfs.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
index dc36a3d..8a5a6a3 100644
--- a/drivers/net/bonding/bond_sysfs.c
+++ b/drivers/net/bonding/bond_sysfs.c
@@ -501,20 +501,25 @@ 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;
@@ -522,7 +527,9 @@ static ssize_t bonding_store_fail_over_mac(struct device *d,
 		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,
-- 
1.8.0

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

* Re: [PATCH 3/4 v2] bonding: add rtnl protection for bonding_store_fail_over_mac
  2013-07-23  7:25 [PATCH 3/4 v2] bonding: add rtnl protection for bonding_store_fail_over_mac Ding Tianhong
@ 2013-07-25  0:46 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2013-07-25  0:46 UTC (permalink / raw)
  To: dingtianhong; +Cc: fubar, andy, netdev

From: Ding Tianhong <dingtianhong@huawei.com>
Date: Tue, 23 Jul 2013 15:25:39 +0800

> 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>

Applied.

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

end of thread, other threads:[~2013-07-25  0:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-23  7:25 [PATCH 3/4 v2] bonding: add rtnl protection for bonding_store_fail_over_mac Ding Tianhong
2013-07-25  0:46 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).