Skip to content

Commit 6cbb7fc

Browse files
lumaggregkh
authored andcommitted
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: Heikki Krogerus <[email protected]> Reviewed-by: Heikki Krogerus <[email protected]> Signed-off-by: Dmitry Baryshkov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 584e8df commit 6cbb7fc

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

drivers/usb/typec/ucsi/ucsi.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static int ucsi_acknowledge(struct ucsi *ucsi, bool conn_ack)
9595
static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
9696
void *data, size_t size, bool conn_ack)
9797
{
98-
int ret;
98+
int ret, err;
9999

100100
*cci = 0;
101101

@@ -120,30 +120,24 @@ static int ucsi_run_command(struct ucsi *ucsi, u64 command, u32 *cci,
120120
if (!(*cci & UCSI_CCI_COMMAND_COMPLETE))
121121
return -EIO;
122122

123-
if (*cci & UCSI_CCI_NOT_SUPPORTED) {
124-
if (ucsi_acknowledge(ucsi, false) < 0)
125-
dev_err(ucsi->dev,
126-
"ACK of unsupported command failed\n");
127-
return -EOPNOTSUPP;
128-
}
129-
130-
if (*cci & UCSI_CCI_ERROR) {
131-
/* Acknowledge the command that failed */
132-
ret = ucsi_acknowledge(ucsi, false);
133-
return ret ? ret : -EIO;
134-
}
123+
if (*cci & UCSI_CCI_NOT_SUPPORTED)
124+
err = -EOPNOTSUPP;
125+
else if (*cci & UCSI_CCI_ERROR)
126+
err = -EIO;
127+
else
128+
err = 0;
135129

136-
if (data) {
137-
ret = ucsi->ops->read_message_in(ucsi, data, size);
138-
if (ret)
139-
return ret;
140-
}
130+
if (!err && data && UCSI_CCI_LENGTH(*cci))
131+
err = ucsi->ops->read_message_in(ucsi, data, size);
141132

142-
ret = ucsi_acknowledge(ucsi, conn_ack);
133+
/*
134+
* Don't ACK connection change if there was an error.
135+
*/
136+
ret = ucsi_acknowledge(ucsi, err ? false : conn_ack);
143137
if (ret)
144138
return ret;
145139

146-
return 0;
140+
return err;
147141
}
148142

149143
static int ucsi_read_error(struct ucsi *ucsi, u8 connector_num)

0 commit comments

Comments
 (0)