From: Douglas Anderson <dianders@chromium.org>
To: broonie@kernel.org, jeffy.chen@rock-chips.com, mka@chromium.org
Cc: briannorris@chromium.org,
Douglas Anderson <dianders@chromium.org>,
Jaroslav Kysela <perex@perex.cz>,
alsa-devel@alsa-project.org, Heiko Stuebner <heiko@sntech.de>,
linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
Takashi Iwai <tiwai@suse.com>,
Liam Girdwood <lgirdwood@gmail.com>,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ASoC: rockchip: Allocate enough memory so we don't overflow routes
Date: Fri, 29 Sep 2017 15:03:24 -0700 [thread overview]
Message-ID: <20170929220324.16413-1-dianders@chromium.org> (raw)
In the recent commit d9f9c167edae ("ASoC: rockchip: Init dapm routes
dynamically") we improperly allocated memory for the card->dapm_routes
causing us to overflow the allocation on every boot. Oops.
Let's allocate the correct amount of memory. We'll also add a check
to make sure that we don't overrun memory even if we encounter some
sort of weird device tree.
Fixes: d9f9c167edae ("ASoC: rockchip: Init dapm routes dynamically")
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
sound/soc/rockchip/rk3399_gru_sound.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index 30eed83e8a13..d64fbbd50544 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -494,13 +494,17 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
struct snd_soc_dai_link *dai;
struct snd_soc_dapm_route *routes;
int i, index;
+ int num_routes;
card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais),
GFP_KERNEL);
if (!card->dai_link)
return -ENOMEM;
- routes = devm_kzalloc(dev, sizeof(rockchip_routes),
+ num_routes = 0;
+ for (i = 0; i < ARRAY_SIZE(rockchip_routes); i++)
+ num_routes += rockchip_routes[i].num_routes;
+ routes = devm_kzalloc(dev, num_routes * sizeof(*routes),
GFP_KERNEL);
if (!routes)
return -ENOMEM;
@@ -538,6 +542,12 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
dai->platform_of_node = np_cpu;
dai->cpu_of_node = np_cpu;
+ if (card->num_dapm_routes + rockchip_routes[index].num_routes >
+ num_routes) {
+ dev_err(dev, "Too many routes\n");
+ return -EINVAL;
+ }
+
memcpy(routes + card->num_dapm_routes,
rockchip_routes[index].routes,
rockchip_routes[index].num_routes * sizeof(*routes));
--
2.14.2.822.g60be5d43e6-goog
next reply other threads:[~2017-09-29 22:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-29 22:03 Douglas Anderson [this message]
2017-10-04 11:28 ` Applied "ASoC: rockchip: Allocate enough memory so we don't overflow routes" to the asoc tree Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170929220324.16413-1-dianders@chromium.org \
--to=dianders@chromium.org \
--cc=alsa-devel@alsa-project.org \
--cc=briannorris@chromium.org \
--cc=broonie@kernel.org \
--cc=heiko@sntech.de \
--cc=jeffy.chen@rock-chips.com \
--cc=lgirdwood@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=mka@chromium.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).