From 4f168be9489d46be48e43a30ef6c45f9152a4478 Mon Sep 17 00:00:00 2001 From: Kwangwoo Lee Date: Tue, 23 Jul 2019 19:44:41 +0900 Subject: [PATCH] ASoC: tegra-alt: check the allocation of dai link kzalloc() can be failed under low memory condition. In such a case, the following memcpy() can cause a panic. Thus, the return value of kzalloc() should be checked. If tegra_machine_get_dai_link_t18x() is called, the return value should also be checked. Bug 2647682 Change-Id: Ia200436a3b1877933932b9a086862f5507c8da54 Signed-off-by: Kwangwoo Lee Reviewed-on: https://git-master.nvidia.com/r/2159959 Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Sameer Pujar Reviewed-by: Ravindra Lokhande Reviewed-by: mobile promotions Tested-by: mobile promotions --- sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c b/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c index d8dcde06..feb75221 100644 --- a/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c +++ b/sound/soc/tegra-alt/utils/tegra_asoc_machine_alt.c @@ -2915,6 +2915,9 @@ struct snd_soc_dai_link *tegra_machine_get_dai_link(void) tegra_asoc_machine_links = kzalloc(size * sizeof(struct snd_soc_dai_link), GFP_KERNEL); + if (!tegra_asoc_machine_links) + return NULL; + memcpy(tegra_asoc_machine_links, link, size * sizeof(struct snd_soc_dai_link)); @@ -3024,6 +3027,9 @@ struct snd_soc_codec_conf *tegra_machine_get_codec_conf(void) tegra_asoc_codec_conf = kzalloc(size * sizeof(struct snd_soc_codec_conf), GFP_KERNEL); + if (!tegra_asoc_codec_conf) + return NULL; + memcpy(tegra_asoc_codec_conf, conf, size * sizeof(struct snd_soc_codec_conf)); @@ -3446,6 +3452,9 @@ struct snd_soc_dai_link *tegra_machine_get_dai_link_t18x(void) tegra_asoc_machine_links_t18x = kzalloc(size * sizeof(struct snd_soc_dai_link), GFP_KERNEL); + if (!tegra_asoc_machine_links_t18x) + return NULL; + memcpy(tegra_asoc_machine_links_t18x, link, size * sizeof(struct snd_soc_dai_link)); @@ -3504,6 +3513,9 @@ struct snd_soc_codec_conf *tegra_machine_get_codec_conf_t18x(void) tegra_asoc_codec_conf_t18x = kzalloc(size * sizeof(struct snd_soc_codec_conf), GFP_KERNEL); + if (!tegra_asoc_codec_conf_t18x) + return NULL; + memcpy(tegra_asoc_codec_conf_t18x, conf, size * sizeof(struct snd_soc_codec_conf));