* [PATCH] ASoC: SOF: topology: fix memory leak in snd_sof_load_topology
@ 2026-06-10 3:11 Zhao Dongdong
2026-06-10 6:58 ` Péter Ujfalusi
0 siblings, 1 reply; 3+ messages in thread
From: Zhao Dongdong @ 2026-06-10 3:11 UTC (permalink / raw)
To: lgirdwood, peter.ujfalusi, daniel.baluta
Cc: linux-sound, linux-kernel, sound-open-firmware, Zhao Dongdong, stable
From: Zhao Dongdong <zhaodongdong@kylinos.cn>
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@vger.kernel.org
Signed-off-by: Zhao Dongdong <zhaodongdong@kylinos.cn>
---
sound/soc/sof/topology.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
index 63d582c65891..09d6dc01814c 100644
--- a/sound/soc/sof/topology.c
+++ b/sound/soc/sof/topology.c
@@ -2534,7 +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");
- return -EINVAL;
+ ret = -EINVAL;
+ goto out;
}
tplg_files[0] = file;
tplg_cnt = 1;
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ASoC: SOF: topology: fix memory leak in snd_sof_load_topology
2026-06-10 3:11 [PATCH] ASoC: SOF: topology: fix memory leak in snd_sof_load_topology Zhao Dongdong
@ 2026-06-10 6:58 ` Péter Ujfalusi
2026-06-10 7:09 ` [PATCH] ASoC: SOF: topology: fix memory leak in Zhao Dongdong
0 siblings, 1 reply; 3+ messages in thread
From: Péter Ujfalusi @ 2026-06-10 6:58 UTC (permalink / raw)
To: Zhao Dongdong, lgirdwood, daniel.baluta
Cc: linux-sound, linux-kernel, sound-open-firmware, Zhao Dongdong, stable
On 10/06/2026 06:11, Zhao Dongdong wrote:
> From: Zhao Dongdong <zhaodongdong@kylinos.cn>
>
> 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@vger.kernel.org
> Signed-off-by: Zhao Dongdong <zhaodongdong@kylinos.cn>
> ---
> sound/soc/sof/topology.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
> index 63d582c65891..09d6dc01814c 100644
> --- a/sound/soc/sof/topology.c
> +++ b/sound/soc/sof/topology.c
> @@ -2534,7 +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");
> - return -EINVAL;
> + ret = -EINVAL;
> + goto out;
I think adding
kfree(tplg_files);
before the return would look better and align better with the code, here
we are sure that led controls have not been created.
> }
> tplg_files[0] = file;
> tplg_cnt = 1;
--
Péter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ASoC: SOF: topology: fix memory leak in
2026-06-10 6:58 ` Péter Ujfalusi
@ 2026-06-10 7:09 ` Zhao Dongdong
0 siblings, 0 replies; 3+ messages in thread
From: Zhao Dongdong @ 2026-06-10 7:09 UTC (permalink / raw)
To: lgirdwood, peter.ujfalusi, daniel.baluta; +Cc: linux-sound, linux-kernel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=y, Size: 1683 bytes --]
On Wed, 10 Jun 2026 09:58:13 +0300, =?UTF-8?Q?P=C3=A9ter_Ujfalusi?= <peter.ujfalusi@linux.intel.com> wrote:
>
>
>
> On 10/06/2026 06:11, Zhao Dongdong wrote:
> > From: Zhao Dongdong <zhaodongdong@kylinos.cn>
> >
> > 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@vger.kernel.org
> > Signed-off-by: Zhao Dongdong <zhaodongdong@kylinos.cn>
> > ---
> > sound/soc/sof/topology.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c
> > index 63d582c65891..09d6dc01814c 100644
> > --- a/sound/soc/sof/topology.c
> > +++ b/sound/soc/sof/topology.c
> > @@ -2534,7 +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");
> > - return -EINVAL;
> > + ret = -EINVAL;
> > + goto out;
>
> I think adding
> kfree(tplg_files);
> before the return would look better and align better with the code, here
> we are sure that led controls have not been created.
>
> > }
> > tplg_files[0] = file;
> > tplg_cnt = 1;
>
> --
> Péter
Thanks for your review.
I will send v2 patch.
--
Regards,
Zhao Dongdong
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-06-10 7:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-10 3:11 [PATCH] ASoC: SOF: topology: fix memory leak in snd_sof_load_topology Zhao Dongdong
2026-06-10 6:58 ` Péter Ujfalusi
2026-06-10 7:09 ` [PATCH] ASoC: SOF: topology: fix memory leak in Zhao Dongdong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome