@@ -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,
void *data, size_t size, bool conn_ack)
{
- int ret;
+ int ret, err;
*cci = 0;
@@ -120,30 +120,24 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
if (!(*cci & UCSI_CCI_COMMAND_COMPLETE))
return -EIO;
- if (*cci & UCSI_CCI_NOT_SUPPORTED) {
- if (ucsi_acknowledge(ucsi, false) < 0)
- dev_err(ucsi->dev,
- "ACK of unsupported command failed\n");
- return -EOPNOTSUPP;
- }
-
- if (*cci & UCSI_CCI_ERROR) {
- /* Acknowledge the command that failed */
- ret = ucsi_acknowledge(ucsi, false);
- return ret ? ret : -EIO;
- }
+ if (*cci & UCSI_CCI_NOT_SUPPORTED)
+ err = -EOPNOTSUPP;
+ else if (*cci & UCSI_CCI_ERROR)
+ err = -EIO;
+ else
+ err = 0;
- if (data) {
- ret = ucsi->ops->read_message_in(ucsi, data, size);
- if (ret)
- return ret;
- }
+ if (!err && data && UCSI_CCI_LENGTH(*cci))
+ err = ucsi->ops->read_message_in(ucsi, data, size);
- 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)
return ret;
- return 0;
+ return err;
}
static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)