ASoC: fix the x1e80100 card after an ADSP restart
Subsystems (4)
cover ASoC: fix the x1e80100 card after an ADSP restart
On Qualcomm boards an ADSP restart unbinds and rebinds the LPASS pin controller, the SoundWire controllers and the codecs, and the card binds again once they are back. On the Hamoa IoT EVK two things break on that
path: the DAI link names point at the SoundWire controllers' freed strings, and the headset jack is never recreated.
The speakers also need Abel's reset-gpio parent fix [1] and the gpiolib-shared follow-up [2].
Tested on the Hamoa IoT EVK on next-20261103: ADSP crash idle and during playback, the card comes back with its controls, the headset jack and working playback.
[1] https://lore.kernel.org/r/20261026-b4-reset-gpio-parent-to-gpio-controller-v1-1-11549e6ea930@oss.qualcomm.com
[2] https://lore.kernel.org/r/[email protected]
Tyler Baker (2):
ASoC: soc-core: copy the DAI link names into the card
ASoC: qcom: x1e80100: recreate the headset jack on card rebind
sound/soc/qcom/x1e80100.c | 18 ++++++++++++++++++ sound/soc/soc-core.c | 16 ++++++++++++++++ 2 files changed, 34 insertions(+)
Signature · 1 line
2.47.3
PATCH 1/2 ASoC: soc-core: copy the DAI link names into the card
snd_soc_of_get_dai_link_codecs() and snd_soc_of_get_dai_link_cpus() keep a DAI name owned by the component, which is freed when the component unbinds, so the card cannot bind again afterwards.
Copy the name onto the card device, as simple-card and audio-graph-card do since commit aa173b70d372 ("ASoC: generic: keep fallback dai_name stable across rebind").
--- sound/soc/soc-core.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
sound/soc/soc-core.c +16 -0
@@ -3253,6 +3253,18 @@ void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link) }EXPORT_SYMBOL_GPL (snd_soc_of_put_dai_link_codecs); +/* dai_name belongs to the component, which can unbind before the card. */ +static int snd_soc_of_dup_dai_name (struct device *dev, +struct snd_soc_dai_link_component *dlc) +{ +if (!dlc->dai_name) +return 0 ; + + dlc->dai_name =devm_kstrdup_const (dev, dlc->dai_name,GFP_KERNEL ); + +return dlc->dai_name ?0 : -ENOMEM ; +} +/* * snd_soc_of_get_dai_link_codecs - Parse a list of CODECs in the devicetree * @dev: Card device
@@ -3282,6 +3294,8 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,/* Parse the list */ for_each_link_codecs (dai_link, index, component) { ret =snd_soc_of_get_dlc (of_node,NULL , component, index); +if (!ret) + ret =snd_soc_of_dup_dai_name (dev, component);if (ret) goto err; }
@@ -3337,6 +3351,8 @@ int snd_soc_of_get_dai_link_cpus(struct device *dev,/* Parse the list */ for_each_link_cpus (dai_link, index, component) { ret =snd_soc_of_get_dlc (of_node,NULL , component, index); +if (!ret) + ret =snd_soc_of_dup_dai_name (dev, component);if (ret) goto err; }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 1/2] ASoC: soc-core: copy the DAI link names into the card
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Medium] ASoC: soc-core: memory leak in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Medium] ASoC: soc-core: memory leak in snd_soc_of_get_dlc() [1] --
commit fe7efa2dfe30cec1a0e194d20cca010f7a414abc
Author: Tyler Baker <[email protected]>
ASoC: soc-core: copy the DAI link names into the card
This commit duplicates the component DAI name onto the card device in snd_soc_of_get_dai_link_codecs() and snd_soc_of_get_dai_link_cpus() so the name remains valid across component unbind and rebind.
Quoted 4 lines
sound/soc/soc-core.c +0
-0
[ ... ]
sound/soc/soc-core.c int snd_soc_of_get_dai_link_codecs(struct device *dev, · line 3301
Quoted 9 lines
sound/soc/soc-core.c +2
-0@@ -3282,6 +3294,8 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,/* Parse the list */ for_each_link_codecs (dai_link, index, component) { ret =snd_soc_of_get_dlc (of_node,NULL , component, index); +if (!ret) + ret =snd_soc_of_dup_dai_name (dev, component);if (ret) goto err; }
[Severity: Medium]
This problem wasn't introduced by this patch, but does snd_soc_of_get_dlc()
[1] leak the device_node reference in args->np when snd_soc_get_dlc() fails?
sound/soc/soc-core.c:snd_soc_of_get_dlc() {
if (!args)
args = &__args;
ret = of_parse_phandle_with_args(of_node, "sound-dai",
"#sound-dai-cells", index, args);
if (ret)
return ret;
return snd_soc_get_dlc(args, dlc);
}of_parse_phandle_with_args() acquires a reference on args->np, which snd_soc_get_dlc() only transfers to dlc->of_node on success. When snd_soc_get_dlc() fails (for example with -EPROBE_DEFER) and the caller passed a NULL args pointer as done here and in snd_soc_of_get_dai_link_cpus(), __args goes out of scope without of_node_put() being called.
[1] https://sashiko.dev/#/bug/linux-11ae6ad5-0cce-4928-9290-e7723e9f7638
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/2 ASoC: qcom: x1e80100: recreate the headset jack on card rebind
In reply to Tyler BakerThe headset jack is only created while jack_setup is false and nothing clears it, so after a card rebind it is not created again and the codecs keep a pointer to the freed jack.
Clear it on link exit, as sc8280xp does.
--- sound/soc/qcom/x1e80100.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
sound/soc/qcom/x1e80100.c +18 -0
@@ -68,6 +68,23 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)return qcom_snd_wcd_jack_setup (rtd, &data->jack, &data->jack_setup); } +static void x1e80100_snd_exit (struct snd_soc_pcm_runtime *rtd) +{ +struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card); +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); + +switch (cpu_dai->id) { +case DISPLAY_PORT_RX_0 : + case DISPLAY_PORT_RX_1 ... DISPLAY_PORT_RX_7: +return ; +default : +break ; + } + +qcom_snd_headset_jack_cleanup (rtd); + data->jack_setup = false; +} +static int x1e80100_be_hw_params_fixup (struct snd_soc_pcm_runtime *rtd,struct snd_pcm_hw_params *params) {
@@ -172,6 +189,7 @@ static void x1e80100_add_be_ops(struct snd_soc_card *card)for_each_card_prelinks (card, i, link) {if (link->no_pcm ==1 ) { link->init = x1e80100_snd_init; + link->exit = x1e80100_snd_exit; link->be_hw_params_fixup = x1e80100_be_hw_params_fixup; link->ops = &x1e80100_be_ops; }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/2] ASoC: qcom: x1e80100: recreate the headset jack on card rebind
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] ASoC: qcom: x1e80100: missing DP jack cleanup in x1e80100_snd_exit() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] ASoC: qcom: x1e80100: missing DP jack cleanup in x1e80100_snd_exit()
--
commit f605374e23a64b3505524d6591f1d001a229a2a3
Author: Tyler Baker <[email protected]>
ASoC: qcom: x1e80100: recreate the headset jack on card rebind
This commit adds a DAI link exit callback for x1e80100 to clean up the headset jack and reset jack_setup on card unbind.
Quoted 10 lines
sound/soc/qcom/x1e80100.c +2
-0@@ -68,6 +68,23 @@ static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd)return qcom_snd_wcd_jack_setup (rtd, &data->jack, &data->jack_setup); } +static void x1e80100_snd_exit (struct snd_soc_pcm_runtime *rtd) +{
sound/soc/qcom/x1e80100.c static int x1e80100_snd_init(struct snd_soc_pcm_runtime *rtd) · line 82
Quoted 10 lines
sound/soc/qcom/x1e80100.c +10
-0+struct x1e80100_snd_data *data =snd_soc_card_get_drvdata (rtd->card); +struct snd_soc_dai *cpu_dai =snd_soc_rtd_to_cpu (rtd,0 ); + +switch (cpu_dai->id) { +case DISPLAY_PORT_RX_0 : + case DISPLAY_PORT_RX_1 ... DISPLAY_PORT_RX_7: +return ; +default : +break ; + }
[Severity: High]
Does returning early for DisplayPort links leave hdmi_codec_priv->jack pointing to data->dp_jack[dp_pcm_id] after snd_card_free() frees its underlying struct snd_jack?
On card rebind, snd_soc_bind_card() runs soc_probe_link_components() before soc_init_pcm_runtime() calls x1e80100_snd_init() to recreate dp_jack->jack. During soc_probe_link_components(), hdmi_probe() calls drm_connector_hdmi_audio_hook_plugged_cb(), which synchronously invokes hdmi_codec_jack_report():
sound/soc/codecs/hdmi-codec.c:hdmi_codec_jack_report() {
...
if (jack_status != hcp->jack_status) {
if (hcp->jack)
snd_soc_jack_report(hcp->jack, jack_status, SND_JACK_AVOUT);
hcp->jack_status = jack_status;
}
}If the DisplayPort plug state changed while the card was unbound, snd_soc_jack_report() dereferences the freed dp_jack->jack (use-after-free). Calling qcom_snd_headset_jack_cleanup(rtd) before returning for the DisplayPort links clears hcp->jack on unbind.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Mark Brown
maintainerQuoted 9 lines · Tyler Baker
ASoC: fix the x1e80100 card after an ADSP restart
On Qualcomm boards an ADSP restart unbinds and rebinds the LPASS pin controller, the SoundWire controllers and the codecs, and the card binds again once they are back. On the Hamoa IoT EVK two things break on that
path: the DAI link names point at the SoundWire controllers' freed strings, and the headset jack is never recreated.[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.4
Thanks!
[1/2] ASoC: soc-core: copy the DAI link names into the card
https://git.kernel.org/broonie/sound/c/33a130f6ed8c [2/2] ASoC: qcom: x1e80100: recreate the headset jack on card rebind https://git.kernel.org/broonie/sound/c/704251f9dad3
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