Skip to content

Commit

Permalink
[SQUASHME]ASoC: SOF: utils: fix memory leak of names during remove()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
keyonjie committed Jul 9, 2018
1 parent 67675cb commit 0e60d1c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions sound/soc/sof/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ int sof_bes_setup(struct device *dev, struct snd_sof_dsp_ops *ops,
/* set up BE dai_links */
for (i = 0; i < link_num; i++) {
snprintf(name, 32, "NoCodec-%d", i);
links[i].name = kmemdup(name, sizeof(name), GFP_KERNEL);
links[i].name = devm_kstrdup(dev, name, GFP_KERNEL);
if (!links[i].name)
goto no_mem;
return -ENOMEM;

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

return 0;
no_mem:
/* free allocated memories and return error */
for (; i > 0; i--)
kfree(links[i - 1].name);

return -ENOMEM;
}
EXPORT_SYMBOL(sof_bes_setup);

0 comments on commit 0e60d1c

Please sign in to comment.