lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200702042942.76674-3-f.fainelli@gmail.com>
Date:   Wed,  1 Jul 2020 21:29:40 -0700
From:   Florian Fainelli <f.fainelli@...il.com>
To:     netdev@...r.kernel.org
Cc:     Florian Fainelli <f.fainelli@...il.com>,
        Andrew Lunn <andrew@...n.ch>,
        Heiner Kallweit <hkallweit1@...il.com>,
        Russell King <linux@...linux.org.uk>,
        "David S. Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Michal Kubecek <mkubecek@...e.cz>,
        linux-kernel@...r.kernel.org (open list)
Subject: [PATCH net-next 2/4] net: phy: Change cable test arguments to net_device

In order to untangle the ethtool/cabletest feature with the PHY library,
make the PHY library functions take a net_device argument and derive the
phy_device reference from there.

No functional changes introduced.

Signed-off-by: Florian Fainelli <f.fainelli@...il.com>
---
 drivers/net/phy/phy.c   | 18 ++++++++++++++----
 include/linux/phy.h     |  8 ++++----
 net/ethtool/cabletest.c |  4 ++--
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 56cfae950472..fbb74f37b961 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -489,12 +489,17 @@ static void phy_abort_cable_test(struct phy_device *phydev)
 		phydev_err(phydev, "Error while aborting cable test");
 }
 
-int phy_start_cable_test(struct phy_device *phydev,
+int phy_start_cable_test(struct net_device *dev,
 			 struct netlink_ext_ack *extack)
 {
-	struct net_device *dev = phydev->attached_dev;
+	struct phy_device *phydev = dev->phydev;
 	int err = -ENOMEM;
 
+	if (!dev->phydev) {
+		NL_SET_ERR_MSG(extack, "Network device not attached to a PHY");
+		return -EOPNOTSUPP;
+	}
+
 	if (!(phydev->drv &&
 	      phydev->drv->cable_test_start &&
 	      phydev->drv->cable_test_get_status)) {
@@ -552,13 +557,18 @@ int phy_start_cable_test(struct phy_device *phydev,
 }
 EXPORT_SYMBOL(phy_start_cable_test);
 
-int phy_start_cable_test_tdr(struct phy_device *phydev,
+int phy_start_cable_test_tdr(struct net_device *dev,
 			     struct netlink_ext_ack *extack,
 			     const struct phy_tdr_config *config)
 {
-	struct net_device *dev = phydev->attached_dev;
+	struct phy_device *phydev = dev->phydev;
 	int err = -ENOMEM;
 
+	if (!dev->phydev) {
+		NL_SET_ERR_MSG(extack, "Network device not attached to a PHY");
+		return -EOPNOTSUPP;
+	}
+
 	if (!(phydev->drv &&
 	      phydev->drv->cable_test_tdr_start &&
 	      phydev->drv->cable_test_get_status)) {
diff --git a/include/linux/phy.h b/include/linux/phy.h
index 101a48fa6750..53b95c52869d 100644
--- a/include/linux/phy.h
+++ b/include/linux/phy.h
@@ -1266,21 +1266,21 @@ int phy_restart_aneg(struct phy_device *phydev);
 int phy_reset_after_clk_enable(struct phy_device *phydev);
 
 #if IS_ENABLED(CONFIG_PHYLIB)
-int phy_start_cable_test(struct phy_device *phydev,
+int phy_start_cable_test(struct net_device *dev,
 			 struct netlink_ext_ack *extack);
-int phy_start_cable_test_tdr(struct phy_device *phydev,
+int phy_start_cable_test_tdr(struct net_device *dev,
 			     struct netlink_ext_ack *extack,
 			     const struct phy_tdr_config *config);
 #else
 static inline
-int phy_start_cable_test(struct phy_device *phydev,
+int phy_start_cable_test(struct net_device *dev,
 			 struct netlink_ext_ack *extack)
 {
 	NL_SET_ERR_MSG(extack, "Kernel not compiled with PHYLIB support");
 	return -EOPNOTSUPP;
 }
 static inline
-int phy_start_cable_test_tdr(struct phy_device *phydev,
+int phy_start_cable_test_tdr(struct net_device *dev,
 			     struct netlink_ext_ack *extack,
 			     const struct phy_tdr_config *config)
 {
diff --git a/net/ethtool/cabletest.c b/net/ethtool/cabletest.c
index 7194956aa09e..0d940a91493b 100644
--- a/net/ethtool/cabletest.c
+++ b/net/ethtool/cabletest.c
@@ -85,7 +85,7 @@ int ethnl_act_cable_test(struct sk_buff *skb, struct genl_info *info)
 	if (ret < 0)
 		goto out_rtnl;
 
-	ret = phy_start_cable_test(dev->phydev, info->extack);
+	ret = phy_start_cable_test(dev, info->extack);
 
 	ethnl_ops_complete(dev);
 
@@ -341,7 +341,7 @@ int ethnl_act_cable_test_tdr(struct sk_buff *skb, struct genl_info *info)
 	if (ret < 0)
 		goto out_rtnl;
 
-	ret = phy_start_cable_test_tdr(dev->phydev, info->extack, &cfg);
+	ret = phy_start_cable_test_tdr(dev, info->extack, &cfg);
 
 	ethnl_ops_complete(dev);
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