Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v3] net: phy: realtek: return MDIO read errors from hwmon
@ 2026-11-08 21:13 Hleb Shauchenka via B4 Relay
  2026-11-12  1:10 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Hleb Shauchenka via B4 Relay @ 2026-11-08 21:13 UTC (permalink / raw)
  To: Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Hleb Shauchenka

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>



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next v3] net: phy: realtek: return MDIO read errors from hwmon
  2026-11-08 21:13 [PATCH net-next v3] net: phy: realtek: return MDIO read errors from hwmon Hleb Shauchenka via B4 Relay
@ 2026-11-12  1:10 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-12  1:10 UTC (permalink / raw)
  To: Hleb Shauchenka
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, netdev,
	linux-kernel

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-12  1:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-08 21:13 [PATCH net-next v3] net: phy: realtek: return MDIO read errors from hwmon Hleb Shauchenka via B4 Relay
2026-11-12  1:10 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox