diff mbox series

[2/2] ASoC: SOF: check for NULL before dereferencing

Message ID 20220318071308.GC29472@kili
State New
Headers show
Series None | expand

Commit Message

Dan Carpenter March 18, 2022, 7:13 a.m. UTC
This code dereferences "dai" before checking whether it can be NULL.

Fixes: 839e484f9e17 ("ASoC: SOF: make struct snd_sof_dai IPC agnostic")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 sound/soc/sof/sof-audio.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/sound/soc/sof/sof-audio.c b/sound/soc/sof/sof-audio.c
index 15c36a51f89f..88ddd1e2476d 100644
--- a/sound/soc/sof/sof-audio.c
+++ b/sound/soc/sof/sof-audio.c
@@ -626,10 +626,13 @@  int sof_set_up_pipelines(struct snd_sof_dev *sdev, bool verify)
 		/* update DAI config. The IPC will be sent in sof_widget_setup() */
 		if (WIDGET_IS_DAI(swidget->id)) {
 			struct snd_sof_dai *dai = swidget->private;
-			struct sof_dai_private_data *private = dai->private;
+			struct sof_dai_private_data *private;
 			struct sof_ipc_dai_config *config;
 
-			if (!dai || !private || !private->dai_config)
+			if (!dai)
+				continue;
+			private = dai->private;
+			if (!private || !private->dai_config)
 				continue;
 
 			config = private->dai_config;
@@ -918,10 +921,13 @@  static int sof_dai_get_clk(struct snd_soc_pcm_runtime *rtd, int clk_type)
 		snd_soc_rtdcom_lookup(rtd, SOF_AUDIO_PCM_DRV_NAME);
 	struct snd_sof_dai *dai =
 		snd_sof_find_dai(component, (char *)rtd->dai_link->name);
-	struct sof_dai_private_data *private = dai->private;
+	struct sof_dai_private_data *private;
 
 	/* use the tplg configured mclk if existed */
-	if (!dai || !private || !private->dai_config)
+	if (!dai)
+		return 0;
+	private = dai->private;
+	if (!private || !private->dai_config)
 		return 0;
 
 	switch (private->dai_config->type) {