From 0e60d1c5ce6b54cdafbf230a256d87baceea304a Mon Sep 17 00:00:00 2001 From: Keyon Jie Date: Mon, 9 Jul 2018 13:08:56 +0800 Subject: [PATCH] [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 --- sound/soc/sof/utils.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sound/soc/sof/utils.c b/sound/soc/sof/utils.c index 8f2116a453526e..215ea84dfe7e68 100644 --- a/sound/soc/sof/utils.c +++ b/sound/soc/sof/utils.c @@ -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; @@ -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);