From 2b1bf49b5fb3683866d21aea271c23fead471080 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 27 Nov 2026 12:14:58 +0200 Subject: [PATCH 1/3] ASoC: hdac_hda: drop PCM reference if codec stream open fails hdac_hda_dai_open() takes a reference to the HDA PCM with snd_hda_codec_pcm_get() before calling the codec stream open callback. If the callback fails, the error is returned to ASoC, which does not call the DAI .shutdown callback for a DAI whose .startup failed. The PCM reference is thus never released. Drop the reference on the error path. Fixes: 6bae5ea94989 ("ASoC: hdac_hda: add asoc extension for legacy HDA codec drivers") Signed-off-by: Kai Vehmanen --- sound/soc/codecs/hdac_hda.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/hdac_hda.c b/sound/soc/codecs/hdac_hda.c index 48eb95973b7a39..5ba5861dfcf40d 100644 --- a/sound/soc/codecs/hdac_hda.c +++ b/sound/soc/codecs/hdac_hda.c @@ -309,8 +309,10 @@ static int hdac_hda_dai_open(struct snd_pcm_substream *substream, hda_stream = &pcm->stream[substream->stream]; ret = hda_stream->ops.open(hda_stream, hda_pvt->codec, substream); - if (ret < 0) + if (ret < 0) { dev_err(dai->dev, "%s: failed %d\n", __func__, ret); + snd_hda_codec_pcm_put(pcm); + } return ret; } From 12a7f8cc85fefa7c73e838d5fa3b98253090bdc0 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 27 Nov 2026 12:15:50 +0200 Subject: [PATCH 2/3] ASoC: hdac_hda: reject hw_params not supported by the codec The hdac_hda DAIs are registered with static stub capabilities (SNDRV_PCM_RATE_8000_192000, 1-16 channels), and the actual codec stream capabilities queried by snd_hda_query_supported_pcm() and adjusted by the codec stream open callback are never checked. hdac_hda_dai_hw_params() only rejects parameters that have no HDA stream format encoding. As a result, a BE configuration using unsupported sampling rate is accepted instead of raising an error. Applying the codec capabilities as hw constraints in the DAI startup callback, like the legacy HDA driver does in azx_pcm_open(), is not an option. In DPCM, the BE substream shares the FE runtime, so the constraints would restrict the FE as well. This is wrong when the BE rate is fixed in topology and differs from the FE rate (with an SRC in the pipeline), as the codec then only sees the fixed BE rate. Instead, validate the BE rate and channel count in hw_params, which is called with the parameters after the BE fixup. The format is not checked, as the codec reports 24-bit support as S32_LE while the DAIs also accept S24_LE, which is handled by snd_hdac_stream_format_bits(). Fixes: 6bae5ea94989 ("ASoC: hdac_hda: add asoc extension for legacy HDA codec drivers") Signed-off-by: Kai Vehmanen --- sound/soc/codecs/hdac_hda.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/hdac_hda.c b/sound/soc/codecs/hdac_hda.c index 5ba5861dfcf40d..d0b09462cddfdd 100644 --- a/sound/soc/codecs/hdac_hda.c +++ b/sound/soc/codecs/hdac_hda.c @@ -215,18 +215,42 @@ static int hdac_hda_dai_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct snd_soc_component *component = dai->component; + unsigned int channels = params_channels(params); + unsigned int rate = params_rate(params); + struct hda_pcm_stream *hda_stream; struct hdac_hda_priv *hda_pvt; unsigned int format_val; + struct hda_pcm *pcm; unsigned int maxbps; unsigned int bits; + hda_pvt = snd_soc_component_get_drvdata(component); + pcm = snd_soc_find_pcm_from_dai(hda_pvt, dai); + if (!pcm) + return -EINVAL; + + hda_stream = &pcm->stream[substream->stream]; + + /* + * The DAI driver advertises stub capabilities, so check the + * BE parameters against what the codec stream actually supports. + */ + if (!(snd_pcm_rate_to_rate_bit(rate) & hda_stream->rates) || + channels < hda_stream->channels_min || + channels > hda_stream->channels_max) { + dev_err(dai->dev, + "%s: unsupported by codec, rate=%u, ch=%u (rates=%#x, ch=%u-%u)\n", + __func__, rate, channels, hda_stream->rates, + hda_stream->channels_min, hda_stream->channels_max); + return -EINVAL; + } + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) maxbps = dai->driver->playback.sig_bits; else maxbps = dai->driver->capture.sig_bits; bits = snd_hdac_stream_format_bits(params_format(params), SNDRV_PCM_SUBFORMAT_STD, maxbps); - hda_pvt = snd_soc_component_get_drvdata(component); format_val = snd_hdac_stream_format(params_channels(params), bits, params_rate(params)); if (!format_val) { dev_err(dai->dev, From 59d0e6b55e30d98aef31b813a11e70381f078c11 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Fri, 27 Nov 2026 13:45:29 +0200 Subject: [PATCH 3/3] ASoC: SOF: ipc4-pcm: use the DAI copier of the stream in BE fixup The playback and capture DAI widgets of a bidirectional DAI link have separate copiers, each with their own set of audio formats, but both are registered as a snd_sof_dai named after the DAI link. sof_ipc4_pcm_dai_link_fixup() looks up the DAI by the link name, so it always gets the copier that was registered last, regardless of the stream being configured, and uses its formats to fix up the BE rate, channels and bit depth. If the formats differ, the BE is configured with the formats of the other direction. For example with a topology where the playback HDA DAI copier supports 22050Hz and 48000Hz, but the capture DAI copier only 48000Hz, a 22050Hz playback stream gets its BE rate forced to 48000Hz, while the playback DAI copier is configured for 22050Hz. The HDA link and codec run at 48000Hz and the audio is played back at the wrong rate. The BE fixup callback is not told the stream direction. Find it using the same test dpcm_be_dai_hw_params() uses to select the BEs to update, and use the copier of the DAI widget for that direction. Fall back to the old behaviour if the direction cannot be determined. Fixes: 26dfc4346110 ("ASoC: SOF: ipc4-pcm: fixup dailink based on copier format") Fixes: 279e52d6b9f3 ("ASoC: SOF: ipc4-pcm: support multiple configs for BE DAIs") Signed-off-by: Kai Vehmanen --- sound/soc/sof/ipc4-pcm.c | 51 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/sound/soc/sof/ipc4-pcm.c b/sound/soc/sof/ipc4-pcm.c index cbf948d8479148..4d7acb3e5e161d 100644 --- a/sound/soc/sof/ipc4-pcm.c +++ b/sound/soc/sof/ipc4-pcm.c @@ -792,6 +792,35 @@ static int sof_ipc4_pcm_dai_link_fixup_channels(struct snd_sof_dev *sdev, return 0; } +/* + * The BE hw_params fixup is not told the stream direction. Find it using + * the same test dpcm_be_dai_hw_params() uses to pick the BEs to update. + * Return -EINVAL if no direction, or both directions, match. + */ +static int sof_ipc4_pcm_dai_link_fixup_stream(struct snd_soc_pcm_runtime *rtd) +{ + struct snd_soc_dpcm *dpcm; + int stream = -EINVAL; + int dir; + + for_each_pcm_streams(dir) { + for_each_dpcm_fe(rtd, dir, dpcm) { + enum snd_soc_dpcm_update update = dpcm->fe->dpcm[dir].runtime_update; + + if (update == SND_SOC_DPCM_UPDATE_FE || + (update == SND_SOC_DPCM_UPDATE_BE && rtd->dpcm[dir].runtime_update)) { + if (stream >= 0) + return -EINVAL; + + stream = dir; + break; + } + } + } + + return stream; +} + static int sof_ipc4_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_pcm_hw_params *params) { @@ -804,7 +833,7 @@ static int sof_ipc4_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, struct sof_ipc4_copier *ipc4_copier; bool single_bitdepth = false; u32 valid_bits = 0; - int dir, ret; + int dir, stream, ret; if (!dai) { dev_err(component->dev, "%s: No DAI found with name %s\n", __func__, @@ -819,20 +848,36 @@ static int sof_ipc4_pcm_dai_link_fixup(struct snd_soc_pcm_runtime *rtd, return -EINVAL; } + stream = sof_ipc4_pcm_dai_link_fixup_stream(rtd); + for_each_pcm_streams(dir) { struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, dir); + if (stream >= 0 && dir != stream) + continue; + if (w) { - struct sof_ipc4_available_audio_format *available_fmt = - &ipc4_copier->available_fmt; + struct sof_ipc4_available_audio_format *available_fmt; struct snd_sof_widget *swidget = w->dobj.private; struct snd_sof_widget *pipe_widget = swidget->spipe->pipe_widget; struct sof_ipc4_pipeline *pipeline = pipe_widget->private; + struct snd_sof_dai *stream_dai = swidget->private; /* Chain DMA does not use copiers, so no fixup needed */ if (pipeline->use_chain_dma) return 0; + /* + * The playback and capture DAI widgets of a link have + * their own copiers, but share the DAI link name used + * in the DAI lookup above. Use the copier of the stream + * being configured, if known. + */ + if (dir == stream && stream_dai->private) + ipc4_copier = stream_dai->private; + + available_fmt = &ipc4_copier->available_fmt; + if (dir == SNDRV_PCM_STREAM_PLAYBACK) { if (sof_ipc4_copier_is_single_bitdepth(sdev, available_fmt->output_pin_fmts,