All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, broonie@kernel.org,
	Jaska Uimonen <jaska.uimonen@linux.intel.com>,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Subject: [PATCH 2/4] ASoC: SOF: ipc: check ipc return value before data copy
Date: Fri, 28 Feb 2020 17:18:48 -0600	[thread overview]
Message-ID: <20200228231850.9226-3-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20200228231850.9226-1-pierre-louis.bossart@linux.intel.com>

From: Jaska Uimonen <jaska.uimonen@linux.intel.com>

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: Jaska Uimonen <jaska.uimonen@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/soc/sof/ipc.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c
index 22d296f95761..cc5762706c9c 100644
--- a/sound/soc/sof/ipc.c
+++ b/sound/soc/sof/ipc.c
@@ -214,15 +214,17 @@ static int tx_wait_done(struct snd_sof_ipc *ipc, struct snd_sof_ipc_msg *msg,
 		snd_sof_handle_fw_exception(ipc->sdev);
 		ret = -ETIMEDOUT;
 	} else {
-		/* copy the data returned from DSP */
 		ret = msg->reply_error;
-		if (msg->reply_size)
-			memcpy(reply_data, msg->reply_data, msg->reply_size);
-		if (ret < 0)
+		if (ret < 0) {
 			dev_err(sdev->dev, "error: ipc error for 0x%x size %zu\n",
 				hdr->cmd, msg->reply_size);
-		else
+		} else {
 			ipc_log_header(sdev->dev, "ipc tx succeeded", hdr->cmd);
+			if (msg->reply_size)
+				/* copy the data returned from DSP */
+				memcpy(reply_data, msg->reply_data,
+				       msg->reply_size);
+		}
 	}
 
 	return ret;
-- 
2.20.1


  parent reply	other threads:[~2020-02-28 23:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28 23:18 [PATCH 0/4] ASoC: SOF: updates for 5.7 Pierre-Louis Bossart
2020-02-28 23:18 ` [PATCH 1/4] ASoC: SOF: pcm: skip DMA buffer pre-allocation Pierre-Louis Bossart
2020-03-02 14:37   ` Applied "ASoC: SOF: pcm: skip DMA buffer pre-allocation" to the asoc tree Mark Brown
2020-02-28 23:18 ` Pierre-Louis Bossart [this message]
2020-03-02 14:37   ` Applied "ASoC: SOF: ipc: check ipc return value before data copy" " Mark Brown
2020-02-28 23:18 ` [PATCH 3/4] ASoC: SOF: Intel: hda-loader: clear the IPC ack bit after FW_PURGE done Pierre-Louis Bossart
2020-03-02 14:37   ` Applied "ASoC: SOF: Intel: hda-loader: clear the IPC ack bit after FW_PURGE done" to the asoc tree Mark Brown
2020-02-28 23:18 ` [PATCH 4/4] ASoC: SOF: add core id to sof_ipc_comp Pierre-Louis Bossart
2020-03-02 14:37   ` Applied "ASoC: SOF: add core id to sof_ipc_comp" to the asoc tree Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200228231850.9226-3-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=jaska.uimonen@linux.intel.com \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.