diff options
author | Douglas Anderson <dianders@chromium.org> | 2017-09-29 18:03:24 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-10-04 06:30:17 -0400 |
commit | 8eae6c2585b0455f0e7200495d5e513020ca2fa2 (patch) | |
tree | 9572d35a4c168595ec9d10e4163aae728910cf6c | |
parent | 7e0dc9aeaea3ed130e090e20e9be0fc4877ddc37 (diff) |
ASoC: rockchip: Allocate enough memory so we don't overflow routes
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>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | sound/soc/rockchip/rk3399_gru_sound.c | 12 |
1 files changed, 11 insertions, 1 deletions
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, | |||
494 | struct snd_soc_dai_link *dai; | 494 | struct snd_soc_dai_link *dai; |
495 | struct snd_soc_dapm_route *routes; | 495 | struct snd_soc_dapm_route *routes; |
496 | int i, index; | 496 | int i, index; |
497 | int num_routes; | ||
497 | 498 | ||
498 | card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais), | 499 | card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais), |
499 | GFP_KERNEL); | 500 | GFP_KERNEL); |
500 | if (!card->dai_link) | 501 | if (!card->dai_link) |
501 | return -ENOMEM; | 502 | return -ENOMEM; |
502 | 503 | ||
503 | routes = devm_kzalloc(dev, sizeof(rockchip_routes), | 504 | num_routes = 0; |
505 | for (i = 0; i < ARRAY_SIZE(rockchip_routes); i++) | ||
506 | num_routes += rockchip_routes[i].num_routes; | ||
507 | routes = devm_kzalloc(dev, num_routes * sizeof(*routes), | ||
504 | GFP_KERNEL); | 508 | GFP_KERNEL); |
505 | if (!routes) | 509 | if (!routes) |
506 | return -ENOMEM; | 510 | return -ENOMEM; |
@@ -538,6 +542,12 @@ static int rockchip_sound_of_parse_dais(struct device *dev, | |||
538 | dai->platform_of_node = np_cpu; | 542 | dai->platform_of_node = np_cpu; |
539 | dai->cpu_of_node = np_cpu; | 543 | dai->cpu_of_node = np_cpu; |
540 | 544 | ||
545 | if (card->num_dapm_routes + rockchip_routes[index].num_routes > | ||
546 | num_routes) { | ||
547 | dev_err(dev, "Too many routes\n"); | ||
548 | return -EINVAL; | ||
549 | } | ||
550 | |||
541 | memcpy(routes + card->num_dapm_routes, | 551 | memcpy(routes + card->num_dapm_routes, |
542 | rockchip_routes[index].routes, | 552 | rockchip_routes[index].routes, |
543 | rockchip_routes[index].num_routes * sizeof(*routes)); | 553 | rockchip_routes[index].num_routes * sizeof(*routes)); |