diff mbox series

ASoC: SOF: ipc4-topology: don't allocate blob if it will not be used

Message ID 20230307110830.2178-1-peter.ujfalusi@linux.intel.com
State New
Headers show
Series ASoC: SOF: ipc4-topology: don't allocate blob if it will not be used | expand

Commit Message

Peter Ujfalusi March 7, 2023, 11:08 a.m. UTC
From: Bard Liao <yung-chuan.liao@linux.intel.com>

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>
---
 sound/soc/sof/ipc4-topology.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

Mark Brown March 8, 2023, 1:52 p.m. UTC | #1
On Tue, 07 Mar 2023 13:08:30 +0200, Peter Ujfalusi wrote:
> 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.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: SOF: ipc4-topology: don't allocate blob if it will not be used
      commit: 3c50211f2d534a5b766b1ff3c6cf6f7bd0bae753

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
diff mbox series

Patch

diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c
index cc641355ba31..1ee046aaf46f 100644
--- a/sound/soc/sof/ipc4-topology.c
+++ b/sound/soc/sof/ipc4-topology.c
@@ -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) {