]> Git Repo - linux.git/commitdiff
usb: typec: tcpm: enforce ready state when queueing alt mode vdm
authorRD Babiera <[email protected]>
Tue, 23 Apr 2024 20:23:57 +0000 (20:23 +0000)
committerGreg Kroah-Hartman <[email protected]>
Tue, 30 Apr 2024 17:44:36 +0000 (19:44 +0200)
Before sending Enter Mode for an Alt Mode, there is a gap between Discover
Modes and the Alt Mode driver queueing the Enter Mode VDM for the port
partner to send a message to the port.

If this message results in unregistering Alt Modes such as in a DR_SWAP,
then the following deadlock can occur with respect to the DisplayPort Alt
Mode driver:
1. The DR_SWAP state holds port->lock. Unregistering the Alt Mode driver
results in a cancel_work_sync() that waits for the current dp_altmode_work
to finish.
2. dp_altmode_work makes a call to tcpm_altmode_enter. The deadlock occurs
because tcpm_queue_vdm_unlock attempts to hold port->lock.

Before attempting to grab the lock, ensure that the port is in a state
vdm_run_state_machine can run in. Alt Mode unregistration will not occur
in these states.

Fixes: 03eafcfb60c0 ("usb: typec: tcpm: Add tcpm_queue_vdm_unlocked() helper")
Cc: [email protected]
Signed-off-by: RD Babiera <[email protected]>
Reviewed-by: Heikki Krogerus <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
drivers/usb/typec/tcpm/tcpm.c

index 77e632ea6872111b36e56684ad28a411b842cf12..53c1f308ebd7ce98919e6f36fbae6af2f2fa466e 100644 (file)
@@ -1564,6 +1564,10 @@ static void tcpm_queue_vdm(struct tcpm_port *port, const u32 header,
 static void tcpm_queue_vdm_unlocked(struct tcpm_port *port, const u32 header,
                                    const u32 *data, int cnt, enum tcpm_transmit_type tx_sop_type)
 {
+       if (port->state != SRC_READY && port->state != SNK_READY &&
+           port->state != SRC_VDM_IDENTITY_REQUEST)
+               return;
+
        mutex_lock(&port->lock);
        tcpm_queue_vdm(port, header, data, cnt, tx_sop_type);
        mutex_unlock(&port->lock);
This page took 0.062884 seconds and 4 git commands to generate.