]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net-sysfs: restore behavior for not running devices
authorEric Dumazet <edumazet@google.com>
Fri, 21 Feb 2025 05:12:23 +0000 (05:12 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:13:50 +0000 (11:13 +0200)
[ Upstream commit 75bc3dab4e49b4daccb27ad6ce8ce2fcd253fc1b ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/core/net-sysfs.c

index 07cb99b114bdd770d93a08088d6b3738776a86a2..88e001a4e0810b3257f8f5972ac2dc317da1237e 100644 (file)
@@ -232,11 +232,12 @@ static ssize_t carrier_show(struct device *dev,
                            struct device_attribute *attr, char *buf)
 {
        struct net_device *netdev = to_net_dev(dev);
-       int ret = -EINVAL;
+       int ret;
 
        if (!rtnl_trylock())
                return restart_syscall();
 
+       ret = -EINVAL;
        if (netif_running(netdev)) {
                /* Synchronize carrier state with link watch,
                 * see also rtnl_getlink().
@@ -266,6 +267,7 @@ static ssize_t speed_show(struct device *dev,
        if (!rtnl_trylock())
                return restart_syscall();
 
+       ret = -EINVAL;
        if (netif_running(netdev)) {
                struct ethtool_link_ksettings cmd;
 
@@ -292,6 +294,7 @@ static ssize_t duplex_show(struct device *dev,
        if (!rtnl_trylock())
                return restart_syscall();
 
+       ret = -EINVAL;
        if (netif_running(netdev)) {
                struct ethtool_link_ksettings cmd;