All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] phy: rockchip-typec: fix tcphy_get_mode error case
@ 2023-01-26  0:10 Neill Kapron
  2023-01-26 16:41 ` Lee Jones
  2023-02-03 11:43 ` Vinod Koul
  0 siblings, 2 replies; 3+ messages in thread
From: Neill Kapron @ 2023-01-26  0:10 UTC (permalink / raw)
  To: Vinod Koul, Kishon Vijay Abraham I, Heiko Stuebner, Chris Zhong,
	Kever Yang, Guenter Roeck
  Cc: linux-kernel, kernel-team, Neill Kapron, Kishon Vijay Abraham I

The existing logic in tcphy_get_mode() can cause the phy to be
incorrectly configured to USB UFP or DisplayPort mode when
extcon_get_state returns an error code.

extcon_get_state() can return 0, 1, or a negative error code.

It is possible to get into the failing state with an extcon driver
which does not support the extcon connector id specified as the
second argument to extcon_get_state().

tcphy_get_mode()
->extcon_get_state()
-->find_cable_index_by_id()
--->return -EINVAL;

Fixes: e96be45cb84e ("phy: Add USB Type-C PHY driver for rk3399")
Signed-off-by: Neill Kapron <nkapron@google.com>
---
 drivers/phy/rockchip/phy-rockchip-typec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c
index d76440ae10ff..6aea512e5d4e 100644
--- a/drivers/phy/rockchip/phy-rockchip-typec.c
+++ b/drivers/phy/rockchip/phy-rockchip-typec.c
@@ -821,10 +821,10 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
 	mode = MODE_DFP_USB;
 	id = EXTCON_USB_HOST;
 
-	if (ufp) {
+	if (ufp > 0) {
 		mode = MODE_UFP_USB;
 		id = EXTCON_USB;
-	} else if (dp) {
+	} else if (dp > 0) {
 		mode = MODE_DFP_DP;
 		id = EXTCON_DISP_DP;
 
-- 
2.39.1.456.gfc5497dd1b-goog


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

* Re: [PATCH] phy: rockchip-typec: fix tcphy_get_mode error case
  2023-01-26  0:10 [PATCH] phy: rockchip-typec: fix tcphy_get_mode error case Neill Kapron
@ 2023-01-26 16:41 ` Lee Jones
  2023-02-03 11:43 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2023-01-26 16:41 UTC (permalink / raw)
  To: Neill Kapron
  Cc: Vinod Koul, Kishon Vijay Abraham I, Heiko Stuebner, Chris Zhong,
	Kever Yang, Guenter Roeck, linux-kernel, kernel-team,
	Kishon Vijay Abraham I

On Thu, 26 Jan 2023, Neill Kapron wrote:

> The existing logic in tcphy_get_mode() can cause the phy to be
> incorrectly configured to USB UFP or DisplayPort mode when
> extcon_get_state returns an error code.
> 
> extcon_get_state() can return 0, 1, or a negative error code.
> 
> It is possible to get into the failing state with an extcon driver
> which does not support the extcon connector id specified as the
> second argument to extcon_get_state().
> 
> tcphy_get_mode()
> ->extcon_get_state()
> -->find_cable_index_by_id()
> --->return -EINVAL;
> 
> Fixes: e96be45cb84e ("phy: Add USB Type-C PHY driver for rk3399")
> Signed-off-by: Neill Kapron <nkapron@google.com>
> ---
>  drivers/phy/rockchip/phy-rockchip-typec.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Good catch.

Reviewed-by: Lee Jones <lee@kernel.org>

> diff --git a/drivers/phy/rockchip/phy-rockchip-typec.c b/drivers/phy/rockchip/phy-rockchip-typec.c
> index d76440ae10ff..6aea512e5d4e 100644
> --- a/drivers/phy/rockchip/phy-rockchip-typec.c
> +++ b/drivers/phy/rockchip/phy-rockchip-typec.c
> @@ -821,10 +821,10 @@ static int tcphy_get_mode(struct rockchip_typec_phy *tcphy)
>  	mode = MODE_DFP_USB;
>  	id = EXTCON_USB_HOST;
>  
> -	if (ufp) {
> +	if (ufp > 0) {
>  		mode = MODE_UFP_USB;
>  		id = EXTCON_USB;
> -	} else if (dp) {
> +	} else if (dp > 0) {
>  		mode = MODE_DFP_DP;
>  		id = EXTCON_DISP_DP;
>  
> -- 
> 2.39.1.456.gfc5497dd1b-goog

-- 
Lee Jones [李琼斯]

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

* Re: [PATCH] phy: rockchip-typec: fix tcphy_get_mode error case
  2023-01-26  0:10 [PATCH] phy: rockchip-typec: fix tcphy_get_mode error case Neill Kapron
  2023-01-26 16:41 ` Lee Jones
@ 2023-02-03 11:43 ` Vinod Koul
  1 sibling, 0 replies; 3+ messages in thread
From: Vinod Koul @ 2023-02-03 11:43 UTC (permalink / raw)
  To: Neill Kapron
  Cc: Kishon Vijay Abraham I, Heiko Stuebner, Chris Zhong, Kever Yang,
	Guenter Roeck, linux-kernel, kernel-team, Kishon Vijay Abraham I

On 26-01-23, 00:10, Neill Kapron wrote:
> The existing logic in tcphy_get_mode() can cause the phy to be
> incorrectly configured to USB UFP or DisplayPort mode when
> extcon_get_state returns an error code.
> 
> extcon_get_state() can return 0, 1, or a negative error code.
> 
> It is possible to get into the failing state with an extcon driver
> which does not support the extcon connector id specified as the
> second argument to extcon_get_state().
> 
> tcphy_get_mode()
> ->extcon_get_state()
> -->find_cable_index_by_id()
> --->return -EINVAL;

Applied, thanks

-- 
~Vinod

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

end of thread, other threads:[~2023-02-03 11:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-26  0:10 [PATCH] phy: rockchip-typec: fix tcphy_get_mode error case Neill Kapron
2023-01-26 16:41 ` Lee Jones
2023-02-03 11:43 ` Vinod Koul

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.