ASoC: SOF: ipc4-topology: don't allocate blob if it will not be used
authorBard Liao <yung-chuan.liao@linux.intel.com>
Tue, 7 Mar 2023 11:08:30 +0000 (13:08 +0200)
committerMark Brown <broonie@kernel.org>
Tue, 7 Mar 2023 13:58:19 +0000 (13:58 +0000)
A copier blob will be only used when a copier is connected in the
topology. An ALH copier in playback direction that doesn't have any
source means the copier is not connected in the topology. Thus, we
don't need to allocate the blob.
The patch doesn't do the same test before freeing the blob because
the blob is null and it is fine to free null.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Link: https://lore.kernel.org/r/20230307110830.2178-1-peter.ujfalusi@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/sof/ipc4-topology.c

index 3e27c7a48ebd39a3136063ee9d4daccf07047cb7..93b2855388d5a5261f7fc7e74cdf807bcce5f0f5 100644 (file)
@@ -517,7 +517,23 @@ static int sof_ipc4_widget_setup_comp_dai(struct snd_sof_widget *swidget)
        {
                struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp);
                struct sof_ipc4_alh_configuration_blob *blob;
+               struct snd_soc_dapm_path *p;
                struct snd_sof_widget *w;
+               int src_num = 0;
+
+               snd_soc_dapm_widget_for_each_source_path(swidget->widget, p)
+                       src_num++;
+
+               if (swidget->id == snd_soc_dapm_dai_in && src_num == 0) {
+                       /*
+                        * The blob will not be used if the ALH copier is playback direction
+                        * and doesn't connect to any source.
+                        * It is fine to call kfree(ipc4_copier->copier_config) since
+                        * ipc4_copier->copier_config is null.
+                        */
+                       ret = 0;
+                       break;
+               }
 
                blob = kzalloc(sizeof(*blob), GFP_KERNEL);
                if (!blob) {