mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chen Yuxi <chenyuxi19@huawei.com>
To: <broonie@kernel.org>, <lgirdwood@gmail.com>
Cc: <peter.ujfalusi@linux.intel.com>,
	<yung-chuan.liao@linux.intel.com>, <daniel.baluta@nxp.com>,
	<kai.vehmanen@linux.intel.com>, <pierre-louis.bossart@linux.dev>,
	<Vijendar.Mukunda@amd.com>, <ranjani.sridharan@linux.intel.com>,
	<perex@perex.cz>, <tiwai@suse.com>,
	<sound-open-firmware@alsa-project.org>,
	<linux-sound@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>, <yeweihua4@huawei.com>
Subject: [PATCH] ASoC: SOF: Intel: hda: Fix NULL deref in hw_params and hw_free
Date: Thu, 19 Nov 2026 08:25:06 +0000	[thread overview]
Message-ID: <20261119082506.2485543-1-chenyuxi19@huawei.com> (raw)

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


                 reply	other threads:[~2026-11-19  8:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119082506.2485543-1-chenyuxi19@huawei.com \
    --to=chenyuxi19@huawei.com \
    --cc=Vijendar.Mukunda@amd.com \
    --cc=broonie@kernel.org \
    --cc=daniel.baluta@nxp.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=sound-open-firmware@alsa-project.org \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.com \
    --cc=yeweihua4@huawei.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®