summaryrefslogtreecommitdiffstats
path: root/sound/soc/mediatek
diff options
context:
space:
mode:
authorTrevor Wu <trevor.wu@mediatek.com>2021-09-10 17:26:13 +0800
committerMark Brown <broonie@kernel.org>2021-09-10 15:08:26 +0100
commit1dd038522615b70f5f8945c5631e9e2fa5bd58b1 (patch)
treebe4c26c17897aea0296efa5a46b7eea6f1b0ddf8 /sound/soc/mediatek
parent26be23af1866eead5a29f8501f9d774ac277d0bd (diff)
downloadlinux-stable-1dd038522615b70f5f8945c5631e9e2fa5bd58b1.tar.gz
linux-stable-1dd038522615b70f5f8945c5631e9e2fa5bd58b1.tar.bz2
linux-stable-1dd038522615b70f5f8945c5631e9e2fa5bd58b1.zip
ASoC: mediatek: common: handle NULL case in suspend/resume function
When memory allocation for afe->reg_back_up fails, reg_back_up can't be used. Keep the suspend/resume flow but skip register backup when afe->reg_back_up is NULL, in case illegal memory access happens. Fixes: 283b612429a2 ("ASoC: mediatek: implement mediatek common structure") Signed-off-by: Trevor Wu <trevor.wu@mediatek.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Link: https://lore.kernel.org/r/20210910092613.30188-1-trevor.wu@mediatek.com Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/mediatek')
-rw-r--r--sound/soc/mediatek/common/mtk-afe-fe-dai.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/sound/soc/mediatek/common/mtk-afe-fe-dai.c b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
index baaa5881b1d4..e95c7c018e7d 100644
--- a/sound/soc/mediatek/common/mtk-afe-fe-dai.c
+++ b/sound/soc/mediatek/common/mtk-afe-fe-dai.c
@@ -334,9 +334,11 @@ int mtk_afe_suspend(struct snd_soc_component *component)
devm_kcalloc(dev, afe->reg_back_up_list_num,
sizeof(unsigned int), GFP_KERNEL);
- for (i = 0; i < afe->reg_back_up_list_num; i++)
- regmap_read(regmap, afe->reg_back_up_list[i],
- &afe->reg_back_up[i]);
+ if (afe->reg_back_up) {
+ for (i = 0; i < afe->reg_back_up_list_num; i++)
+ regmap_read(regmap, afe->reg_back_up_list[i],
+ &afe->reg_back_up[i]);
+ }
afe->suspended = true;
afe->runtime_suspend(dev);
@@ -356,12 +358,13 @@ int mtk_afe_resume(struct snd_soc_component *component)
afe->runtime_resume(dev);
- if (!afe->reg_back_up)
+ if (!afe->reg_back_up) {
dev_dbg(dev, "%s no reg_backup\n", __func__);
-
- for (i = 0; i < afe->reg_back_up_list_num; i++)
- mtk_regmap_write(regmap, afe->reg_back_up_list[i],
- afe->reg_back_up[i]);
+ } else {
+ for (i = 0; i < afe->reg_back_up_list_num; i++)
+ mtk_regmap_write(regmap, afe->reg_back_up_list[i],
+ afe->reg_back_up[i]);
+ }
afe->suspended = false;
return 0;