aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/pending-5.15/726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2023-04-23 18:46:02 +0100
committerDaniel Golle <daniel@makrotopia.org>2023-04-24 03:16:26 +0100
commit6d33afd2b6b0b94c406141884410fee3dc4e08c3 (patch)
treee8b5f458785994c0e76c291c710ab79aaa8dc3b0 /target/linux/generic/pending-5.15/726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch
parent0601f7134d5f86f75997453eb30590b0f578cbfb (diff)
downloadupstream-6d33afd2b6b0b94c406141884410fee3dc4e08c3.tar.gz
upstream-6d33afd2b6b0b94c406141884410fee3dc4e08c3.tar.bz2
upstream-6d33afd2b6b0b94c406141884410fee3dc4e08c3.zip
kernel: net: phy: realtek: fix NULL pointer dereference
The previous attempt to replace an open coded paged read in the RealTek Ethernet PHY driver was too naive and resulted in breaking the r8169 PCIe Ethernet driver which also makes use of the RealTek Ethernet PHY driver. Fix this by instead of using the (not yet populated) paged operations rather use rtl821x_write_page and protect the whole paged read operation using the MDIO bus mutex. Fixes: 998b973157 ("kernel: net: phy: realtek: improve RealTek 2.5G PHY driver") Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'target/linux/generic/pending-5.15/726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch')
-rw-r--r--target/linux/generic/pending-5.15/726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch35
1 files changed, 35 insertions, 0 deletions
diff --git a/target/linux/generic/pending-5.15/726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch b/target/linux/generic/pending-5.15/726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch
new file mode 100644
index 0000000000..31f0622327
--- /dev/null
+++ b/target/linux/generic/pending-5.15/726-net-phy-realtek-make-sure-paged-read-is-protected-by.patch
@@ -0,0 +1,35 @@
+From 4dd2cc9b91ecb25f278a2c55e07e6455e9000e6b Mon Sep 17 00:00:00 2001
+From: Daniel Golle <daniel@makrotopia.org>
+Date: Sat, 22 Apr 2023 01:21:14 +0100
+Subject: [PATCH] net: phy: realtek: make sure paged read is protected by mutex
+
+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@makrotopia.org>
+---
+ drivers/net/phy/realtek.c | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+--- a/drivers/net/phy/realtek.c
++++ b/drivers/net/phy/realtek.c
+@@ -727,9 +727,11 @@ static bool rtlgen_supports_2_5gbps(stru
+ {
+ 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;
+ }