gpio-nct5104d: fix compilation with kernel 6.6
[openwrt/openwrt.git] / target / linux / generic / pending-6.1 / 726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch
1 From 4dd2cc9b91ecb25f278a2c55e07e6455e9000e6b Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Sat, 22 Apr 2023 01:21:14 +0100
4 Subject: [PATCH] net: phy: realtek: make sure paged read is protected by mutex
5
6 As we cannot rely on phy_read_paged function before the PHY is
7 identified, the paged read in rtlgen_supports_2_5gbps needs to be open
8 coded as it is being called by the match_phy_device function, ie. before
9 .read_page and .write_page have been populated.
10
11 Make sure it is also protected by the MDIO bus mutex and use
12 rtl821x_write_page instead of 3 individually locked MDIO bus operations.
13
14 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
15 ---
16 drivers/net/phy/realtek.c | 8 +++++---
17 1 file changed, 5 insertions(+), 3 deletions(-)
18
19 --- a/drivers/net/phy/realtek.c
20 +++ b/drivers/net/phy/realtek.c
21 @@ -737,9 +737,11 @@ static bool rtlgen_supports_2_5gbps(stru
22 {
23 int val;
24
25 - phy_write(phydev, RTL821x_PAGE_SELECT, 0xa61);
26 - val = phy_read(phydev, 0x13);
27 - phy_write(phydev, RTL821x_PAGE_SELECT, 0);
28 + mutex_lock(&phydev->mdio.bus->mdio_lock);
29 + rtl821x_write_page(phydev, 0xa61);
30 + val = __phy_read(phydev, 0x13);
31 + rtl821x_write_page(phydev, 0);
32 + mutex_unlock(&phydev->mdio.bus->mdio_lock);
33
34 return val >= 0 && val & RTL_SUPPORTS_2500FULL;
35 }