audio: add param check for resample [1/1]
authorShuai Li <shuai.li@amlogic.com>
Sun, 28 Apr 2019 13:15:49 +0000 (21:15 +0800)
committerNick Xie <nick@khadas.com>
Mon, 5 Aug 2019 06:06:16 +0000 (14:06 +0800)
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 <shuai.li@amlogic.com>
sound/soc/amlogic/auge/resample.c
sound/soc/amlogic/auge/spdif.c

index 7c56eb1..e429f4d 100644 (file)
@@ -246,16 +246,22 @@ int resample_set(int id, int index)
        if (!p_resample)
                return 0;
 
+       if (index < 0 || index > 7) {
+               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',
+               auge_resample_texts[index],
+               auge_resample_texts[p_resample->asrc_rate_idx]);
+
        if (index == p_resample->asrc_rate_idx)
                return 0;
 
        p_resample->asrc_rate_idx = index;
 
-       pr_info("%s resample_%c %s\n",
-               __func__,
-               (id == 0) ? 'a' : 'b',
-               auge_resample_texts[index]);
-
        if (audio_resample_set(p_resample, (bool)index, resample_rate))
                return 0;
 
index 885be09..11066d7 100644 (file)
@@ -1476,6 +1476,12 @@ static int aml_spdif_parse_of(struct platform_device *pdev)
                if (ret < 0)
                        p_spdif->auto_asrc = 0;
 
+               if (p_spdif->auto_asrc < 0 ||
+                               p_spdif->auto_asrc > 7) {
+                       pr_info("%s(), inval asrc setting %d\n",
+                               __func__, p_spdif->auto_asrc);
+                       p_spdif->auto_asrc = 0;
+               }
                pr_debug("SPDIF id %d asrc_id:%d auto_asrc:%d\n",
                        p_spdif->id,
                        p_spdif->asrc_id,