Skip to contentSkip to conversation

phy: rockchip-typec: fix tcphy_get_mode error case

PATCH Applied Neill Kapron 3 participants 3 messages Jan 26, 2023 – Feb 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 phy: rockchip-typec: fix tcphy_get_mode error case

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")
---
 drivers/phy/rockchip/phy-rockchip-typec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/phy/rockchip/phy-rockchip-typec.c +2 -2
index d76440ae10ff..6aea512e5d4e 100644
@@ -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;
 
Signature · 1 line
2.39.1.456.gfc5497dd1b-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Neill Kapron

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;

Quoted 5 lines
Fixes e96be45cb84e ("phy: Add USB Type-C PHY driver for rk3399")
---
 drivers/phy/rockchip/phy-rockchip-typec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Good catch.

Quoted 19 lines
drivers/phy/rockchip/phy-rockchip-typec.c +2 -2
index d76440ae10ff..6aea512e5d4e 100644
@@ -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;
 
Signature · 1 line
2.39.1.456.gfc5497dd1b-goog
Signature · 1 line
Lee Jones [李琼斯]
maintainer Applied
#2 lore raw
In reply to Neill Kapron
Quoted 6 lines · Neill Kapron

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.

Quoted 8 lines

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

Signature · 1 line
~Vinod