[PATCH v2] ASoC: SOF: topology: fix memory leak in snd_sof_load_topology
From: Zhao Dongdong
Date: Wed Jun 10 2026 - 03:21:12 EST
From: Zhao Dongdong <zhaodongdong@xxxxxxxxxx>
When the topology filename contains "dummy" and tplg_cnt is 0, the
function returns -EINVAL directly without freeing the tplg_files
allocated by kcalloc() at line 2497. This leaks memory on every
such topology load attempt.
Fix this by setting ret = -EINVAL and jumping to the out: label,
which already handles the kfree(tplg_files) cleanup.
Fixes: 99c159279c6d ("ASoC: SOF: don't check the existence of dummy topology")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Zhao Dongdong <zhaodongdong@xxxxxxxxxx>
---
v2: add kfree(tplg_files) before the return
v1: https://lore.kernel.org/all/tencent_D87B6446BC0B517BEF9D4731C6CD8B288206@xxxxxx/
---
sound/soc/sof/topology.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index 63d582c65891..a368e257c459 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -2534,6 +2534,8 @@ int snd_sof_load_topology(struct snd_soc_component *scomp, const char *file)
if (strstr(file, "dummy")) {
dev_err(scomp->dev,
"Function topology is required, please upgrade sof-firmware\n");
+
+ kfree(tplg_files);
return -EINVAL;
}
tplg_files[0] = file;
--
2.25.1