Thread (22 messages) 22 messages, 6 authors, 2011-09-01

Re: [patch net-next-2.6 1/2] net: allow to change carrier via sysfs

flat view

From: Ben Hutchings <hidden>
Date: 2011-08-30 15:14:27

On Tue, 2011-08-30 at 16:46 +0200, Jiri Pirko wrote:
Allow to write to "carrier" attribute. Devices may implement ndo_change_carrier
callback to allow changing carrier from userspace.
[...]
quoted hunk ↗ jump to hunk
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 56e42ab..c8f2ca4 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -126,6 +126,30 @@ static ssize_t show_broadcast(struct device *dev,
 	return -EINVAL;
 }
 
+static ssize_t store_carrier(struct device *dev, struct device_attribute *attr,
+			     const char *buf, size_t len)
+{
+	struct net_device *netdev = to_net_dev(dev);
+	ssize_t ret;
+	int new_value;
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	if (!netif_running(netdev))
+		return -EINVAL;
Not sure that's the right error code.
+	if (sscanf(buf, "%d", &new_value) != 1)
+		return -EINVAL;
kstrtoint()

(Or maybe we should have kstrobool().)
+	if (!rtnl_trylock())
+		return restart_syscall();
[...]

This is consistent with other attributes, but it seems like a really bad
practice as it will generally result in the process busy-waiting on the
RTNL lock!  I think it would be better to add and use an
rtnl_lock_interruptible().

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help