Commit 6cbb7fc9 authored by Dmitry Baryshkov's avatar Dmitry Baryshkov Committed by Greg Kroah-Hartman

usb: typec: ucsi: reorder operations in ucsi_run_command()

Streamline control stream of ucsi_run_command(). Reorder operations so
that there is only one call to ucsi_acknowledge(), making sure that all
complete commands are acknowledged. This also makes sure that the
command is acknowledged even if reading MESSAGE_IN data returns an
error.
Tested-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://lore.kernel.org/r/20240627-ucsi-rework-interface-v4-7-289ddc6874c7@linaro.orgSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 584e8df5
...@@ -95,7 +95,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack) ...@@ -95,7 +95,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack)
static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
void *data, size_t size, bool conn_ack) void *data, size_t size, bool conn_ack)
{ {
int ret; int ret, err;
*cci = 0; *cci = 0;
...@@ -120,30 +120,24 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci, ...@@ -120,30 +120,24 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
if (!(*cci & UCSI_CCI_COMMAND_COMPLETE)) if (!(*cci & UCSI_CCI_COMMAND_COMPLETE))
return -EIO; return -EIO;
if (*cci & UCSI_CCI_NOT_SUPPORTED) { if (*cci & UCSI_CCI_NOT_SUPPORTED)
if (ucsi_acknowledge(ucsi, false) < 0) err = -EOPNOTSUPP;
dev_err(ucsi->dev, else if (*cci & UCSI_CCI_ERROR)
"ACK of unsupported command failed\n"); err = -EIO;
return -EOPNOTSUPP; else
} err = 0;
if (*cci & UCSI_CCI_ERROR) {
/* Acknowledge the command that failed */
ret = ucsi_acknowledge(ucsi, false);
return ret ? ret : -EIO;
}
if (data) { if (!err && data && UCSI_CCI_LENGTH(*cci))
ret = ucsi->ops->read_message_in(ucsi, data, size); err = ucsi->ops->read_message_in(ucsi, data, size);
if (ret)
return ret;
}
ret = ucsi_acknowledge(ucsi, conn_ack); /*
* Don't ACK connection change if there was an error.
*/
ret = ucsi_acknowledge(ucsi, err ? false : conn_ack);
if (ret) if (ret)
return ret; return ret;
return 0; return err;
} }
static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num) static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment