Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net-sysfs: restore behavior for not running devices

modprobe dummy dumdummies=1

Old behavior :

$ cat /sys/class/net/dummy0/carrier
cat: /sys/class/net/dummy0/carrier: Invalid argument

After blamed commit, an empty string is reported.

$ cat /sys/class/net/dummy0/carrier
$

In this commit, I restore the old behavior for carrier,
speed and duplex attributes.

Fixes: 79c61899b5ee ("net-sysfs: remove rtnl_trylock from device attributes")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Marco Leogrande <leogrande@google.com>
Reviewed-by: Antoine Tenart <atenart@kernel.org>
Link: https://patch.msgid.link/20250221051223.576726-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
75bc3dab 98f99288

+4 -1
+4 -1
net/core/net-sysfs.c
··· 313 313 struct device_attribute *attr, char *buf) 314 314 { 315 315 struct net_device *netdev = to_net_dev(dev); 316 - int ret = -EINVAL; 316 + int ret; 317 317 318 318 ret = sysfs_rtnl_lock(&dev->kobj, &attr->attr, netdev); 319 319 if (ret) 320 320 return ret; 321 321 322 + ret = -EINVAL; 322 323 if (netif_running(netdev)) { 323 324 /* Synchronize carrier state with link watch, 324 325 * see also rtnl_getlink(). ··· 350 349 if (ret) 351 350 return ret; 352 351 352 + ret = -EINVAL; 353 353 if (netif_running(netdev)) { 354 354 struct ethtool_link_ksettings cmd; 355 355 ··· 378 376 if (ret) 379 377 return ret; 380 378 379 + ret = -EINVAL; 381 380 if (netif_running(netdev)) { 382 381 struct ethtool_link_ksettings cmd; 383 382