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: <20240906093955.3083245-3-niklas.soderlund+renesas@ragnatech.se>
Date: Fri,  6 Sep 2024 11:39:55 +0200
From: Niklas Söderlund <niklas.soderlund+renesas@...natech.se>
To: Andrew Lunn <andrew@...n.ch>,
	Heiner Kallweit <hkallweit1@...il.com>,
	Russell King <linux@...linux.org.uk>,
	"David S. Miller" <davem@...emloft.net>,
	Eric Dumazet <edumazet@...gle.com>,
	Jakub Kicinski <kuba@...nel.org>,
	Paolo Abeni <pabeni@...hat.com>,
	Yoshihiro Shimoda <yoshihiro.shimoda.uh@...esas.com>,
	netdev@...r.kernel.org
Cc: linux-renesas-soc@...r.kernel.org,
	Niklas Söderlund <niklas.soderlund+renesas@...natech.se>
Subject: [net-next 2/2] net: phy: Fallback to C22 access if needed in phy_mii_ioctl()

If a C45 only PHY is attached to a driver that only knows how to talk
C22 phylib will fallback and use indirect access. This frees the driver
from having to implement this themself.

The IOCTL implementation for SIOCGMIIREG and SIOCSMIIREG do not use
these convenience functions and instead fail if a C45 PHY is used
together with a driver that only knows how to speak C22.

Fix this by using the two convince functions that knows when to fallback
to indirect access to read/write to the MDIO bus when needed.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@...natech.se>
---
 drivers/net/phy/phy.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 4f3e742907cb..89f52bb123aa 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -342,9 +342,12 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
 		if (mdio_phy_id_is_c45(mii_data->phy_id)) {
 			prtad = mdio_phy_id_prtad(mii_data->phy_id);
 			devad = mdio_phy_id_devad(mii_data->phy_id);
-			ret = mdiobus_c45_read(phydev->mdio.bus, prtad, devad,
-					       mii_data->reg_num);
 
+			mutex_lock(&phydev->mdio.bus->mdio_lock);
+			ret = mmd_phy_read(phydev->mdio.bus, prtad,
+					   phydev->is_c45, devad,
+					   mii_data->reg_num);
+			mutex_unlock(&phydev->mdio.bus->mdio_lock);
 		} else {
 			ret = mdiobus_read(phydev->mdio.bus, mii_data->phy_id,
 					   mii_data->reg_num);
@@ -403,11 +406,14 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
 			}
 		}
 
-		if (mdio_phy_id_is_c45(mii_data->phy_id))
-			mdiobus_c45_write(phydev->mdio.bus, prtad, devad,
-					  mii_data->reg_num, val);
-		else
+		if (mdio_phy_id_is_c45(mii_data->phy_id)) {
+			mutex_lock(&phydev->mdio.bus->mdio_lock);
+			mmd_phy_write(phydev->mdio.bus, prtad, phydev->is_c45,
+				      devad, mii_data->reg_num, val);
+			mutex_unlock(&phydev->mdio.bus->mdio_lock);
+		} else {
 			mdiobus_write(phydev->mdio.bus, prtad, devad, val);
+		}
 
 		if (prtad == phydev->mdio.addr &&
 		    devad == MII_BMCR &&
-- 
2.46.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