From bb992b58b1c1d31923a198389b841d160917cfcd Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Fri, 22 Nov 2019 14:34:55 -0600 Subject: [PATCH] ASoC: SOF: Intel: hda: hda-dai: fix oops on hda_link .free When the PCM_PARAM IPC fails, the kernel oopses in the HDaudio link DMA .free operation. The root cause is a NULL dma_data. This patches makes sure the dma_data is properly save in hw_params, even if there are additional errors and tested in hw_free. Opens: 1. the entire flow with hw_params used on system resume looks like a hack. 2. it's not clear why the problem actually happens on hw_free, maybe that's because of the -EBUSY call? Trace with this patch: 14.509636] sof-audio-pci 0000:00:1f.3: pcm: open stream 0 dir 1 [ 14.509643] sof-audio-pci 0000:00:1f.3: period min 192 max 16384 bytes [ 14.509646] sof-audio-pci 0000:00:1f.3: period count 2 max 16 [ 14.509648] sof-audio-pci 0000:00:1f.3: buffer max 65536 bytes [ 14.510003] sof-audio-pci 0000:00:1f.3: ipc tx: 0x80010000: GLB_DAI_MSG: CONFIG [ 14.510114] sof-audio-pci 0000:00:1f.3: ipc tx succeeded: 0x80010000: GLB_DAI_MSG: CONFIG [ 14.510135] sof-audio-pci 0000:00:1f.3: format_val=49, rate=48000, ch=2, format=10 [ 14.510144] sof-audio-pci 0000:00:1f.3: pcm: hw params stream 0 dir 1 [ 14.510149] sof-audio-pci 0000:00:1f.3: generating page table for 00000000ce69792e size 0x4b00 pages 5 [ 14.510157] sof-audio-pci 0000:00:1f.3: FW Poll Status: reg=0x40000 successful [ 14.510175] sof-audio-pci 0000:00:1f.3: FW Poll Status: reg=0x40000 successful [ 14.510179] sof-audio-pci 0000:00:1f.3: period_bytes:0x12c0 [ 14.510182] sof-audio-pci 0000:00:1f.3: periods:4 [ 14.510197] sof-audio-pci 0000:00:1f.3: stream_tag 2 [ 14.510209] sof-audio-pci 0000:00:1f.3: ipc tx: 0x60010000: GLB_STREAM_MSG: PCM_PARAMS [ 14.510513] sof-audio-pci 0000:00:1f.3: error: ipc error for 0x60010000 size 20 [ 14.510520] sof-audio-pci 0000:00:1f.3: error: hw params ipc failed for stream 2 [ 14.510525] sof-audio-pci 0000:00:1f.3: ASoC: 0000:00:1f.3 hw params failed: -22 [ 14.510530] HDA Analog: ASoC: hw_params FE failed -22 [ 14.510553] sof-audio-pci 0000:00:1f.3: ipc tx: 0x80010000: GLB_DAI_MSG: CONFIG [ 14.510668] sof-audio-pci 0000:00:1f.3: ipc tx succeeded: 0x80010000: GLB_DAI_MSG: CONFIG [ 14.510677] sof-audio-pci 0000:00:1f.3: pcm: free stream 0 dir 1 [ 14.510690] sof-audio-pci 0000:00:1f.3: hda_link_hw_free: link_dev is not assigned [ 14.510821] sof-audio-pc GitHub issue: https://github.com/thesofproject/linux/issues/1417 Signed-off-by: Pierre-Louis Bossart --- sound/soc/sof/intel/hda-dai.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sound/soc/sof/intel/hda-dai.c b/sound/soc/sof/intel/hda-dai.c index 2d9ac0035bd2fc..7d2903a675034d 100644 --- a/sound/soc/sof/intel/hda-dai.c +++ b/sound/soc/sof/intel/hda-dai.c @@ -217,6 +217,8 @@ static int hda_link_hw_params(struct snd_pcm_substream *substream, link_dev = hda_link_stream_assign(bus, substream); if (!link_dev) return -EBUSY; + + snd_soc_dai_set_dma_data(dai, substream, (void *)link_dev); } stream_tag = hdac_stream(link_dev)->stream_tag; @@ -229,8 +231,6 @@ static int hda_link_hw_params(struct snd_pcm_substream *substream, if (ret < 0) return ret; - snd_soc_dai_set_dma_data(dai, substream, (void *)link_dev); - link = snd_hdac_ext_bus_get_link(bus, codec_dai->component->name); if (!link) return -EINVAL; @@ -362,6 +362,13 @@ static int hda_link_hw_free(struct snd_pcm_substream *substream, bus = hstream->bus; rtd = snd_pcm_substream_chip(substream); link_dev = snd_soc_dai_get_dma_data(dai, substream); + + if (!link_dev) { + dev_dbg(dai->dev, + "%s: link_dev is not assigned\n", __func__); + return -EINVAL; + } + hda_stream = hstream_to_sof_hda_stream(link_dev); /* free the link DMA channel in the FW */