[PATCH net-next v3] net: phy: realtek: return MDIO read errors from hwmon

From: Hleb Shauchenka via B4 Relay

Date: Sun Nov 08 2026 - 16:14:47 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, so that readers of the hwmon attributes see
the failure rather than a plausible but wrong temperature.

Signed-off-by: Hleb Shauchenka <me@xxxxxxxxxx>
---
This patch was prepared with AI assistance (Claude Opus 5.5), after an
AI review of v1 pointed out the problem. It is build-tested only: I
could not provoke a failed MDIO read on hardware.
---
Changes in v3:
- Drop the binding and HWMON_C_REGISTER_TZ patches: their only user is
out-of-tree code.
- Send this patch alone, without the Fixes tag.
- Move the AI note below the ---.
- Link to v2: https://patch.msgid.link/20261107-realtek-hwmon-tz-v2-0-6b9a69d44470@xxxxxxxxxx

Changes in v2:
- New patch, in a series with two others.
- Link to v1: https://patch.msgid.link/20261103-realtek-hwmon-tz-v1-1-e672723c58cb@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;

---
base-commit: fa5196392691051963726787944db872420dfa75
change-id: 20261103-realtek-hwmon-tz-95237a921bf9

Best regards,
--
Hleb Shauchenka <me@xxxxxxxxxx>