Linux-PHY Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sebastian Reichel" <sebastian.reichel@collabora.com>
Cc: linux-phy@lists.infradead.org, devicetree@vger.kernel.org,
	olteanv@gmail.com, conor+dt@kernel.org, robh@kernel.org,
	vkoul@kernel.org, neil.armstrong@linaro.org
Subject: Re: [PATCH v5 17/18] phy: rockchip: usbdp: Support going from DP-only mode to USB mode
Date: Fri, 12 Jun 2026 17:08:18 +0000	[thread overview]
Message-ID: <20260612170819.29A4F1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260612-rockchip-usbdp-cleanup-v5-17-efc83069869f@collabora.com>

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [Medium] The return value of `rk_udphy_power_on()` is silently ignored during Type-C mux state transitions.
- [Medium] The `usb_in_use` flag is permanently left as `true` if `rk_udphy_power_on()` fails during USB PHY initialization.

Pre-existing issues:
- [High] The `UDPHY_MODE_USB` bit in `udphy->status` is permanently leaked if `rk_udphy_usb3_phy_exit()` is called while the Type-C mux is currently in DP-only mode.
- [High] Failing to reinitialize the PHY after a transient error masks subsequent failures and reports false success.
--

commit 3ea1c2acafe2e85bbef04dfbb4e06950b88402b0
Author: Sebastian Reichel <sebastian.reichel@collabora.com>

phy: rockchip: usbdp: Support going from DP-only mode to USB mode

When a USB-C adapter, which maps all Superspeed lanes to DP is plugged
in, the USB support is disabled in the PHY. When the adapter is
unplugged and a different adapter with USB functionality is plugged in
afterwards, USB functionality is not restored as the USB controller
keeps the PHY enabled for the entire time.

> diff --git a/drivers/phy/rockchip/phy-rockchip-usbdp.c b/drivers/phy/rockchip/phy-rockchip-usbdp.c
> --- a/drivers/phy/rockchip/phy-rockchip-usbdp.c
> +++ b/drivers/phy/rockchip/phy-rockchip-usbdp.c

[ ... ]

> @@ -1015,6 +1016,9 @@ static int rk_udphy_power_on(struct rk_udphy *udphy, u8 mode)
>  		ret = rk_udphy_init(udphy);
>  		if (ret)
>  			return ret;

[Severity: High]
This is a pre-existing issue, but if rk_udphy_init() fails here, 
udphy->phy_needs_reinit was already set to false earlier in the block.

Will subsequent calls to rk_udphy_power_on() skip initialization and 
falsely return success while the hardware remains broken? 

Should phy_needs_reinit be restored to true on the error path?

> +
> +		if (udphy->mode & UDPHY_MODE_USB)
> +			rk_udphy_u3_port_disable(udphy, false);
>  	}
>  
>  	udphy->status |= mode;

[ ... ]

> @@ -1278,6 +1282,15 @@ static int rk_udphy_usb3_phy_init(struct phy *phy)
>  
>  	guard(mutex)(&udphy->mutex);
>  
> +	udphy->usb_in_use = true;
> +
>  	/* DP only or high-speed, disable U3 port */
>  	if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs) {
>  		rk_udphy_u3_port_disable(udphy, true);
>  		return 0;
>  	}
>  
>  	ret = rk_udphy_power_on(udphy, UDPHY_MODE_USB);
>  
>  	return ret;
>  }

[Severity: Medium]
If rk_udphy_power_on() fails and returns an error, usb_in_use remains true. 

Will this cause rk_udphy_typec_mux_set() to incorrectly attempt to power on 
the USB PHY later, despite the USB controller not actively using it?

Should the flag be reverted to false on the error path?

> @@ -1295,6 +1301,13 @@ static int rk_udphy_usb3_phy_exit(struct phy *phy)
>  
>  	guard(mutex)(&udphy->mutex);
>  
> +	udphy->usb_in_use = false;
> +
>  	/* DP only or high-speed */
>  	if (!(udphy->mode & UDPHY_MODE_USB) || udphy->hs)
>  		return 0;

[Severity: High]
This isn't a bug introduced by this patch, but if the Type-C mode 
transitions to DP-only, udphy->mode loses the UDPHY_MODE_USB bit. 

When rk_udphy_usb3_phy_exit() is subsequently called, it checks 
!(udphy->mode & UDPHY_MODE_USB) and returns 0 early, skipping 
rk_udphy_power_off(). 

