summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2026-06-05 03:29:10 +0300
committerJakub Kicinski <kuba@kernel.org>2026-06-09 20:13:06 +0300
commitf58a40d07be39823abf2fa1f73b6a839580404f0 (patch)
treeb4b4afe43215f2c97bd05a339579d3c27b9c691e
parent732fa5ced1cc82bbdae3d05e5b364c7b6ecf04c3 (diff)
downloadlinux-f58a40d07be39823abf2fa1f73b6a839580404f0.tar.xz
net: ethtool: ioctl: concentrate the locking
Add another layer of helper functions to make upcoming locking changes easier. Otherwise we'd need a pretty complex goto structure. netdev instance lock is now taken slightly sooner but that should not be an issue since rtnl_lock is already held, anyway. Reviewed-by: Eric Dumazet <edumazet@google.com> Acked-by: Stanislav Fomichev <sdf@fomichev.me> Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Link: https://patch.msgid.link/20260605002912.3456868-11-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--net/ethtool/ioctl.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index a4b0cbae4063..c32c099845e3 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -3258,18 +3258,14 @@ static int ethtool_set_fecparam(struct net_device *dev, void __user *useraddr)
/* The main entry point in this file. Called from net/core/dev_ioctl.c */
static int
-__dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
- u32 ethcmd, struct ethtool_devlink_compat *devlink_state)
+dev_ethtool_locked(struct net *net, struct net_device *dev,
+ void __user *useraddr,
+ u32 ethcmd, struct ethtool_devlink_compat *devlink_state)
{
- struct net_device *dev;
u32 sub_cmd;
int rc;
netdev_features_t old_features;
- dev = __dev_get_by_name(net, ifr->ifr_name);
- if (!dev)
- return -ENODEV;
-
if (ethcmd == ETHTOOL_PERQUEUE) {
if (copy_from_user(&sub_cmd, useraddr + sizeof(ethcmd), sizeof(sub_cmd)))
return -EFAULT;
@@ -3320,7 +3316,6 @@ __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
return -EPERM;
}
- netdev_lock_ops(dev);
if (dev->dev.parent)
pm_runtime_get_sync(dev->dev.parent);
@@ -3560,7 +3555,29 @@ __dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
out:
if (dev->dev.parent)
pm_runtime_put(dev->dev.parent);
+
+ return rc;
+}
+
+static int
+__dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr,
+ u32 ethcmd, struct ethtool_devlink_compat *devlink_state)
+{
+ struct net_device *dev;
+ int rc;
+
+ rtnl_lock();
+ dev = __dev_get_by_name(net, ifr->ifr_name);
+ if (!dev) {
+ rc = -ENODEV;
+ goto exit_rtnl_unlock;
+ }
+
+ netdev_lock_ops(dev);
+ rc = dev_ethtool_locked(net, dev, useraddr, ethcmd, devlink_state);
netdev_unlock_ops(dev);
+exit_rtnl_unlock:
+ rtnl_unlock();
return rc;
}
@@ -3588,9 +3605,7 @@ int dev_ethtool(struct net *net, struct ifreq *ifr, void __user *useraddr)
break;
}
- rtnl_lock();
rc = __dev_ethtool(net, ifr, useraddr, ethcmd, state);
- rtnl_unlock();
if (rc)
goto exit_free;