[PATCH] phy: realtek: usb: fix the USB 2.0 PHY's port range check

From: Joshua Scott

Date: Tue Nov 03 2026 - 17:18:04 EST


rtk_phy_toggle() checks the port number before using it to index the
phy_parameter array, which has num_phy entries. Ports are numbered from
zero, so the check should reject port == num_phy, but it only rejects
ports greater than num_phy. Fix the off-by-one.

Found by code inspection.

Fixes: eeda494542e5 ("phy: realtek: usb: add new driver for the Realtek RTD SoC USB 2.0 PHY")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Joshua Scott <joshua.scott@xxxxxxxxxxxxxxxxxxx>
---
Prepared with the help of Claude Code (claude-opus-5-5), which drafted
the change and changelog. I reviewed it and tested it on an RTL9311B
board, where USB devices still connect and disconnect normally.

drivers/phy/realtek/phy-rtk-usb2.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/phy/realtek/phy-rtk-usb2.c b/drivers/phy/realtek/phy-rtk-usb2.c
index 1f08b151d90a..e43ad5fa6d64 100644
--- a/drivers/phy/realtek/phy-rtk-usb2.c
+++ b/drivers/phy/realtek/phy-rtk-usb2.c
@@ -670,7 +670,7 @@ static void rtk_phy_toggle(struct rtk_phy *rtk_phy, bool connect, int port)
{
int index = port;

- if (index > rtk_phy->num_phy) {
+ if (index >= rtk_phy->num_phy) {
dev_err(rtk_phy->dev, "%s: The port=%d is not in usb phy (num_phy=%d)\n",
__func__, index, rtk_phy->num_phy);
return;

base-commit: cbbddb6b08cc9900a87cccaa9b22bbe06aa4f50a
--
2.53.0