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

Stanley Chang[昌育德] stanley_chang at realtek.com
Wed Nov 4 22:12:43 PST 2026


Hi Joshua,


> 
> 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 at vger.kernel.org
> Signed-off-by: Joshua Scott <joshua.scott at alliedtelesis.co.nz>
> ---
> 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;

Reviewed-by: Stanley Chang <stanley_chang at realtek.com>


Thanks,
Stanley


More information about the linux-phy mailing list