[PATCH net-next v2 2/3] net: phy: realtek: return MDIO read errors from hwmon

From: Hleb Shauchenka via B4 Relay

Date: Sat Nov 07 2026 - 12:03:10 EST


From: Hleb Shauchenka <me@xxxxxxxxxx>

rtl822x_hwmon_read() masks or shifts the value returned by
phy_read_mmd() without checking it and returns success, so a failed
MDIO read is reported as a temperature: -EIO reads as -2.5 C and
-ETIMEDOUT as -55 C.

Return the error instead. Once the sensor feeds a thermal zone, the
thermal core then keeps its previous state rather than acting on a
bogus reading.

The problem was found by an AI review of the previous posting, and
this patch was prepared with AI assistance (Claude Opus 5.5). It is
build-tested only: I could not provoke a failed MDIO read on hardware.

Fixes: 33700ca45b7d ("net: phy: realtek: add hwmon support for temp sensor on RTL822x")
Signed-off-by: Hleb Shauchenka <me@xxxxxxxxxx>
---
drivers/net/phy/realtek/realtek_hwmon.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/realtek/realtek_hwmon.c b/drivers/net/phy/realtek/realtek_hwmon.c
index ac96e2d1e..b6b2806e2 100644
--- a/drivers/net/phy/realtek/realtek_hwmon.c
+++ b/drivers/net/phy/realtek/realtek_hwmon.c
@@ -30,13 +30,17 @@ static int rtl822x_hwmon_read(struct device *dev, enum hwmon_sensor_types type,

switch (attr) {
case hwmon_temp_input:
- raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSRR) & 0x3ff;
- *val = rtl822x_hwmon_get_temp(raw);
+ raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSRR);
+ if (raw < 0)
+ return raw;
+ *val = rtl822x_hwmon_get_temp(raw & 0x3ff);
break;
case hwmon_temp_max:
/* Chip reduces speed to 1G if threshold is exceeded */
- raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSSR) >> 6;
- *val = rtl822x_hwmon_get_temp(raw);
+ raw = phy_read_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_TSSR);
+ if (raw < 0)
+ return raw;
+ *val = rtl822x_hwmon_get_temp(raw >> 6);
break;
default:
return -EINVAL;

--
2.56.0