staging: typec: tcpm: Add timeout when waiting for role swap completion
The Type-C protocol manager state machine could fail, which might result in role swap requests from user space to hang forever. Add a generous timeout when waiting for role swaps to complete to avoid this situation. Originally-from: Badhri Jagan Sridharan <badhri@google.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
b46a9c9095
commit
9adf9f9ee7
|
@ -3165,9 +3165,12 @@ static int tcpm_dr_set(const struct typec_capability *cap,
|
||||||
tcpm_set_state(port, DR_SWAP_SEND, 0);
|
tcpm_set_state(port, DR_SWAP_SEND, 0);
|
||||||
mutex_unlock(&port->lock);
|
mutex_unlock(&port->lock);
|
||||||
|
|
||||||
wait_for_completion(&port->swap_complete);
|
if (!wait_for_completion_timeout(&port->swap_complete,
|
||||||
|
msecs_to_jiffies(PD_ROLE_SWAP_TIMEOUT)))
|
||||||
|
ret = -ETIMEDOUT;
|
||||||
|
else
|
||||||
|
ret = port->swap_status;
|
||||||
|
|
||||||
ret = port->swap_status;
|
|
||||||
goto swap_unlock;
|
goto swap_unlock;
|
||||||
|
|
||||||
port_unlock:
|
port_unlock:
|
||||||
|
@ -3222,9 +3225,12 @@ static int tcpm_pr_set(const struct typec_capability *cap,
|
||||||
tcpm_set_state(port, PR_SWAP_SEND, 0);
|
tcpm_set_state(port, PR_SWAP_SEND, 0);
|
||||||
mutex_unlock(&port->lock);
|
mutex_unlock(&port->lock);
|
||||||
|
|
||||||
wait_for_completion(&port->swap_complete);
|
if (!wait_for_completion_timeout(&port->swap_complete,
|
||||||
|
msecs_to_jiffies(PD_ROLE_SWAP_TIMEOUT)))
|
||||||
|
ret = -ETIMEDOUT;
|
||||||
|
else
|
||||||
|
ret = port->swap_status;
|
||||||
|
|
||||||
ret = port->swap_status;
|
|
||||||
goto swap_unlock;
|
goto swap_unlock;
|
||||||
|
|
||||||
port_unlock:
|
port_unlock:
|
||||||
|
@ -3259,9 +3265,12 @@ static int tcpm_vconn_set(const struct typec_capability *cap,
|
||||||
tcpm_set_state(port, VCONN_SWAP_SEND, 0);
|
tcpm_set_state(port, VCONN_SWAP_SEND, 0);
|
||||||
mutex_unlock(&port->lock);
|
mutex_unlock(&port->lock);
|
||||||
|
|
||||||
wait_for_completion(&port->swap_complete);
|
if (!wait_for_completion_timeout(&port->swap_complete,
|
||||||
|
msecs_to_jiffies(PD_ROLE_SWAP_TIMEOUT)))
|
||||||
|
ret = -ETIMEDOUT;
|
||||||
|
else
|
||||||
|
ret = port->swap_status;
|
||||||
|
|
||||||
ret = port->swap_status;
|
|
||||||
goto swap_unlock;
|
goto swap_unlock;
|
||||||
|
|
||||||
port_unlock:
|
port_unlock:
|
||||||
|
|
|
@ -34,7 +34,8 @@ enum typec_cc_polarity {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Time to wait for TCPC to complete transmit */
|
/* Time to wait for TCPC to complete transmit */
|
||||||
#define PD_T_TCPC_TX_TIMEOUT 100
|
#define PD_T_TCPC_TX_TIMEOUT 100 /* in ms */
|
||||||
|
#define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
|
||||||
|
|
||||||
enum tcpm_transmit_status {
|
enum tcpm_transmit_status {
|
||||||
TCPC_TX_SUCCESS = 0,
|
TCPC_TX_SUCCESS = 0,
|
||||||
|
|
Loading…
Reference in New Issue