Skip to content

Commit 0e60d1c

Browse files
committed
[SQUASHME]ASoC: SOF: utils: fix memory leak of names during remove()
Change to use devm_kstrdup() for string duplicate allocation, which will be freed together with dev free, to fix memory leak (names are not freed) during remove(). Signed-off-by: Keyon Jie <yang.jie@linux.intel.com>
1 parent 67675cb commit 0e60d1c

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

sound/soc/sof/utils.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ int sof_bes_setup(struct device *dev, struct snd_sof_dsp_ops *ops,
2626
/* set up BE dai_links */
2727
for (i = 0; i < link_num; i++) {
2828
snprintf(name, 32, "NoCodec-%d", i);
29-
links[i].name = kmemdup(name, sizeof(name), GFP_KERNEL);
29+
links[i].name = devm_kstrdup(dev, name, GFP_KERNEL);
3030
if (!links[i].name)
31-
goto no_mem;
31+
return -ENOMEM;
3232

3333
links[i].id = i;
3434
links[i].no_pcm = 1;
@@ -44,12 +44,6 @@ int sof_bes_setup(struct device *dev, struct snd_sof_dsp_ops *ops,
4444
card->num_links = link_num;
4545

4646
return 0;
47-
no_mem:
48-
/* free allocated memories and return error */
49-
for (; i > 0; i--)
50-
kfree(links[i - 1].name);
51-
52-
return -ENOMEM;
5347
}
5448
EXPORT_SYMBOL(sof_bes_setup);
5549

0 commit comments

Comments
 (0)