ASoC: SOF: add error handling to snd_sof_ipc_msg_data()
Peter Ujfalusi
maintainerPATCH 1/1 ASoC: SOF: add error handling to snd_sof_ipc_msg_data()
From: Guennadi Liakhovetski <[email protected]>
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.
--- sound/soc/sof/imx/imx8.c | 7 +++--- sound/soc/sof/imx/imx8m.c | 7 +++--- sound/soc/sof/intel/hda-ipc.c | 15 +++++++----- sound/soc/sof/intel/hda.h | 6 ++--- sound/soc/sof/intel/intel-ipc.c | 14 +++++++---- sound/soc/sof/ipc.c | 41 +++++++++++++++++++++++++-------- sound/soc/sof/ops.h | 8 +++---- sound/soc/sof/sof-priv.h | 12 +++++----- 8 files changed, 71 insertions(+), 39 deletions(-)
sound/soc/sof/imx/imx8.c +4 -3
@@ -375,11 +375,12 @@ static int imx8_get_bar_index(struct snd_sof_dev *sdev, u32 type) } } -static void imx8_ipc_msg_data (struct snd_sof_dev *sdev, -struct snd_pcm_substream *substream, -void *p,size_t sz) +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,
sound/soc/sof/imx/imx8m.c +4 -3
@@ -238,11 +238,12 @@ static int imx8m_get_bar_index(struct snd_sof_dev *sdev, u32 type) } } -static void imx8m_ipc_msg_data (struct snd_sof_dev *sdev, -struct snd_pcm_substream *substream, -void *p,size_t sz) +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,
sound/soc/sof/intel/hda-ipc.c +9 -6
@@ -253,9 +253,9 @@ 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, -struct snd_pcm_substream *substream, -void *p,size_t sz) +int hda_ipc_msg_data (struct snd_sof_dev *sdev, +struct snd_pcm_substream *substream, +void *p,size_t sz) {if (!substream || !sdev->stream_box.size) {sof_mailbox_read (sdev, sdev->dsp_box.offset, p, 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,
sound/soc/sof/intel/hda.h +3 -3
@@ -563,9 +563,9 @@ 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, -struct snd_pcm_substream *substream, -void *p,size_t sz); +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,struct snd_pcm_substream *substream,const struct sof_ipc_pcm_params_reply *reply);
sound/soc/sof/intel/intel-ipc.c +9 -5
@@ -25,9 +25,9 @@ struct intel_stream { };/* Mailbox-based Intel IPC implementation */ -void intel_ipc_msg_data (struct snd_sof_dev *sdev, -struct snd_pcm_substream *substream, -void *p,size_t sz) +int intel_ipc_msg_data (struct snd_sof_dev *sdev, +struct snd_pcm_substream *substream, +void *p,size_t sz) {if (!substream || !sdev->stream_box.size) {sof_mailbox_read (sdev, sdev->dsp_box.offset, p, 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) -sof_mailbox_read (sdev, stream->posn_offset, p, sz); +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 );
sound/soc/sof/ipc.c +32 -9
101 lines not on this page · raw message
sound/soc/sof/ops.h +4 -4
@@ -422,11 +422,11 @@ static inline int snd_sof_load_firmware(struct snd_sof_dev *sdev) }/* host DSP message data */ -static inline void snd_sof_ipc_msg_data (struct snd_sof_dev *sdev, -struct snd_pcm_substream *substream, -void *p,size_t sz) +static inline int snd_sof_ipc_msg_data (struct snd_sof_dev *sdev, +struct snd_pcm_substream *substream, +void *p,size_t sz) { -sof_ops (sdev)->ipc_msg_data (sdev, substream, p, sz); +return sof_ops (sdev)->ipc_msg_data (sdev, substream, p, sz); }/* host configure DSP HW parameters */
sound/soc/sof/sof-priv.h +6 -6
@@ -210,9 +210,9 @@ struct snd_sof_dsp_ops {#endif /* host read DSP stream data */ -void (*ipc_msg_data)(struct snd_sof_dev *sdev, -struct snd_pcm_substream *substream, -void *p,size_t sz);/* mandatory */ +int (*ipc_msg_data)(struct snd_sof_dev *sdev, +struct snd_pcm_substream *substream, +void *p,size_t sz);/* mandatory */ /* host configure DSP HW parameters */ int (*ipc_pcm_params)(struct snd_sof_dev *sdev,
@@ -567,9 +567,9 @@ int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,int sof_fw_ready (struct snd_sof_dev *sdev,u32 msg_id); -void intel_ipc_msg_data (struct snd_sof_dev *sdev, -struct snd_pcm_substream *substream, -void *p,size_t sz); +int intel_ipc_msg_data (struct snd_sof_dev *sdev, +struct snd_pcm_substream *substream, +void *p,size_t sz);int intel_ipc_pcm_params (struct snd_sof_dev *sdev,struct snd_pcm_substream *substream,const struct sof_ipc_pcm_params_reply *reply);
Signature · 1 line
2.33.0
Mark Brown
maintainerQuoted 8 lines · Peter Ujfalusi
From: Guennadi Liakhovetski <[email protected]>
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.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: SOF: add error handling to snd_sof_ipc_msg_data()
commit: 6a0ba071b71c44bc905522b77e96afad464e8aac
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark