Unverified Commit 6a0ba071 authored by Guennadi Liakhovetski's avatar Guennadi Liakhovetski Committed by Mark Brown
Browse files

ASoC: SOF: add error handling to snd_sof_ipc_msg_data()



If an invalid stream is passed to snd_sof_ipc_msg_data() it won't
fill the provided object with data. The caller has to be able to
recognise such cases to avoid handling invalid data. Make the
function return an error when failing.

Signed-off-by: default avatarGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Reviewed-by: default avatarPeter Ujfalusi <peter.ujfalusi@intel.com>
Reviewed-by: default avatarKai Vehmanen <kai.vehmanen@linux.intel.com>
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: default avatarPeter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20210928103516.8066-1-peter.ujfalusi@linux.intel.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent b05cfb12
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -369,11 +369,12 @@ static int imx8_get_bar_index(struct snd_sof_dev *sdev, u32 type)
	return type;
}

static void imx8_ipc_msg_data(struct snd_sof_dev *sdev,
static int imx8_ipc_msg_data(struct snd_sof_dev *sdev,
			     struct snd_pcm_substream *substream,
			     void *p, size_t sz)
{
	sof_mailbox_read(sdev, sdev->dsp_box.offset, p, sz);
	return 0;
}

static int imx8_ipc_pcm_params(struct snd_sof_dev *sdev,
+4 −3
Original line number Diff line number Diff line
@@ -232,11 +232,12 @@ static int imx8m_get_bar_index(struct snd_sof_dev *sdev, u32 type)
	return type;
}

static void imx8m_ipc_msg_data(struct snd_sof_dev *sdev,
static int imx8m_ipc_msg_data(struct snd_sof_dev *sdev,
			      struct snd_pcm_substream *substream,
			      void *p, size_t sz)
{
	sof_mailbox_read(sdev, sdev->dsp_box.offset, p, sz);
	return 0;
}

static int imx8m_ipc_pcm_params(struct snd_sof_dev *sdev,
+9 −6
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ int hda_dsp_ipc_get_window_offset(struct snd_sof_dev *sdev, u32 id)
	return SRAM_WINDOW_OFFSET(id);
}

void hda_ipc_msg_data(struct snd_sof_dev *sdev,
int hda_ipc_msg_data(struct snd_sof_dev *sdev,
		     struct snd_pcm_substream *substream,
		     void *p, size_t sz)
{
@@ -268,10 +268,13 @@ void hda_ipc_msg_data(struct snd_sof_dev *sdev,
					  hda_stream.hstream);

		/* The stream might already be closed */
		if (hstream)
			sof_mailbox_read(sdev, hda_stream->stream.posn_offset,
					 p, sz);
		if (!hstream)
			return -ESTRPIPE;

		sof_mailbox_read(sdev, hda_stream->stream.posn_offset, p, sz);
	}

	return 0;
}

int hda_ipc_pcm_params(struct snd_sof_dev *sdev,
+3 −3
Original line number Diff line number Diff line
@@ -563,7 +563,7 @@ int hda_dsp_stream_spib_config(struct snd_sof_dev *sdev,
			       struct hdac_ext_stream *stream,
			       int enable, u32 size);

void hda_ipc_msg_data(struct snd_sof_dev *sdev,
int hda_ipc_msg_data(struct snd_sof_dev *sdev,
		     struct snd_pcm_substream *substream,
		     void *p, size_t sz);
int hda_ipc_pcm_params(struct snd_sof_dev *sdev,
+9 −5
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ struct intel_stream {
};

/* Mailbox-based Intel IPC implementation */
void intel_ipc_msg_data(struct snd_sof_dev *sdev,
int intel_ipc_msg_data(struct snd_sof_dev *sdev,
		       struct snd_pcm_substream *substream,
		       void *p, size_t sz)
{
@@ -35,9 +35,13 @@ void intel_ipc_msg_data(struct snd_sof_dev *sdev,
		struct intel_stream *stream = substream->runtime->private_data;

		/* The stream might already be closed */
		if (stream)
		if (!stream)
			return -ESTRPIPE;

		sof_mailbox_read(sdev, stream->posn_offset, p, sz);
	}

	return 0;
}
EXPORT_SYMBOL_NS(intel_ipc_msg_data, SND_SOC_SOF_INTEL_HIFI_EP_IPC);

Loading