Browse Source

qcacld-3.0: Acquire mutex before accessing tdls function

peer_list is a parameter for tdls_ctx, so every access to
peer_list should be protected with mutex lock.

This change refactors the code for function
wlan_hdd_tdls_disable_offchan_and_teardown_links(),
wlan_hdd_tdls_scan_callback() and wlan_hdd_tdls_teardown
_links() before calling wlan_hdd_tdls_find_all_peer().

Change-Id: I881e12bb0c50bfbeb4fe60cb21cfdf0f7d6c2f56
CRs-Fixed: 1106293
Nitesh Shah 8 years ago
parent
commit
542fdee90e
1 changed files with 13 additions and 9 deletions
  1. 13 9
      core/hdd/src/wlan_hdd_tdls.c

+ 13 - 9
core/hdd/src/wlan_hdd_tdls.c

@@ -259,6 +259,7 @@ void wlan_hdd_tdls_disable_offchan_and_teardown_links(hdd_context_t *hddctx)
 		if (!hddctx->tdlsConnInfo[staidx].staId)
 			continue;
 
+		mutex_lock(&hddctx->tdls_lock);
 		curr_peer = wlan_hdd_tdls_find_all_peer(hddctx,
 				hddctx->tdlsConnInfo[staidx].peerMac.bytes);
 
@@ -272,9 +273,10 @@ void wlan_hdd_tdls_disable_offchan_and_teardown_links(hdd_context_t *hddctx)
 					curr_peer->pHddTdlsCtx->pAdapter,
 					curr_peer,
 					eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON,
-					true);
+					false);
 		hdd_send_wlan_tdls_teardown_event(eTDLS_TEARDOWN_CONCURRENCY,
 			curr_peer->peerMac);
+		mutex_unlock(&hddctx->tdls_lock);
 	}
 }
 
@@ -2343,8 +2345,6 @@ hddTdlsPeer_t *wlan_hdd_tdls_find_all_peer(hdd_context_t *pHddCtx,
 	hddTdlsPeer_t *curr_peer = NULL;
 	QDF_STATUS status = 0;
 
-	mutex_lock(&pHddCtx->tdls_lock);
-
 	status = hdd_get_front_adapter(pHddCtx, &pAdapterNode);
 	while (NULL != pAdapterNode && QDF_STATUS_SUCCESS == status) {
 		pAdapter = pAdapterNode->pAdapter;
@@ -2354,14 +2354,12 @@ hddTdlsPeer_t *wlan_hdd_tdls_find_all_peer(hdd_context_t *pHddCtx,
 			curr_peer =
 				wlan_hdd_tdls_find_peer(pAdapter, mac, false);
 			if (curr_peer) {
-				mutex_unlock(&pHddCtx->tdls_lock);
 				return curr_peer;
 			}
 		}
 		status = hdd_get_next_adapter(pHddCtx, pAdapterNode, &pNext);
 		pAdapterNode = pNext;
 	}
-	mutex_unlock(&pHddCtx->tdls_lock);
 	return curr_peer;
 }
 
@@ -2971,6 +2969,7 @@ int wlan_hdd_tdls_scan_callback(hdd_adapter_t *pAdapter, struct wiphy *wiphy,
 			for (staIdx = 0; staIdx < pHddCtx->max_num_tdls_sta;
 			     staIdx++) {
 				if (pHddCtx->tdlsConnInfo[staIdx].staId) {
+					mutex_lock(&pHddCtx->tdls_lock);
 					curr_peer =
 						wlan_hdd_tdls_find_all_peer(pHddCtx,
 									    pHddCtx->
@@ -2984,6 +2983,7 @@ int wlan_hdd_tdls_scan_callback(hdd_adapter_t *pAdapter, struct wiphy *wiphy,
 						if (!(curr_peer->isBufSta))
 							allPeersBufStas = 0;
 					}
+					mutex_unlock(&pHddCtx->tdls_lock);
 				}
 			}
 
@@ -6151,15 +6151,20 @@ static int wlan_hdd_tdls_teardown_links(hdd_context_t *hddctx,
 		if (!hddctx->tdlsConnInfo[staidx].staId)
 			continue;
 
+		mutex_lock(&hddctx->tdls_lock);
 		curr_peer = wlan_hdd_tdls_find_all_peer(hddctx,
 			hddctx->tdlsConnInfo[staidx].peerMac.bytes);
 
-		if (!curr_peer)
+		if (!curr_peer) {
+			mutex_unlock(&hddctx->tdls_lock);
 			continue;
+		}
 
 		/* Check if connected peer supports more than one stream */
-		if (curr_peer->spatial_streams == TDLS_NSS_1x1_MODE)
+		if (curr_peer->spatial_streams == TDLS_NSS_1x1_MODE) {
+			mutex_unlock(&hddctx->tdls_lock);
 			continue;
+		}
 
 		hdd_info("Indicate TDLS teardown (staId %d)",
 			 curr_peer->staId);
@@ -6168,8 +6173,7 @@ static int wlan_hdd_tdls_teardown_links(hdd_context_t *hddctx,
 					curr_peer->pHddTdlsCtx->pAdapter,
 					curr_peer,
 					eSIR_MAC_TDLS_TEARDOWN_UNSPEC_REASON,
-					true);
-		mutex_lock(&hddctx->tdls_lock);
+					false);
 		hddctx->tdls_teardown_peers_cnt++;
 		mutex_unlock(&hddctx->tdls_lock);
 	}