Skip to content

Commit

Permalink
ASoC: SOF: Intel: ASoC: SOF: Intel: hda-dai: Ensure DAI widget is val…
Browse files Browse the repository at this point in the history
…id during params

Each cpu DAI should associate with a widget. However, the topology might
not create the right number of DAI widgets for aggregated amps. And it
will cause NULL pointer deference.
Check that the DAI widget associated with the CPU DAI is valid to prevent
NULL pointer deference due to missing DAI widgets in topologies with
aggregated amps.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
  • Loading branch information
bardliao authored and ranj063 committed Nov 26, 2024
1 parent 761c938 commit 414dc95
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sound/soc/sof/intel/hda-dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ int sdw_hda_dai_hw_params(struct snd_pcm_substream *substream,
int ret;
int i;

if (!w) {
dev_err(cpu_dai->dev, "%s widget not found, check amp link num in the topology\n",
cpu_dai->name);
return -EINVAL;
}

ops = hda_dai_get_ops(substream, cpu_dai);
if (!ops) {
dev_err(cpu_dai->dev, "DAI widget ops not set\n");
Expand Down Expand Up @@ -568,6 +574,12 @@ int sdw_hda_dai_hw_params(struct snd_pcm_substream *substream,
*/
for_each_rtd_cpu_dais(rtd, i, dai) {
w = snd_soc_dai_get_widget(dai, substream->stream);
if (!w) {
dev_err(cpu_dai->dev,
"%s widget not found, check amp link num in the topology\n",
dai->name);
return -EINVAL;
}
ipc4_copier = widget_to_copier(w);
memcpy(&ipc4_copier->dma_config_tlv[cpu_dai_id], dma_config_tlv,
sizeof(*dma_config_tlv));
Expand Down
5 changes: 5 additions & 0 deletions sound/soc/sof/intel/hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ static int sdw_params_stream(struct device *dev,
struct snd_soc_dapm_widget *w = snd_soc_dai_get_widget(d, params_data->substream->stream);
struct snd_sof_dai_config_data data = { 0 };

if (!w) {
dev_err(dev, "%s widget not found, check amp link num in the topology\n",
d->name);
return -EINVAL;
}
data.dai_index = (params_data->link_id << 8) | d->id;
data.dai_data = params_data->alh_stream_id;
data.dai_node_id = data.dai_data;
Expand Down

0 comments on commit 414dc95

Please sign in to comment.