Skip to content

Commit 657e50f

Browse files
Jaska Uimonengregkh
authored andcommitted
ASoC: SOF: ipc: check ipc return value before data copy
[ Upstream commit 1919b42 ] In tx_wait_done the ipc payload is copied before the DSP transaction error code is checked. This might lead to corrupted data in kernel side even though the error would be handled later. It is also pointless to copy the data in case of error. So change the order of error check and copy. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Signed-off-by: Jaska Uimonen <jaska.uimonen@linux.intel.com> Link: https://lore.kernel.org/r/20200228231850.9226-3-pierre-louis.bossart@linux.intel.com Signed-off-by: Mark Brown <broonie@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 29c25e6 commit 657e50f

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

sound/soc/sof/ipc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,17 @@ static int tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *msg,
215215
snd_sof_trace_notify_for_error(ipc->sdev);
216216
ret = -ETIMEDOUT;
217217
} else {
218-
/* copy the data returned from DSP */
219218
ret = msg->reply_error;
220-
if (msg->reply_size)
221-
memcpy(reply_data, msg->reply_data, msg->reply_size);
222-
if (ret < 0)
219+
if (ret < 0) {
223220
dev_err(sdev->dev, "error: ipc error for 0x%x size %zu\n",
224221
hdr->cmd, msg->reply_size);
225-
else
222+
} else {
226223
ipc_log_header(sdev->dev, "ipc tx succeeded", hdr->cmd);
224+
if (msg->reply_size)
225+
/* copy the data returned from DSP */
226+
memcpy(reply_data, msg->reply_data,
227+
msg->reply_size);
228+
}
227229
}
228230

229231
return ret;

0 commit comments

Comments
 (0)