🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Hleb Shauchenka via B4 Relay Sun, 08 Nov 2026 21:13
[PATCH net-next v3] net: phy: realtek: return MDIO read errors from hwmon
#12847
Author: Hleb Shauchenka via B4 Relay
Date: Sun, 08 Nov 2026 21:13
65 lines
12946 bytes
From: Hleb Shauchenka <me@marleb.org>

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@marleb.org>
---
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@marleb.org

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@marleb.org
---
 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@marleb.org>
Re: [PATCH net-next v3] net: phy: realtek: return MDIO read errors from hwmon
#14809
Author: patchwork-bot+netdevbpf
Date: Thu, 12 Nov 2026 01:10
24 lines
8619 bytes
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Sun, 08 Nov 2026 22:13:45 +0100 you wrote:
> From: Hleb Shauchenka <me@marleb.org>
> 
> 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.
> 
> [...]

Here is the summary with links:
  - [net-next,v3] net: phy: realtek: return MDIO read errors from hwmon
    https://git.kernel.org/netdev/net-next/c/d5b5ab50d2f6

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads