Skip to contentSkip to conversation

net: dsa: realtek: rtl8365mb: fix mode mask calculation

PATCH Applied Mieczyslaw Nalewaj 3 participants 3 messages Apr 19 – Apr 23 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 1/1 net: dsa: realtek: rtl8365mb: fix mode mask calculation

The RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK macro was shifting the 4-bit mask (0xF) by only (_extint % 2) bits instead of (_extint % 2) * 4. This caused the mask to overlap with the adjacent nibble when configuring odd-numbered external interfaces, selecting the wrong bits entirely.

Align the shift calculation with the existing ...MODE_OFFSET macro.

Fixes 4af2950c50c8 ("net: dsa: realtek-smi: add rtl8365mb subdriver for RTL8365MB-VC")
---
 drivers/net/dsa/realtek/rtl8365mb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/realtek/rtl8365mb.c +1 -1
index ad7044b295ec..b85c99216648 100644
@@ -216,7 +216,7 @@
 		 (_extint) == 2 ? RTL8365MB_DIGITAL_INTERFACE_SELECT_REG1 : \
 		 0x0)
 #define   RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK(_extint) \
-		(0xF << (((_extint) % 2)))
+		(0xF << (((_extint) % 2) * 4))
 #define   RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_OFFSET(_extint) \
 		(((_extint) % 2) * 4)
 
Signature · 1 line
2.53.0
#2 lore raw
Quoted 6 lines

The RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK macro was shifting the 4-bit mask (0xF) by only (_extint % 2) bits instead of (_extint % 2) * 4. This caused the mask to overlap with the adjacent nibble when configuring odd-numbered external interfaces, selecting the wrong bits entirely.

Quoted 6 lines

Align the shift calculation with the existing ...MODE_OFFSET macro.

Fixes 4af2950c50c8 ("net: dsa: realtek-smi: add rtl8365mb subdriver for RTL8365MB-VC")

This bug specifically affected ext1 (Port 6) for all digital interface modes except DISABLED (0x0) and RGMII (0x1).

The error caused the mask for ext1 to overlap with the adjacent nibble of ext0. Since ext0 is currently unused by all supported devices in this family, the incorrect mask was zeroing bits that were already expected to be zero, masking the failure.

However, for ext1, the incorrect shift left the effective mask with only a single bit (bit 4) instead of the full 4-bit nibble (bits 4-7). This meant the driver could only successfully write values 0x0 or 0x1. Any mode requiring bits [7:5] (such as MII, RMII, or HSGMII) would have been effectively written as 0x0 or 0x1, breaking those configurations.

The original chip for this driver, RTL8365MB-VC, does utilize ext1, but as the driver currently only implements RGMII mode, the hardware result remained coincidentally correct:

Before patch: (0x0001 << 4) & 0x001E = 0x0010
After patch: (0x0001 << 4) & 0x00F0 = 0x0010

Tests on my device, TP-Link Archer C5v4, show no problem before and no regressions, as ext1/port6 is not connected on that specific hardware.

Backporting note: There is no strict need to backport this fix to stable trees, as only the RGMII mode was actually implemented and it happened to work despite the logical error.

Regards,

Luiz

#3 lore raw
In reply to Mieczyslaw Nalewaj
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Sun, 19 Apr 2026 21:37:07 +0200 you wrote:

The RTL8365MB_DIGITAL_INTERFACE_SELECT_MODE_MASK macro was shifting the 4-bit mask (0xF) by only (_extint % 2) bits instead of (_extint % 2) * 4. This caused the mask to overlap with the adjacent nibble when configuring odd-numbered external interfaces, selecting the wrong bits entirely.

Align the shift calculation with the existing ...MODE_OFFSET macro.

[...]

Here is the summary with links:
- [v2] net: dsa: realtek: rtl8365mb: fix mode mask calculation

    https://git.kernel.org/netdev/net/c/0c078021d386

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html