From e2c536b4819cf4af4589586909fffbad0c0e7978 Mon Sep 17 00:00:00 2001 From: Shuai Li Date: Sun, 28 Apr 2019 21:15:49 +0800 Subject: [PATCH] audio: add param check for resample [1/1] PD#SWPL-7798 Problem: Crashed when audio resample setting params are invalid. Solution: Add check method if the params is invalid. Verify: Tl1. Change-Id: I1e0396be8d401c0a49ff0de9fd7f160f0c8133ca Signed-off-by: Shuai Li --- sound/soc/amlogic/auge/resample.c | 7 ++++++- sound/soc/amlogic/auge/spdif.c | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/sound/soc/amlogic/auge/resample.c b/sound/soc/amlogic/auge/resample.c index f3a99483eec3..6b2fb6da8298 100644 --- a/sound/soc/amlogic/auge/resample.c +++ b/sound/soc/amlogic/auge/resample.c @@ -274,6 +274,11 @@ int resample_set(enum resample_idx id, enum samplerate_index index) if (!p_resample) return 0; + if (index < RATE_OFF || index > RATE_192K) { + pr_err("%s(), invalid index %d\n", __func__, index); + return 0; + } + pr_info("%s resample_%c to %s, last %s\n", __func__, (id == RESAMPLE_A) ? 'a' : 'b', @@ -284,7 +289,7 @@ int resample_set(enum resample_idx id, enum samplerate_index index) if (index == p_resample->asrc_rate_idx) return 0; #endif - p_resample->asrc_rate_idx = index; + set_resample_rate_index(id, index); resample_rate = resample_idx2rate(index); ret = audio_resample_set(p_resample, (bool)index, resample_rate); diff --git a/sound/soc/amlogic/auge/spdif.c b/sound/soc/amlogic/auge/spdif.c index 520c982a031c..ab79a49b7c1a 100644 --- a/sound/soc/amlogic/auge/spdif.c +++ b/sound/soc/amlogic/auge/spdif.c @@ -1492,6 +1492,12 @@ static int aml_spdif_parse_of(struct platform_device *pdev) if (ret < 0) p_spdif->auto_asrc = 0; + if (p_spdif->auto_asrc < RATE_OFF || + p_spdif->auto_asrc > RATE_192K) { + pr_info("%s(), inval asrc setting %d\n", + __func__, p_spdif->auto_asrc); + p_spdif->auto_asrc = RATE_OFF; + } pr_debug("SPDIF id %d asrc_id:%d auto_asrc:%d\n", p_spdif->id, p_spdif->asrc_id,