Skip to content

Commit 65ba8ce

Browse files
Heikki Krogerusgregkh
authored andcommitted
usb: typec: ucsi: Fix a deadlock in ucsi_send_command_common()
The function returns with the ppm_lock held if the PPM is busy or there's an error. Reported-and-tested-by: Luciano Coelho <luciano.coelho@intel.com> Fixes: 5e9c166 ("usb: typec: ucsi: rework command execution functions") Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reported-by: Luciano Coelho <luciano.coelho@intel.com> Signed-off-by: Luca Coelho <luciano.coelho@intel.com> Link: https://lore.kernel.org/r/20240806112029.2984319-1-heikki.krogerus@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent becac61 commit 65ba8ce

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,10 @@ static int ucsi_send_command_common(struct ucsi *ucsi, u64 cmd,
238238
mutex_lock(&ucsi->ppm_lock);
239239

240240
ret = ucsi_run_command(ucsi, cmd, &cci, data, size, conn_ack);
241-
if (cci & UCSI_CCI_BUSY) {
242-
ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false);
243-
return ret ? ret : -EBUSY;
244-
}
245-
246-
if (cci & UCSI_CCI_ERROR)
247-
return ucsi_read_error(ucsi, connector_num);
241+
if (cci & UCSI_CCI_BUSY)
242+
ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false) ?: -EBUSY;
243+
else if (cci & UCSI_CCI_ERROR)
244+
ret = ucsi_read_error(ucsi, connector_num);
248245

249246
mutex_unlock(&ucsi->ppm_lock);
250247
return ret;

0 commit comments

Comments
 (0)