[PATCH] ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free
From: Chen Yuxi
Date: Thu Nov 19 2026 - 03:45:11 EST
When the topology and the machine driver DAI links do not match,
the DAI widget may be missing and hda_dai_get_ops() returns NULL.
However, in hda_dai_hw_params_data() and hda_dai_hw_free(), the sdev
pointer is obtained by dereferencing the DAI widget at declaration
time, before the ops check, so a NULL widget is dereferenced before
the intended error path can run.
Move both sdev assignments after the ops check. Also use dai->dev
instead of sdev->dev for the error message in hda_dai_hw_params_data(),
since sdev cannot be obtained when the DAI widget is missing.
Fixes: de8e2d5d8024 ("ASoC: SOF: Intel: hda-dai: remove use of cpu_dai->component drvdata")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Chen Yuxi <chenyuxi19@xxxxxxxxxx>
---
sound/soc/sof/intel/hda-dai.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c
index 7d920d43ef2a..987a4deeee28 100644
--- a/sound/soc/sof/intel/hda-dai.c
+++ b/sound/soc/sof/intel/hda-dai.c
@@ -223,13 +223,15 @@ static int __maybe_unused hda_dai_hw_free(struct snd_pcm_substream *substream,
{
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, cpu_dai);
struct hdac_ext_stream *hext_stream;
- struct snd_sof_dev *sdev = dai_to_sdev(substream, cpu_dai);
+ struct snd_sof_dev *sdev;
if (!ops) {
dev_err(cpu_dai->dev, "DAI widget ops not set\n");
return -EINVAL;
}
+ sdev = dai_to_sdev(substream, cpu_dai);
+
hext_stream = ops->get_hext_stream(sdev, cpu_dai, substream);
if (!hext_stream)
return 0;
@@ -246,14 +248,16 @@ static int __maybe_unused hda_dai_hw_params_data(struct snd_pcm_substream *subst
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(dai, substream->stream);
const struct hda_dai_widget_dma_ops *ops = hda_dai_get_ops(substream, dai);
struct hdac_ext_stream *hext_stream;
- struct snd_sof_dev *sdev = widget_to_sdev(w);
+ struct snd_sof_dev *sdev;
int ret;
if (!ops) {
- dev_err(sdev->dev, "DAI widget ops not set\n");
+ dev_err(dai->dev, "DAI widget ops not set\n");
return -EINVAL;
}
+ sdev = widget_to_sdev(w);
+
hext_stream = ops->get_hext_stream(sdev, dai, substream);
if (hext_stream && hext_stream->link_prepared)
return 0;
--
2.34.1