Skip to content

Commit 59f9ee3

Browse files
ChiYuan Huanggregkh
authored andcommitted
usb: typec: tcpm: Fix altmode re-registration causes sysfs create fail
commit 36f7847 upstream. There's the altmode re-registeration issue after data role swap (DR_SWAP). Comparing to USBPD 2.0, in USBPD 3.0, it loose the limit that only DFP can initiate the VDM command to get partner identity information. For a USBPD 3.0 UFP device, it may already get the identity information from its port partner before DR_SWAP. If DR_SWAP send or receive at the mean time, 'send_discover' flag will be raised again. It causes discover identify action restart while entering ready state. And after all discover actions are done, the 'tcpm_register_altmodes' will be called. If old altmode is not unregistered, this sysfs create fail can be found. In 'DR_SWAP_CHANGE_DR' state case, only DFP will unregister altmodes. For UFP, the original altmodes keep registered. This patch fix the logic that after DR_SWAP, 'tcpm_unregister_altmodes' must be called whatever the current data role is. Reviewed-by: Macpaul Lin <[email protected]> Fixes: ae8a2ca ("usb: typec: Group all TCPCI/TCPM code together") Reported-by: TommyYl Chen <[email protected]> Cc: [email protected] Signed-off-by: ChiYuan Huang <[email protected]> Acked-by: Heikki Krogerus <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a1c8a5c commit 59f9ee3

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

drivers/usb/typec/tcpm/tcpm.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,14 +4527,13 @@ static void run_state_machine(struct tcpm_port *port)
45274527
tcpm_set_state(port, ready_state(port), 0);
45284528
break;
45294529
case DR_SWAP_CHANGE_DR:
4530-
if (port->data_role == TYPEC_HOST) {
4531-
tcpm_unregister_altmodes(port);
4530+
tcpm_unregister_altmodes(port);
4531+
if (port->data_role == TYPEC_HOST)
45324532
tcpm_set_roles(port, true, port->pwr_role,
45334533
TYPEC_DEVICE);
4534-
} else {
4534+
else
45354535
tcpm_set_roles(port, true, port->pwr_role,
45364536
TYPEC_HOST);
4537-
}
45384537
tcpm_ams_finish(port);
45394538
tcpm_set_state(port, ready_state(port), 0);
45404539
break;

0 commit comments

Comments
 (0)