Skip to content

Commit 85e85c8

Browse files
committed
ASoC: SOF: Intel: hda: Fix NULL pointer dereference
If there's a mismatch between the DAI links in the machine driver and the topology, it is possible that the playback/capture widget is not set, especially in the case of iloopback capture for echo reference where we use the dummy DAI link. Return the error when the widget is not set to avoid a null pointer dereference like below when the topology is broken. RIP: 0010:hda_dai_get_ops.isra.0+0x14/0xa0 [snd_sof_intel_hda_common] Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
1 parent ec0e6c6 commit 85e85c8

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

sound/soc/sof/intel/hda-dai.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,22 @@ static const struct hda_dai_widget_dma_ops *
7070
hda_dai_get_ops(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai)
7171
{
7272
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(cpu_dai, substream->stream);
73-
struct snd_sof_widget *swidget = w->dobj.private;
73+
struct snd_sof_widget *swidget;
7474
struct snd_sof_dev *sdev;
7575
struct snd_sof_dai *sdai;
7676

77-
sdev = widget_to_sdev(w);
77+
/*
78+
* this is unlikely if the topology and the machine driver DAI links match.
79+
* But if there's a missing DAI link in topology, this will prevent a NULL pointer
80+
* dereference later on.
81+
*/
82+
if (!w) {
83+
dev_err(cpu_dai->dev, "%s: widget is NULL\n", __func__);
84+
return NULL;
85+
}
7886

87+
sdev = widget_to_sdev(w);
88+
swidget = w->dobj.private;
7989
if (!swidget) {
8090
dev_err(sdev->dev, "%s: swidget is NULL\n", __func__);
8191
return NULL;

0 commit comments

Comments
 (0)