Skip to content

Commit a826492

Browse files
Xu Yanggregkh
authored andcommitted
usb: typec: tcpm: fix create duplicate source-capabilities file
The kernel will dump in the below cases: sysfs: cannot create duplicate filename '/devices/virtual/usb_power_delivery/pd1/source-capabilities' 1. After soft reset has completed, an Explicit Contract negotiation occurs. The sink device will receive source capabilitys again. This will cause a duplicate source-capabilities file be created. 2. Power swap twice on a device that is initailly sink role. This will unregister existing capabilities when above cases occurs. Fixes: 8203d26 ("usb: typec: tcpm: Register USB Power Delivery Capabilities") cc: <[email protected]> Signed-off-by: Xu Yang <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6c67ed9 commit a826492

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/usb/typec/tcpm/tcpm.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4570,6 +4570,9 @@ static void run_state_machine(struct tcpm_port *port)
45704570
case SOFT_RESET:
45714571
port->message_id = 0;
45724572
port->rx_msgid = -1;
4573+
/* remove existing capabilities */
4574+
usb_power_delivery_unregister_capabilities(port->partner_source_caps);
4575+
port->partner_source_caps = NULL;
45734576
tcpm_pd_send_control(port, PD_CTRL_ACCEPT);
45744577
tcpm_ams_finish(port);
45754578
if (port->pwr_role == TYPEC_SOURCE) {
@@ -4589,6 +4592,9 @@ static void run_state_machine(struct tcpm_port *port)
45894592
case SOFT_RESET_SEND:
45904593
port->message_id = 0;
45914594
port->rx_msgid = -1;
4595+
/* remove existing capabilities */
4596+
usb_power_delivery_unregister_capabilities(port->partner_source_caps);
4597+
port->partner_source_caps = NULL;
45924598
if (tcpm_pd_send_control(port, PD_CTRL_SOFT_RESET))
45934599
tcpm_set_state_cond(port, hard_reset_state(port), 0);
45944600
else
@@ -4718,6 +4724,9 @@ static void run_state_machine(struct tcpm_port *port)
47184724
tcpm_set_state(port, SNK_STARTUP, 0);
47194725
break;
47204726
case PR_SWAP_SNK_SRC_SINK_OFF:
4727+
/* will be source, remove existing capabilities */
4728+
usb_power_delivery_unregister_capabilities(port->partner_source_caps);
4729+
port->partner_source_caps = NULL;
47214730
/*
47224731
* Prevent vbus discharge circuit from turning on during PR_SWAP
47234732
* as this is not a disconnect.

0 commit comments

Comments
 (0)