Forráskód Böngészése

qcacld-3.0: Add a function to free fields of saved scan command

saved_scan_cmd has many fields that are allocated separately during
profile save operations. Add a routine to free those memory objects,
release the profile and avoid memory leaks.

CRs-Fixed: 2012430
Change-Id: I0d9fcb29ca7f8290692ba4b688ffe025d5b5d747
Deepak Dhamdhere 8 éve
szülő
commit
6f7fbbeb17

+ 2 - 7
core/sme/src/common/sme_api.c

@@ -252,6 +252,7 @@ static QDF_STATUS sme_process_set_hw_mode_resp(tpAniSirGlobal mac, uint8_t *msg)
 			saved_cmd->u.scanCmd.pToRoamProfile = NULL;
 		}
 		if (saved_cmd) {
+			csr_saved_scan_cmd_free_fields(mac, saved_cmd);
 			qdf_mem_free(saved_cmd);
 			saved_cmd = NULL;
 			mac->sme.saved_scan_cmd = NULL;
@@ -266,13 +267,7 @@ static QDF_STATUS sme_process_set_hw_mode_resp(tpAniSirGlobal mac, uint8_t *msg)
 			csr_scan_handle_search_for_ssid_failure(mac,
 					session_id);
 		}
-		if (session->scan_info.roambssentry)
-			qdf_mem_free(session->scan_info.roambssentry);
-		if (session->scan_info.profile) {
-			csr_release_profile(mac, session->scan_info.profile);
-			qdf_mem_free(session->scan_info.profile);
-			session->scan_info.profile = NULL;
-		}
+		csr_saved_scan_cmd_free_fields(mac, session);
 #endif
 	}
 

+ 65 - 39
core/sme/src/csr/csr_api_scan.c

