summaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2020-06-04 18:12:16 +0100
committerMark Brown <broonie@kernel.org>2020-06-05 12:13:03 +0100
commit6e801dc411329aff592fbd48fb116183d0acdb00 (patch)
tree1fd9b044f7b74e3d08f82ed8d946dcabe4eb8282 /sound
parent97ed3e509ee6d098730d137759c627a8d674cf55 (diff)
downloadlwn-6e801dc411329aff592fbd48fb116183d0acdb00.tar.gz
lwn-6e801dc411329aff592fbd48fb116183d0acdb00.zip
ASoC: meson: fix memory leak of links if allocation of ldata fails
Currently if the allocation of ldata fails the error return path does not kfree the allocated links object. Fix this by adding an error exit return path that performs the necessary kfree'ing. Fixes: 7864a79f37b5 ("ASoC: meson: add axg sound card support") Signed-off-by: Colin Ian King <colin.king@canonical.com> Addresses-Coverity: ("Resource leak") Link: https://lore.kernel.org/r/20200604171216.60043-1-colin.king@canonical.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/meson/meson-card-utils.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/sound/soc/meson/meson-card-utils.c b/sound/soc/meson/meson-card-utils.c
index 2ca8c98e204f..5a4a91c88734 100644
--- a/sound/soc/meson/meson-card-utils.c
+++ b/sound/soc/meson/meson-card-utils.c
@@ -49,19 +49,26 @@ int meson_card_reallocate_links(struct snd_soc_card *card,
links = krealloc(priv->card.dai_link,
num_links * sizeof(*priv->card.dai_link),
GFP_KERNEL | __GFP_ZERO);
+ if (!links)
+ goto err_links;
+
ldata = krealloc(priv->link_data,
num_links * sizeof(*priv->link_data),
GFP_KERNEL | __GFP_ZERO);
-
- if (!links || !ldata) {
- dev_err(priv->card.dev, "failed to allocate links\n");
- return -ENOMEM;
- }
+ if (!ldata)
+ goto err_ldata;
priv->card.dai_link = links;
priv->link_data = ldata;
priv->card.num_links = num_links;
return 0;
+
+err_ldata:
+ kfree(links);
+err_links:
+ dev_err(priv->card.dev, "failed to allocate links\n");
+ return -ENOMEM;
+
}
EXPORT_SYMBOL_GPL(meson_card_reallocate_links);