mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free
@ 2026-11-19  8:25 Chen Yuxi
  0 siblings, 0 replies; only message in thread
From: Chen Yuxi @ 2026-11-19  8:25 UTC (permalink / raw)
  To: broonie, lgirdwood
  Cc: peter.ujfalusi, yung-chuan.liao, daniel.baluta, kai.vehmanen,
	pierre-louis.bossart, Vijendar.Mukunda, ranjani.sridharan, perex,
	tiwai, sound-open-firmware, linux-sound, linux-kernel, stable,
	yeweihua4

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@vger.kernel.org
Signed-off-by: Chen Yuxi <chenyuxi19@huawei.com>
---
 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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19  8:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19  8:25 [PATCH] ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free Chen Yuxi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®