Skip to content

Commit eb5d7ff

Browse files
Heikki Krogerusgregkh
authored andcommitted
usb: typec: ucsi: Fix role swapping
All attempts to swap the roles timed out because the completion was done without releasing the port lock. Fixing that by releasing the lock before starting to wait for the completion. Link: https://lore.kernel.org/linux-usb/037de7ac-e210-bdf5-ec7a-8c0c88a0be20@gmail.com/ Fixes: ad74b86 ("usb: typec: ucsi: Preliminary support for alternate modes") Cc: stable@vger.kernel.org Reported-and-tested-by: Jia-Ju Bai <baijiaju1990@gmail.com> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Link: https://lore.kernel.org/r/20220405134824.68067-3-heikki.krogerus@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent e25adcc commit eb5d7ff

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -958,14 +958,18 @@ static int ucsi_dr_swap(struct typec_port *port, enum typec_data_role role)
958958
if (ret < 0)
959959
goto out_unlock;
960960

961+
mutex_unlock(&con->lock);
962+
961963
if (!wait_for_completion_timeout(&con->complete,
962-
msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS)))
963-
ret = -ETIMEDOUT;
964+
msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS)))
965+
return -ETIMEDOUT;
966+
967+
return 0;
964968

965969
out_unlock:
966970
mutex_unlock(&con->lock);
967971

968-
return ret < 0 ? ret : 0;
972+
return ret;
969973
}
970974

971975
static int ucsi_pr_swap(struct typec_port *port, enum typec_role role)
@@ -996,11 +1000,13 @@ static int ucsi_pr_swap(struct typec_port *port, enum typec_role role)
9961000
if (ret < 0)
9971001
goto out_unlock;
9981002

1003+
mutex_unlock(&con->lock);
1004+
9991005
if (!wait_for_completion_timeout(&con->complete,
1000-
msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS))) {
1001-
ret = -ETIMEDOUT;
1002-
goto out_unlock;
1003-
}
1006+
msecs_to_jiffies(UCSI_SWAP_TIMEOUT_MS)))
1007+
return -ETIMEDOUT;
1008+
1009+
mutex_lock(&con->lock);
10041010

10051011
/* Something has gone wrong while swapping the role */
10061012
if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) !=

0 commit comments

Comments
 (0)