[PATCH] net: phy: realtek: make sure paged read is protected by mutex

From: Daniel Golle
Date: Sun Apr 23 2023 - 13:47:45 EST


As we cannot rely on phy_read_paged function before the PHY is
identified, the paged read in rtlgen_supports_2_5gbps needs to be open
coded as it is being called by the match_phy_device function, ie. before
.read_page and .write_page have been populated.

Make sure it is also protected by the MDIO bus mutex and use
rtl821x_write_page instead of 3 individually locked MDIO bus operations.

Signed-off-by: Daniel Golle <daniel@xxxxxxxxxxxxxx>
---
drivers/net/phy/realtek.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index f97b5e49fae5..c27ec4e99fc2 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -735,9 +735,11 @@ static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
{
int val;

- phy_write(phydev, RTL821x_PAGE_SELECT, 0xa61);
- val = phy_read(phydev, 0x13);
- phy_write(phydev, RTL821x_PAGE_SELECT, 0);
+ mutex_lock(&phydev->mdio.bus->mdio_lock);
+ rtl821x_write_page(phydev, 0xa61);
+ val = __phy_read(phydev, 0x13);
+ rtl821x_write_page(phydev, 0);
+ mutex_unlock(&phydev->mdio.bus->mdio_lock);

return val >= 0 && val & RTL_SUPPORTS_2500FULL;
}
--
2.40.0