From: Yu Liao Date: Fri, 18 Mar 2022 02:16:16 +0000 (+0800) Subject: ASoC: SOF: topology: Fix memory leak in sof_control_load() X-Git-Tag: v6.1-rc5~1398^2~18^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b91d0ece22b9ab37fc185511c7f992e51c93d6e;p=platform%2Fkernel%2Flinux-starfive.git 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: Yu Liao Link: https://lore.kernel.org/r/20220318021616.2599630-1-liaoyu15@huawei.com Signed-off-by: Mark Brown --- diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 5953d10..3e5b319b 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -904,8 +904,10 @@ static int sof_control_load(struct snd_soc_component *scomp, int index, return -ENOMEM; scontrol->name = kstrdup(hdr->name, GFP_KERNEL); - if (!scontrol->name) + if (!scontrol->name) { + kfree(scontrol); return -ENOMEM; + } scontrol->scomp = scomp; scontrol->access = kc->access;