ASoC: Intel: avs: Set of functional fixes
Subsystems (3)
Cezary Rojewski
maintainercover ASoC: Intel: avs: Set of functional fixes
Medium range of fixes all avs-driver related. The most important fixes lead the way:
1. For ASoC-hda codec driver, existing RPM manipulation in hda_codec_probe_complete()'s error path is superfluous and leads to RPM usage count underflow if the probe exists early e.g.: build-controls operation fails.
2. Resolve deadlock when DSP-recovery is a consequence of SET_D0IX IPC. The procedure handling IPC timeouts and EXCEPTION_CAUGHT notification shall cancel any D0IX work before proceeding with DSP recovery. If SET_D0IX called from delayed_work is the failing IPC the procedure will deadlock.
3. LINK format (PPLCxFMT) calculation is incorrect.
HDAudio transfer types utilize SDxFMT for front-end (HOST) and PPLCxFMT for back-end (LINK) side when setting up the stream. BE's substream->runtime duplicates FE runtime so switch to using BE's hw_params to address incorrect format values on the LINK side when FE and BE formats differ.
Below three patches address problems found by Coverity static analyzer:
ASoC: Intel: avs: Fix possible null-ptr-deref when initing hw
ASoC: Intel: avs: Verify kcalloc() status when setting constraints
ASoC: Intel: avs: Verify content returned by parse_int_array()
While unlikely in runtime, it's good to keep code resilient. The last few patches are readability/cohesiveness improvements.
Amadeusz Sławiński (1):
ASoC: Intel: avs: Fix paths in MODULE_FIRMWARE hints
Cezary Rojewski (8):
ASoC: codecs: hda: Fix RPM usage count underflow
ASoC: Intel: avs: Fix deadlock when the failing IPC is SET_D0IX
ASoC: Intel: avs: Fix PPLCxFMT calculation
ASoC: Intel: avs: Fix possible null-ptr-deref when initing hw
ASoC: Intel: avs: Verify kcalloc() status when setting constraints
ASoC: Intel: avs: Verify content returned by parse_int_array()
ASoC: Intel: avs: Simplify verification of parse_int_array() result
ASoC: Intel: avs: Include missing string.h
sound/soc/codecs/hda.c | 4 ++-- sound/soc/intel/avs/board_selection.c | 2 +- sound/soc/intel/avs/core.c | 20 ++++++++++---------- sound/soc/intel/avs/debugfs.c | 12 ++++++++---- sound/soc/intel/avs/ipc.c | 4 +++- sound/soc/intel/avs/loader.c | 1 + sound/soc/intel/avs/path.c | 2 ++ sound/soc/intel/avs/pcm.c | 13 ++++++------- 8 files changed, 33 insertions(+), 25 deletions(-)
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 1/9 ASoC: codecs: hda: Fix RPM usage count underflow
RPM manipulation in hda_codec_probe_complete()'s error path is superfluous and leads to RPM usage count underflow if the build-controls operation fails.
hda_codec_probe_complete() is called in:
1) hda_codec_probe() for all non-HDMI codecs
2) in card->late_probe() for HDMI codecs
Error path for hda_codec_probe() takes care of bus' RPM already. For 2) if late_probe() fails, ASoC performs card cleanup what triggers hda_codec_remote() - same treatment is in 1).
--- sound/soc/codecs/hda.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/hda.c +2 -2
@@ -152,7 +152,7 @@ int hda_codec_probe_complete(struct hda_codec *codec) ret =snd_hda_codec_build_controls (codec);if (ret <0 ) {dev_err (&hdev->dev,"unable to create controls %d\n" , ret); - goto out; +return ret; }/* Bus suspended codecs as it does not manage their pm */
@@ -160,7 +160,7 @@ int hda_codec_probe_complete(struct hda_codec *codec)/* rpm was forbidden in snd_hda_codec_device_new() */ snd_hda_codec_set_power_save (codec,2000 );snd_hda_codec_register (codec); -out: +/* Complement pm_runtime_get_sync(bus) in probe */ pm_runtime_mark_last_busy (bus->dev);pm_runtime_put_autosuspend (bus->dev);
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 2/9 ASoC: Intel: avs: Fix deadlock when the failing IPC is SET_D0IX
In reply to Cezary RojewskiThe procedure handling IPC timeouts and EXCEPTION_CAUGHT notification shall cancel any D0IX work before proceeding with DSP recovery. If SET_D0IX called from delayed_work is the failing IPC the procedure will deadlock. Conditionally skip cancelling the work to fix that.
--- sound/soc/intel/avs/ipc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/intel/avs/ipc.c +3 -1
@@ -169,7 +169,9 @@ static void avs_dsp_exception_caught(struct avs_dev *adev, union avs_notify_msgdev_crit (adev->dev,"communication severed, rebooting dsp..\n" ); -cancel_delayed_work_sync (&ipc->d0ix_work); +/* Avoid deadlock as the exception may be the response to SET_D0IX. */ +if (current_work () != &ipc->d0ix_work.work) +cancel_delayed_work_sync (&ipc->d0ix_work); ipc->in_d0ix = false;/* Re-enabled on recovery completion. */ pm_runtime_disable (adev->dev);
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 3/9 ASoC: Intel: avs: Fix PPLCxFMT calculation
In reply to Cezary RojewskiHDAudio transfer types utilize SDxFMT for front-end (HOST) and PPLCxFMT for back-end (LINK) side when setting up the stream. BE's substream->runtime duplicates FE runtime so switch to using BE's hw_params to address incorrect format values on the LINK side when FE and BE formats differ.
The problem is introduced with commit d070002a20fc ("ASoC: Intel: avs:
HDA PCM BE operations") but the code has been shuffled around since then so direct 'Fixes:' tag does not apply.
--- sound/soc/intel/avs/pcm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
sound/soc/intel/avs/pcm.c +5 -3
@@ -450,9 +450,10 @@ static int avs_dai_hda_be_hw_free(struct snd_pcm_substream *substream, struct snstatic int avs_dai_hda_be_prepare (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) { -struct snd_pcm_runtime *runtime = substream->runtime; +struct snd_soc_pcm_runtime *be =snd_soc_substream_to_rtd (substream);const struct snd_soc_pcm_stream *stream_info;struct hdac_ext_stream *link_stream; +const struct snd_pcm_hw_params *p;struct avs_dma_data *data;unsigned int format_val;unsigned int bits;
@@ -460,14 +461,15 @@ static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct sn data =snd_soc_dai_get_dma_data (dai, substream); link_stream = data->link_stream; + p = &be->dpcm[substream->stream].hw_params;if (link_stream->link_prepared)return 0 ; stream_info =snd_soc_dai_get_pcm_stream (dai, substream->stream); - bits =snd_hdac_stream_format_bits (runtime->format, runtime->subformat, + bits =snd_hdac_stream_format_bits (params_format (p),params_subformat (p), stream_info->sig_bits); - format_val =snd_hdac_stream_format (runtime->channels, bits, runtime->rate); + format_val =snd_hdac_stream_format (params_channels (p), bits,params_rate (p));snd_hdac_ext_stream_decouple (&data->adev->base.core, link_stream, true);snd_hdac_ext_stream_reset (link_stream);
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 4/9 ASoC: Intel: avs: Fix possible null-ptr-deref when initing hw
In reply to Cezary RojewskiSearch result of avs_dai_find_path_template() shall be verified before being used. As 'template' is already known when avs_hw_constraints_init() is fired, drop the search entirely.
--- sound/soc/intel/avs/pcm.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
sound/soc/intel/avs/pcm.c +1 -4
@@ -83,10 +83,8 @@ void avs_period_elapsed(struct snd_pcm_substream *substream)static int hw_rule_param_size (struct snd_pcm_hw_params *params,struct snd_pcm_hw_rule *rule);static int avs_hw_constraints_init (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) { -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_pcm_runtime *runtime = substream->runtime;struct snd_pcm_hw_constraint_list *r, *c, *s; -struct avs_tplg_path_template *template;struct avs_dma_data *data;int ret;
@@ -99,8 +97,7 @@ static int avs_hw_constraints_init(struct snd_pcm_substream *substream, struct s c = &(data->channels_list); s = &(data->sample_bits_list); - template =avs_dai_find_path_template (dai, !rtd->dai_link->no_pcm, substream->stream); - ret =avs_path_set_constraint (data->adev, template, r, c, s); + ret =avs_path_set_constraint (data->adev, data->template, r, c, s);if (ret <=0 )return ret;
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 5/9 ASoC: Intel: avs: Fix paths in MODULE_FIRMWARE hints
In reply to Cezary RojewskiFrom: Amadeusz Sławiński <[email protected]>
The binaries for cAVS architecture are located in "intel/avs" subdirectory, not "intel".
--- sound/soc/intel/avs/core.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
sound/soc/intel/avs/core.c +10 -10
@@ -945,14 +945,14 @@ MODULE_AUTHOR("Cezary Rojewski <[email protected]>");MODULE_AUTHOR ("Amadeusz Slawinski <[email protected]>" );MODULE_DESCRIPTION ("Intel cAVS sound driver" );MODULE_LICENSE ("GPL" ); -MODULE_FIRMWARE ("intel/skl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/apl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/cnl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/icl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/jsl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/lkf/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/tgl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/ehl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/adl/dsp_basefw.bin" ); -MODULE_FIRMWARE ("intel/adl_n/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/skl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/apl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/cnl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/icl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/jsl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/lkf/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/tgl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/ehl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/adl/dsp_basefw.bin" ); +MODULE_FIRMWARE ("intel/avs/adl_n/dsp_basefw.bin" );MODULE_FIRMWARE ("intel/fcl/dsp_basefw.bin" );
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 6/9 ASoC: Intel: avs: Verify kcalloc() status when setting constraints
In reply to Cezary RojewskiAll memory operations shall be checked.
--- sound/soc/intel/avs/path.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/intel/avs/path.c +2 -0
@@ -134,6 +134,8 @@ int avs_path_set_constraint(struct avs_dev *adev, struct avs_tplg_path_template rlist =kcalloc (i,sizeof (*rlist),GFP_KERNEL ); clist =kcalloc (i,sizeof (*clist),GFP_KERNEL ); slist =kcalloc (i,sizeof (*slist),GFP_KERNEL ); +if (!rlist || !clist || !slist) +return -ENOMEM ; i =0 ;list_for_each_entry (path_template, &template->path_list, node) {
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 7/9 ASoC: Intel: avs: Verify content returned by parse_int_array()
In reply to Cezary RojewskiThe first element of the returned array stores its length. If it is 0, any manipulation beyond the element at index 0 ends with null-ptr-deref.
--- sound/soc/intel/avs/debugfs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
sound/soc/intel/avs/debugfs.c +5 -1
@@ -373,7 +373,10 @@ static ssize_t trace_control_write(struct file *file, const char __user *from, sreturn ret; num_elems = *array; - resource_mask = array[1 ]; +if (!num_elems) { + ret = -EINVAL ; + goto free_array; + }/* * Disable if just resource mask is provided - no log priority flags.
@@ -381,6 +384,7 @@ static ssize_t trace_control_write(struct file *file, const char __user *from, s* Enable input format: mask, prio1, .., prioN * Where 'N' equals number of bits set in the 'mask'. */ + resource_mask = array[1 ];if (num_elems ==1 ) { ret =disable_logs (adev, resource_mask); }else {
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 8/9 ASoC: Intel: avs: Simplify verification of parse_int_array() result
In reply to Cezary RojewskiThe function return either success or an error code, no need to involve '<' operator.
--- sound/soc/intel/avs/board_selection.c | 2 +- sound/soc/intel/avs/debugfs.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-)
sound/soc/intel/avs/board_selection.c +1 -1
@@ -548,7 +548,7 @@ static int avs_register_i2s_test_boards(struct avs_dev *adev)u32 *array, num_elems; ret =parse_int_array (i2s_test,strlen (i2s_test), (int **)&array); -if (ret <0 ) { +if (ret) {dev_err (adev->dev,"failed to parse i2s_test parameter\n" );return ret; }
sound/soc/intel/avs/debugfs.c +3 -3
@@ -144,7 +144,7 @@ static ssize_t probe_points_write(struct file *file, const char __user *from, siint ret; ret =parse_int_array_user (from, count, (int **)&array); -if (ret <0 ) +if (ret)return ret; num_elems = *array;
@@ -181,7 +181,7 @@ static ssize_t probe_points_disconnect_write(struct file *file, const char __useint ret; ret =parse_int_array_user (from, count, (int **)&array); -if (ret <0 ) +if (ret)return ret; num_elems = *array;
@@ -369,7 +369,7 @@ static ssize_t trace_control_write(struct file *file, const char __user *from, sint ret; ret =parse_int_array_user (from, count, (int **)&array); -if (ret <0 ) +if (ret)return ret; num_elems = *array;
Signature · 1 line
2.25.1
Cezary Rojewski
maintainerPATCH 9/9 ASoC: Intel: avs: Include missing string.h
In reply to Cezary RojewskiFile loader.c utilizes strscpy().
--- sound/soc/intel/avs/loader.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/intel/avs/loader.c +1 -0
@@ -9,6 +9,7 @@#include <linux/firmware.h> #include <linux/module.h> #include <linux/slab.h> +#include <linux/string.h> #include <sound/hdaudio.h> #include <sound/hdaudio_ext.h> #include "avs.h"
Signature · 1 line
2.25.1
Mark Brown
maintainerRe: (subset) [PATCH 0/9] ASoC: Intel: avs: Set of functional fixes
In reply to Cezary RojewskiQuoted 9 lines · Cezary Rojewski
Medium range of fixes all avs-driver related. The most important fixes lead the way:
1. For ASoC-hda codec driver, existing RPM manipulation in hda_codec_probe_complete()'s error path is superfluous and leads to RPM usage count underflow if the probe exists early e.g.: build-controls operation fails.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/9] ASoC: codecs: hda: Fix RPM usage count underflow
commit: ff0045de4ee0288dec683690f66f2f369b7d3466
[2/9] ASoC: Intel: avs: Fix deadlock when the failing IPC is SET_D0IX
commit: 9ad1f3cd0d60444c69948854c7e50d2a61b63755
[3/9] ASoC: Intel: avs: Fix PPLCxFMT calculation
commit: 347c8d6db7c9d65d93ef226849b273823f54eaea
[4/9] ASoC: Intel: avs: Fix possible null-ptr-deref when initing hw
commit: 2f78724d4f0c665c83e202e3989d5333a2cb1036
[5/9] ASoC: Intel: avs: Fix paths in MODULE_FIRMWARE hints
commit: 9e3285be55e6c0829e451b4a341e3059da47ec9d
[6/9] ASoC: Intel: avs: Verify kcalloc() status when setting constraints
commit: 5f342aeee2724d31046172eb5caab8e0e8afd57d
[7/9] ASoC: Intel: avs: Verify content returned by parse_int_array()
commit: 93e246b6769bdacb09cfff4ea0f00fe5ab4f0d7a
[9/9] ASoC: Intel: avs: Include missing string.h
commit: 38b1befc7a35a475d90ec32bfbe319f4412880a1All 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
Cezary Rojewski
maintainerRe: (subset) [PATCH 0/9] ASoC: Intel: avs: Set of functional fixes
Quoted 18 lines · Mark Brown
Quoted 9 lines · Cezary Rojewski
Medium range of fixes all avs-driver related. The most important fixes lead the way:
1. For ASoC-hda codec driver, existing RPM manipulation in hda_codec_probe_complete()'s error path is superfluous and leads to RPM usage count underflow if the probe exists early e.g.: build-controls operation fails.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/9] ASoC: codecs: hda: Fix RPM usage count underflow
Quoted 15 lines
commit: ff0045de4ee0288dec683690f66f2f369b7d3466
[2/9] ASoC: Intel: avs: Fix deadlock when the failing IPC is SET_D0IX
commit: 9ad1f3cd0d60444c69948854c7e50d2a61b63755
[3/9] ASoC: Intel: avs: Fix PPLCxFMT calculation
commit: 347c8d6db7c9d65d93ef226849b273823f54eaea
[4/9] ASoC: Intel: avs: Fix possible null-ptr-deref when initing hw
commit: 2f78724d4f0c665c83e202e3989d5333a2cb1036
[5/9] ASoC: Intel: avs: Fix paths in MODULE_FIRMWARE hints
commit: 9e3285be55e6c0829e451b4a341e3059da47ec9d
[6/9] ASoC: Intel: avs: Verify kcalloc() status when setting constraints
commit: 5f342aeee2724d31046172eb5caab8e0e8afd57d
[7/9] ASoC: Intel: avs: Verify content returned by parse_int_array()
commit: 93e246b6769bdacb09cfff4ea0f00fe5ab4f0d7a
[9/9] ASoC: Intel: avs: Include missing string.h
commit: 38b1befc7a35a475d90ec32bfbe319f4412880a1I've just checked broonie/sound/for-next and it seems the status of the branch matches above - patch 8/9 is _missing_.
At the same time, I do not see any reply with reasoning behind skipping the patch. What can I do to help address that?
Quoted 20 lines
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
Mark Brown
maintainerRe: (subset) [PATCH 0/9] ASoC: Intel: avs: Set of functional fixes
Quoted 5 lines · Cezary Rojewski
I've just checked broonie/sound/for-next and it seems the status of the branch matches above - patch 8/9 is _missing_.
At the same time, I do not see any reply with reasoning behind skipping the patch. What can I do to help address that?
It was waiting for after the merge window, though largely a fat finger as I intended to skip patch 9 (adding string.h).
Cezary Rojewski
maintainerRe: (subset) [PATCH 0/9] ASoC: Intel: avs: Set of functional fixes
Quoted 10 lines · Mark Brown
Quoted 5 lines · Cezary Rojewski
I've just checked broonie/sound/for-next and it seems the status of the branch matches above - patch 8/9 is _missing_.
At the same time, I do not see any reply with reasoning behind skipping the patch. What can I do to help address that?
It was waiting for after the merge window, though largely a fat finger as I intended to skip patch 9 (adding
string.h).
It's clear then. Thank you for a quick reply, Mark!
Mark Brown
maintainerQuoted 9 lines · Cezary Rojewski
Medium range of fixes all avs-driver related. The most important fixes lead the way:
1. For ASoC-hda codec driver, existing RPM manipulation in hda_codec_probe_complete()'s error path is superfluous and leads to RPM usage count underflow if the probe exists early e.g.: build-controls operation fails.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/9] ASoC: codecs: hda: Fix RPM usage count underflow
commit: ff0045de4ee0288dec683690f66f2f369b7d3466
[2/9] ASoC: Intel: avs: Fix deadlock when the failing IPC is SET_D0IX
commit: 9ad1f3cd0d60444c69948854c7e50d2a61b63755
[3/9] ASoC: Intel: avs: Fix PPLCxFMT calculation
commit: 347c8d6db7c9d65d93ef226849b273823f54eaea
[4/9] ASoC: Intel: avs: Fix possible null-ptr-deref when initing hw
commit: 2f78724d4f0c665c83e202e3989d5333a2cb1036
[5/9] ASoC: Intel: avs: Fix paths in MODULE_FIRMWARE hints
commit: 9e3285be55e6c0829e451b4a341e3059da47ec9d
[6/9] ASoC: Intel: avs: Verify kcalloc() status when setting constraints
commit: 5f342aeee2724d31046172eb5caab8e0e8afd57d
[7/9] ASoC: Intel: avs: Verify content returned by parse_int_array()
commit: 93e246b6769bdacb09cfff4ea0f00fe5ab4f0d7a
[8/9] ASoC: Intel: avs: Simplify verification of parse_int_array() result
commit: 065a651e2fb35209cbfe6fc5f1ababf92b66d4a4
[9/9] ASoC: Intel: avs: Include missing string.h
commit: 38b1befc7a35a475d90ec32bfbe319f4412880a1All 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