Browse Source

dsp: audio_ion: Add checks before memmory access

-Add check for memory access in msm_audio_ion_crash_handler

Change-Id: Idd7a51578260b2779c72040d99483de453c4330e
Ranjith 3 years ago
parent
commit
a241af4cf8
1 changed files with 21 additions and 11 deletions
  1. 21 11
      dsp/msm_audio_ion.c

+ 21 - 11
dsp/msm_audio_ion.c

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2013-2021, The Linux Foundation. All rights reserved.
- * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  */
 
 #include <linux/init.h>
@@ -610,23 +610,33 @@ void msm_audio_ion_crash_handler(void)
 	struct msm_audio_ion_private *ion_data = NULL;
 
 	pr_debug("Inside %s\n", __func__);
+	if(!msm_audio_ion_fd_list_init) {
+		pr_err("%s: list not initialized yet, hence returning .... ", __func__);
+		return;
+	}
 	mutex_lock(&(msm_audio_ion_fd_list.list_mutex));
 	list_for_each_entry(msm_audio_fd_data,
 		&msm_audio_ion_fd_list.fd_list, list) {
-		handle = msm_audio_fd_data->handle;
-		ion_data = dev_get_drvdata(msm_audio_fd_data->dev);
-		/*  clean if CMA was used*/
-		if (msm_audio_fd_data->hyp_assign) {
-			msm_audio_hyp_unassign(msm_audio_fd_data);
+		if(msm_audio_fd_data) {
+			handle = msm_audio_fd_data->handle;
+			ion_data = dev_get_drvdata(msm_audio_fd_data->dev);
+			/*  clean if CMA was used*/
+			if (msm_audio_fd_data->hyp_assign)
+				msm_audio_hyp_unassign(msm_audio_fd_data);
+			if(handle)
+				msm_audio_ion_free(handle, ion_data);
 		}
-		msm_audio_ion_free(handle, ion_data);
 	}
 	list_for_each_safe(ptr, next,
 		&msm_audio_ion_fd_list.fd_list) {
-		msm_audio_fd_data = list_entry(ptr, struct msm_audio_fd_data,
-						list);
-		list_del(&(msm_audio_fd_data->list));
-		kfree(msm_audio_fd_data);
+		if(ptr) {
+			msm_audio_fd_data = list_entry(ptr, struct msm_audio_fd_data,
+							list);
+			if(msm_audio_fd_data) {
+				list_del(&(msm_audio_fd_data->list));
+				kfree(msm_audio_fd_data);
+			}
+		}
 	}
 	mutex_unlock(&(msm_audio_ion_fd_list.list_mutex));
 }