mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 02:17:36 -04:00
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>
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user