@@ -2598,6 +2598,32 @@ csr_diag_scan_complete(tpAniSirGlobal mac_ctx,
 #endif /* #ifdef FEATURE_WLAN_DIAG_SUPPORT_CSR */
 
 #ifdef NAPIER_SCAN
+/**
+ * csr_saved_scan_cmd_free_fields() - Free internal fields of scan command
+ *
+ * @mac_ctx: Global MAC context
+ * @saved_scan_cmd: Pointer to scan command
+ *
+ * Frees data structures allocated inside saved_scan_cmd and releases
+ * the profile.
+ * Return: None
+ */
+
+void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx,
+				    tCsrRoamSession *session)
+{
+	if (session->scan_info.profile) {
+		csr_release_profile(mac_ctx,
+				    session->scan_info.profile);
+		qdf_mem_free(session->scan_info.profile);
+		session->scan_info.profile = NULL;
+	}
+
+	if (session->scan_info.roambssentry) {
+		qdf_mem_free(session->scan_info.roambssentry);
+		session->scan_info.roambssentry = NULL;
+	}
+}
 /**
  * csr_save_profile() - Save the profile info from sme command
  * @mac_ctx: Global MAC context
@@ -2659,16 +2685,7 @@ static QDF_STATUS csr_save_profile(tpAniSirGlobal mac_ctx,
 error:
 	csr_scan_handle_search_for_ssid_failure(mac_ctx,
 			session_id);
-	if (session->scan_info.roambssentry) {
-		qdf_mem_free(session->scan_info.roambssentry);
-		session->scan_info.roambssentry = NULL;
-	}
-	if (session->scan_info.profile) {
-		csr_release_profile(mac_ctx,
-				    session->scan_info.profile);
-		qdf_mem_free(session->scan_info.profile);
-		session->scan_info.profile = NULL;
-	}
+	csr_saved_scan_cmd_free_fields(mac_ctx, session);
 
 	return QDF_STATUS_E_FAILURE;
 }
@@ -2720,6 +2737,37 @@ static void csr_handle_nxt_cmd(tpAniSirGlobal mac_ctx,
 	}
 }
 #else
+/**
+ * csr_saved_scan_cmd_free_fields() - Free internal fields of scan command
+ *
+ * @mac_ctx: Global MAC context
+ * @saved_scan_cmd: Pointer to scan command
+ *
+ * Frees data structures allocated inside saved_scan_cmd and releases
+ * the profile.
+ * Return: None
+ */
+
+void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx,
+				    tSmeCmd *saved_scan_cmd)
+{
+	if (saved_scan_cmd->u.scanCmd.pToRoamProfile) {
+		csr_release_profile(mac_ctx,
+				    saved_scan_cmd->u.scanCmd.pToRoamProfile);
+		qdf_mem_free(saved_scan_cmd->u.scanCmd.pToRoamProfile);
+		saved_scan_cmd->u.scanCmd.pToRoamProfile = NULL;
+	}
+	if (saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList) {
+		qdf_mem_free(saved_scan_cmd->u.scanCmd.u.
+			     scanRequest.SSIDs.SSIDList);
+		saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList = NULL;
+	}
+	if (saved_scan_cmd->u.roamCmd.pRoamBssEntry) {
+		qdf_mem_free(saved_scan_cmd->u.roamCmd.pRoamBssEntry);
+		saved_scan_cmd->u.roamCmd.pRoamBssEntry = NULL;
+	}
+}
+
 /**
  * csr_save_profile() - Save the profile info from sme command
  * @mac_ctx: Global MAC context
@@ -2813,15 +2861,7 @@ static QDF_STATUS csr_save_profile(tpAniSirGlobal mac_ctx,
 error:
 	csr_scan_handle_search_for_ssid_failure(mac_ctx,
 			command);
-	if (save_cmd->u.roamCmd.pRoamBssEntry)
-		qdf_mem_free(save_cmd->u.roamCmd.pRoamBssEntry);
-	if (save_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList)
-		qdf_mem_free(save_cmd->u.scanCmd.u.scanRequest.SSIDs.SSIDList);
-	if (save_cmd->u.scanCmd.pToRoamProfile) {
-		csr_release_profile(mac_ctx,
-				    save_cmd->u.scanCmd.pToRoamProfile);
-		qdf_mem_free(save_cmd->u.scanCmd.pToRoamProfile);
-	}
+	csr_saved_scan_cmd_free_fields(mac_ctx, save_cmd);
 
 	return QDF_STATUS_E_FAILURE;
 }
@@ -2900,26 +2940,8 @@ csr_handle_nxt_cmd(tpAniSirGlobal mac_ctx, tSmeCmd *pCommand,
 					chan, pCommand->sessionId, ret);
 		saved_scan_cmd = (tSmeCmd *)mac_ctx->sme.saved_scan_cmd;
 		if (saved_scan_cmd) {
-			csr_release_profile(mac_ctx, saved_scan_cmd->u.scanCmd.
-					    pToRoamProfile);
-			if (saved_scan_cmd->u.scanCmd.pToRoamProfile) {
-				qdf_mem_free(saved_scan_cmd->u.scanCmd.
-					     pToRoamProfile);
-				saved_scan_cmd->u.scanCmd.
-					pToRoamProfile = NULL;
-			}
-			if (saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.
-			    SSIDList) {
-				qdf_mem_free(saved_scan_cmd->u.scanCmd.u.
-					     scanRequest.SSIDs.SSIDList);
-				saved_scan_cmd->u.scanCmd.u.scanRequest.SSIDs.
-					SSIDList = NULL;
-			}
-			if (saved_scan_cmd->u.roamCmd.pRoamBssEntry) {
-				qdf_mem_free(saved_scan_cmd->u.roamCmd.
-					     pRoamBssEntry);
-				saved_scan_cmd->u.roamCmd.pRoamBssEntry = NULL;
-			}
+			csr_saved_scan_cmd_free_fields(mac_ctx,
+						       saved_scan_cmd);
 			qdf_mem_free(saved_scan_cmd);
 			saved_scan_cmd = NULL;
 			sme_err(FL("memory should have been free. Check!"));
@@ -2946,6 +2968,8 @@ error:
 			csr_scan_handle_search_for_ssid_failure(mac_ctx,
 								pCommand);
 			if (mac_ctx->sme.saved_scan_cmd) {
+				csr_saved_scan_cmd_free_fields(mac_ctx,
+						mac_ctx->sme.saved_scan_cmd);
 				qdf_mem_free(mac_ctx->sme.saved_scan_cmd);
 				mac_ctx->sme.saved_scan_cmd = NULL;
 			}
@@ -2954,6 +2978,8 @@ error:
 			sme_err("conn update ret %d", ret);
 			csr_scan_handle_search_for_ssid(mac_ctx, pCommand);
 			if (mac_ctx->sme.saved_scan_cmd) {
+				csr_saved_scan_cmd_free_fields(mac_ctx,
+						mac_ctx->sme.saved_scan_cmd);
 				qdf_mem_free(mac_ctx->sme.saved_scan_cmd);
 				mac_ctx->sme.saved_scan_cmd = NULL;
 			}

+ 4 - 0
core/sme/src/csr/csr_inside_api.h

@@ -1042,11 +1042,15 @@ QDF_STATUS csr_scan_handle_search_for_ssid(tpAniSirGlobal mac,
 		tSmeCmd *command);
 QDF_STATUS csr_scan_handle_search_for_ssid_failure(tpAniSirGlobal mac,
 		tSmeCmd *command);
+void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx,
+				    tSmeCmd *saved_scan_cmd);
 #else
 QDF_STATUS csr_scan_handle_search_for_ssid(tpAniSirGlobal mac_ctx,
 					   uint32_t session_id);
 QDF_STATUS csr_scan_handle_search_for_ssid_failure(tpAniSirGlobal mac,
 		uint32_t session_id);
+void csr_saved_scan_cmd_free_fields(tpAniSirGlobal mac_ctx,
+				    tCsrRoamSession *session);
 #endif
 tpSirBssDescription csr_get_fst_bssdescr_ptr(tScanResultHandle result_handle);