[Bugfix][T8TSK-304] revert file mtk-afe-platform-driver.c of [merge mtk official patch 5th AP patch release]

Only Configure: No
Affected branch: MR3.0-Merge-v2.0-ZK
Affected module: N/A
Is it affected on both ZXIC and MTK: only MTK
Self-test: Yes
Doc Update: No

Change-Id: I83a7226a9e0e1623226b29dbbc4a441c3d27d3ee
(cherry picked from commit d6eb6994388cfa0f294b08f752083d5369152b93)
diff --git a/src/kernel/linux/v4.19/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/src/kernel/linux/v4.19/sound/soc/mediatek/common/mtk-afe-platform-driver.c
index a784ee5..cca4bf2 100755
--- a/src/kernel/linux/v4.19/sound/soc/mediatek/common/mtk-afe-platform-driver.c
+++ b/src/kernel/linux/v4.19/sound/soc/mediatek/common/mtk-afe-platform-driver.c
@@ -93,45 +93,75 @@
 static snd_pcm_uframes_t mtk_afe_pcm_pointer
 			 (struct snd_pcm_substream *substream)
 {
-	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
-	struct mtk_base_afe *afe;
-	struct mtk_base_afe_memif *memif = NULL;
-	const struct mtk_base_memif_data *memif_data;
-	struct regmap *regmap;
-	struct device *dev;
-	int reg_ofs_base;
-	int reg_ofs_cur;
+	struct snd_soc_pcm_runtime *rtd;
+	struct snd_soc_component *component;
+    struct mtk_base_afe *afe;
+    struct mtk_base_afe_memif *memif;
+    const struct mtk_base_memif_data *memif_data;
+    struct regmap *regmap;
+    struct device *dev;
+    int reg_ofs_base;
+    int reg_ofs_cur;
 	unsigned int hw_ptr = 0, hw_base = 0;
 	int ret, pcm_ptr_bytes;
 
-	if (component == NULL)
-		return -EINVAL;
-	afe = snd_soc_component_get_drvdata(component);
-	if (afe == NULL)
-		return -EINVAL;
-	dev = afe->dev;
+    if(substream == NULL)
+    {
+        dev_err(NULL, "%s substream is NULL\n", __func__);
+        return -EINVAL;
+    }
 
-	if (rtd->cpu_dai->id >= 0 && rtd->cpu_dai->id < afe->memif_size) {
-		memif = &afe->memif[rtd->cpu_dai->id];
-	}
-	if (memif == NULL) {
-		dev_err(dev, "%s memif NULL\n", __func__);
-		return -EINVAL;
-	}
-	memif_data = memif->data;
-	if (memif_data == NULL) {
-		dev_err(dev, "%s memif_data NULL\n", __func__);
-		return -EINVAL;
-	}
-	regmap = afe->regmap;
-	if (regmap == NULL) {
-		dev_err(dev, "%s regmap NULL\n", __func__);
-		return -EINVAL;
-	}
+    rtd = substream->private_data;
 
-	reg_ofs_base = memif_data->reg_ofs_base;
-	reg_ofs_cur = memif_data->reg_ofs_cur;
+    if(rtd == NULL)
+    {
+        dev_err(NULL, "%s rtd is NULL\n", __func__);
+        return -EINVAL;
+    }
+
+    component = snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
+
+    if (component == NULL) {
+      dev_err(NULL, "%s component NULL\n", __func__);
+      return -EINVAL;
+    }
+    afe = snd_soc_component_get_drvdata(component);
+    if (afe == NULL) {
+        dev_err(NULL, "%s afe NULL\n", __func__);
+        return -EINVAL;
+    }
+
+    dev = afe->dev;
+    if(dev == NULL){
+        dev_err(NULL, "%s dev is NULL\n", __func__);
+      //  return -EINVAL;
+    }
+
+    if (rtd->cpu_dai->id >= 0 && rtd->cpu_dai->id < afe->memif_size) {
+        memif = &afe->memif[rtd->cpu_dai->id];
+    }
+    else {
+       dev_err(dev, "%s rtd->cpu_dai->id %d is error\n", __func__ , rtd->cpu_dai->id);
+       return -EINVAL;
+    }
+    memif = &afe->memif[rtd->cpu_dai->id];
+    if (memif == NULL) {
+        dev_err(dev, "%s memif NULL\n", __func__);
+        return -EINVAL;
+    }
+    memif_data = memif->data;
+    if (memif_data == NULL) {
+        dev_err(dev, "%s memif_data NULL\n", __func__);
+        return -EINVAL;
+    }
+    regmap = afe->regmap;
+    if (regmap == NULL) {
+        dev_err(dev, "%s regmap 2 NULL\n", __func__);
+        return -EINVAL;
+    }
+   
+    reg_ofs_base = memif_data->reg_ofs_base;
+    reg_ofs_cur = memif_data->reg_ofs_cur;
 
 	ret = regmap_read(regmap, reg_ofs_cur, &hw_ptr);
 	if (ret || hw_ptr == 0) {
@@ -149,6 +179,11 @@
 
 	pcm_ptr_bytes = hw_ptr - hw_base;
 
+    if(pcm_ptr_bytes <0)
+    {
+        dev_err(dev, "%s pcm_ptr_bytes < 0 hw_ptr is %d, hw_base is %d \n", __func__ , hw_ptr, hw_base);
+    }
+
 POINTER_RETURN_FRAMES:
 	pcm_ptr_bytes = word_size_align(pcm_ptr_bytes);
 	return bytes_to_frames(substream->runtime, pcm_ptr_bytes);