Skip to content

Commit

Permalink
usb: typec: ucsi: Fix a deadlock in ucsi_send_command_common()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Heikki Krogerus authored and Greg Kroah-Hartman committed Aug 7, 2024
1 parent becac61 commit 65ba8ce
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions drivers/usb/typec/ucsi/ucsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,10 @@ static int ucsi_send_command_common(struct ucsi *ucsi, u64 cmd,
mutex_lock(&ucsi->ppm_lock);

ret = ucsi_run_command(ucsi, cmd, &cci, data, size, conn_ack);
if (cci & UCSI_CCI_BUSY) {
ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false);
return ret ? ret : -EBUSY;
}

if (cci & UCSI_CCI_ERROR)
return ucsi_read_error(ucsi, connector_num);
if (cci & UCSI_CCI_BUSY)
ret = ucsi_run_command(ucsi, UCSI_CANCEL, &cci, NULL, 0, false) ?: -EBUSY;
else if (cci & UCSI_CCI_ERROR)
ret = ucsi_read_error(ucsi, connector_num);

mutex_unlock(&ucsi->ppm_lock);
return ret;
Expand Down

0 comments on commit 65ba8ce

Please sign in to comment.