Skip to content

Commit

Permalink
ASoC: meson: fix memory leak of links if allocation of ldata fails
Browse files Browse the repository at this point in the history
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: 7864a79 ("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>
  • Loading branch information
Colin Ian King authored and Mark Brown committed Jun 5, 2020
1 parent 97ed3e5 commit 6e801dc
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions sound/soc/meson/meson-card-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 6e801dc

Please sign in to comment.