Does this result in a permanent leak of the PHY's clocks and resets, since 
udphy->status never clears the UDPHY_MODE_USB bit?

>  
>  	rk_udphy_power_off(udphy, UDPHY_MODE_USB);
>  
>  	return 0;
>  }

[ ... ]

> @@ -1325,8 +1334,20 @@ static int rk_udphy_typec_mux_set(struct typec_mux_dev *mux,
>  
>  	guard(mutex)(&udphy->mutex);
>  
> +	old_mode = udphy->mode;
> +
>  	rk_udphy_set_typec_state(udphy, state->mode);
>  
> +	/*
> +	 * If the new mode includes USB but the old one didn't (e.g. leaving
> +	 * DP-only), and the USB PHY was already initialized by the USB
> +	 * controller, we need to power on the USB side now since no
> +	 * subsequent phy_init call will come from the controller.
> +	 */
> +	if ((udphy->mode & UDPHY_MODE_USB) && !(old_mode & UDPHY_MODE_USB) &&
> +	    udphy->usb_in_use && !udphy->hs)
> +		rk_udphy_power_on(udphy, UDPHY_MODE_USB);

[Severity: Medium]
Does this code discard the return value of rk_udphy_power_on()? 

If initialization fails, the error is ignored and the driver reports success 
for the Type-C mux state transition, which could leave the USB functionality 
silently broken. 

Should this check the return value and at least log or propagate the error?

> +
>  	return 0;
>  }

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260612-rockchip-usbdp-cleanup-v5-0-efc83069869f@collabora.com?part=17

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

  reply	other threads:[~2026-06-12 17:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-12 16:21 [PATCH v5 00/18] phy: rockchip: usbdp: Fixes, DP 1-lane support and cleanups Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 01/18] dt-bindings: phy: rockchip-usbdp: add improved ports scheme Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 02/18] phy: rockchip: usbdp: Do not lose USB3 PHY status Sebastian Reichel
2026-06-12 16:38   ` sashiko-bot
2026-06-12 16:21 ` [PATCH v5 03/18] phy: rockchip: usbdp: Keep clocks running on PHY re-init Sebastian Reichel
2026-06-12 16:41   ` sashiko-bot
2026-06-12 16:21 ` [PATCH v5 04/18] phy: rockchip: usbdp: Amend SSC modulation deviation Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 05/18] phy: rockchip: usbdp: Fix LFPS detect threshold control Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 06/18] phy: rockchip: usbdp: Add missing mode_change update Sebastian Reichel
2026-06-12 16:46   ` sashiko-bot
2026-06-12 16:21 ` [PATCH v5 07/18] phy: rockchip: usbdp: Support single-lane DP Sebastian Reichel
2026-06-12 16:55   ` sashiko-bot
2026-06-12 16:21 ` [PATCH v5 08/18] phy: rockchip: usbdp: Rename DP lane functions Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 09/18] phy: rockchip: usbdp: Use FIELD_PREP_WM16_CONST Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 10/18] phy: rockchip: usbdp: Cleanup DP lane selection function Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 11/18] phy: rockchip: usbdp: Register DP aux bridge Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 12/18] phy: rockchip: usbdp: Drop DP HPD handling Sebastian Reichel
2026-06-12 16:53   ` sashiko-bot
2026-06-12 16:21 ` [PATCH v5 13/18] phy: rockchip: usbdp: Rename mode_change to phy_needs_reinit Sebastian Reichel
2026-06-12 16:52   ` sashiko-bot
2026-06-12 16:21 ` [PATCH v5 14/18] phy: rockchip: usbdp: Re-init the PHY on orientation change Sebastian Reichel
2026-06-12 17:03   ` sashiko-bot
2026-06-12 16:21 ` [PATCH v5 15/18] phy: rockchip: usbdp: Factor out lane_mux_sel setup Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 16/18] phy: rockchip: usbdp: Use guard functions for mutex Sebastian Reichel
2026-06-12 16:21 ` [PATCH v5 17/18] phy: rockchip: usbdp: Support going from DP-only mode to USB mode Sebastian Reichel
2026-06-12 17:08   ` sashiko-bot [this message]
2026-06-12 16:21 ` [PATCH v5 18/18] phy: rockchip: usbdp: Add some extra debug messages Sebastian Reichel
2026-06-12 17:06   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260612170819.29A4F1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-phy@lists.infradead.org \
    --cc=neil.armstrong@linaro.org \
    --cc=olteanv@gmail.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sebastian.reichel@collabora.com \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox