linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net-sysfs: Report link speed only when possible
@ 2014-06-06  8:40 Michal Privoznik
  2014-06-06  8:57 ` Jiri Pirko
  0 siblings, 1 reply; 11+ messages in thread
From: Michal Privoznik @ 2014-06-06  8:40 UTC (permalink / raw)
  To: davem; +Cc: gregkh, jiri, linux-kernel, netdev

The link speed is available at /sys/class/net/$nic/speed.
However, in some cases, depending on the driver, if the link is
not plugged, -1 is reported (this is the case of e1000e for
instance). To make things worse, the value is printed out as an
unsigned integer, so you'll get this shady number which you can't
evaluate correctly. This is actually a regression in 3.X kernels
as the commit that broke things is 8ae6daca. With this change,
you'll get -EINVAL whenever a -1 is to be printed out.

Before the change:
  # cat /sys/class/net/eth0/speed
  4294967295

After the change:
  # cat /sys/class/net/eth0/speed
  cat: /sys/class/net/eth0/speed: Invalid argument

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 net/core/net-sysfs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 1cac29e..ce4b298 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -172,8 +172,13 @@ static ssize_t speed_show(struct device *dev,
 
 	if (netif_running(netdev)) {
 		struct ethtool_cmd cmd;
-		if (!__ethtool_get_settings(netdev, &cmd))
-			ret = sprintf(buf, fmt_udec, ethtool_cmd_speed(&cmd));
+		if (!__ethtool_get_settings(netdev, &cmd)) {
+			__u32 speed = ethtool_cmd_speed(&cmd);
+
+			if (speed != (__u32) -1)
+				ret = sprintf(buf, fmt_udec,
+					      ethtool_cmd_speed(&cmd));
+		}
 	}
 	rtnl_unlock();
 	return ret;
-- 
2.0.0


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

end of thread, other threads:[~2014-06-16  9:01 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-06  8:40 [PATCH] net-sysfs: Report link speed only when possible Michal Privoznik
2014-06-06  8:57 ` Jiri Pirko
2014-06-06 19:54   ` David Miller
2014-06-13  9:19     ` Michal Privoznik
2014-06-13 20:03       ` David Miller
2014-06-16  7:32         ` Michal Privoznik
2014-06-16  8:11           ` David Miller
2014-06-16  8:30             ` Michal Privoznik
2014-06-16  8:44               ` David Miller
2014-06-16  8:59                 ` Michal Privoznik
2014-06-16  9:01                 ` Jiri Pirko

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