diff mbox series

[net-next,3/4] ethtool: move netif_device_present check from ethnl_parse_header_dev_get to ethnl_ops_begin

Message ID 82cd410f-8e0e-86d1-031c-bbb43c315574@gmail.com (mailing list archive)
State Accepted
Commit 41107ac22fcf39c45afaf1a59e259e5e0059e31a
Delegated to: Netdev Maintainers
Headers show
Series ethtool: runtime-resume netdev parent before ethtool ops | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 3 maintainers not CCed: vladyslavt@nvidia.com yangbo.lu@nxp.com johannes.berg@intel.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/header_inline success Link

Commit Message

Heiner Kallweit Aug. 1, 2021, 10:40 a.m. UTC
If device is runtime-suspended and not accessible then it may be
flagged as not present. If checking whether device is present is
done too early then we may bail out before we have the chance to
runtime-resume the device. Therefore move this check to
ethnl_ops_begin(). This is in preparation of a follow-up patch
that tries to runtime-resume the device before executing ethtool
ops.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 net/ethtool/netlink.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/net/ethtool/netlink.c b/net/ethtool/netlink.c
index ac720d684..e628d17f5 100644
--- a/net/ethtool/netlink.c
+++ b/net/ethtool/netlink.c
@@ -31,7 +31,13 @@  const struct nla_policy ethnl_header_policy_stats[] = {
 
 int ethnl_ops_begin(struct net_device *dev)
 {
-	if (dev && dev->ethtool_ops->begin)
+	if (!dev)
+		return 0;
+
+	if (!netif_device_present(dev))
+		return -ENODEV;
+
+	if (dev->ethtool_ops->begin)
 		return dev->ethtool_ops->begin(dev);
 	else
 		return 0;
@@ -115,12 +121,6 @@  int ethnl_parse_header_dev_get(struct ethnl_req_info *req_info,
 		return -EINVAL;
 	}
 
-	if (dev && !netif_device_present(dev)) {
-		dev_put(dev);
-		NL_SET_ERR_MSG(extack, "device not present");
-		return -ENODEV;
-	}
-
 	req_info->dev = dev;
 	req_info->flags = flags;
 	return 0;