From 2117e7c78acbee922539888d6567fa57e4a575ac Mon Sep 17 00:00:00 2001 From: Heikki Krogerus Date: Tue, 5 Apr 2022 16:48:23 +0300 Subject: [PATCH] BACKPORT: usb: typec: ucsi: Fix reuse of completion structure The role swapping completion variable is reused, so it needs to be reinitialised every time. Otherwise it will be marked as done after the first time it's used and completing immediately. Bug: 254441685 Link: https://lore.kernel.org/linux-usb/20220325203959.GA19752@jackp-linux.qualcomm.com/ Fixes: 6df475f804e6 ("usb: typec: ucsi: Start using struct typec_operations") Cc: stable@vger.kernel.org Reported-and-suggested-by: Jack Pham Signed-off-by: Heikki Krogerus Link: https://lore.kernel.org/r/20220405134824.68067-2-heikki.krogerus@linux.intel.com Signed-off-by: Greg Kroah-Hartman (cherry picked from commit e25adcca917d7e4cdc1dc6444d0692ffda7594bf) Signed-off-by: Lee Jones Change-Id: I2213ab8733a17495198c09fbf990ecc9de991ab2 --- drivers/usb/typec/ucsi/ucsi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 96ef4fc0bcf0..6da0ce066785 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -739,6 +739,8 @@ static int ucsi_dr_swap(struct typec_port *port, enum typec_data_role role) role == TYPEC_HOST)) goto out_unlock; + reinit_completion(&con->complete); + UCSI_CMD_SET_UOR(ctrl, con, role); ret = ucsi_role_cmd(con, &ctrl); if (ret < 0) @@ -774,6 +776,8 @@ static int ucsi_pr_swap(struct typec_port *port, enum typec_role role) if (con->status.pwr_dir == role) goto out_unlock; + reinit_completion(&con->complete); + UCSI_CMD_SET_PDR(ctrl, con, role); ret = ucsi_role_cmd(con, &ctrl); if (ret < 0)