Commit 9b91d0ec authored by Yu Liao's avatar Yu Liao Committed by Mark Brown

ASoC: SOF: topology: Fix memory leak in sof_control_load()

scontrol doesn't get freed when kstrdup returns NULL.
Fix by free iscontrol in that case.

     scontrol = kzalloc(sizeof(*scontrol), GFP_KERNEL);
     if (!scontrol)
         return -ENOMEM;

     scontrol->name = kstrdup(hdr->name, GFP_KERNEL);
     if (!scontrol->name)
         return -ENOMEM;
Signed-off-by: default avatarYu Liao <liaoyu15@huawei.com>
Link: https://lore.kernel.org/r/20220318021616.2599630-1-liaoyu15@huawei.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 20744617
...@@ -904,8 +904,10 @@ static int sof_control_load(struct snd_soc_component *scomp, int index, ...@@ -904,8 +904,10 @@ static int sof_control_load(struct snd_soc_component *scomp, int index,
return -ENOMEM; return -ENOMEM;
scontrol->name = kstrdup(hdr->name, GFP_KERNEL); scontrol->name = kstrdup(hdr->name, GFP_KERNEL);
if (!scontrol->name) if (!scontrol->name) {
kfree(scontrol);
return -ENOMEM; return -ENOMEM;
}
scontrol->scomp = scomp; scontrol->scomp = scomp;
scontrol->access = kc->access; scontrol->access = kc->access;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment