Kaynağa Gözat

qcacld-3.0: Acquire mutex before accessing tdls context

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 the function wlan_hdd_
tdls_get_peer() by removing the need for mutex lock inside
the function. The change also refactors the calling functions
for wlan_hdd_tdls_get_peer().

Change-Id: I3acb278162127e84d751ef7fdeaac2dc245bbe81
CRs-Fixed: 1106682
Nitesh Shah 8 yıl önce
ebeveyn
işleme
379449e295

+ 1 - 2
core/hdd/inc/wlan_hdd_tdls.h

@@ -538,8 +538,7 @@ int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter,
 					    tCsrTdlsLinkEstablishParams *
 					    tdlsLinkEstablishParams);
 hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter,
-				      const uint8_t *mac,
-				      bool need_mutex_lock);
+				      const uint8_t *mac);
 
 int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter, const uint8_t *mac,
 			  tTDLSCapType cap);

+ 1 - 2
core/hdd/src/wlan_hdd_assoc.c

@@ -3971,8 +3971,7 @@ hdd_roam_tdls_status_update_handler(hdd_adapter_t *pAdapter,
 
 		curr_peer =
 			wlan_hdd_tdls_get_peer(pAdapter,
-					       pRoamInfo->peerMac.bytes,
-					       false);
+					       pRoamInfo->peerMac.bytes);
 		if (!curr_peer) {
 			hdd_info("curr_peer is null");
 			status = QDF_STATUS_E_FAILURE;

+ 27 - 34
core/hdd/src/wlan_hdd_tdls.c

@@ -972,15 +972,13 @@ static void wlan_hdd_tdls_timers_destroy(tdlsCtx_t *pHddTdlsCtx)
  * wlan_hdd_tdls_get_peer() - find or add an peer given mac address
  * @pAdapter: HDD adapter
  * @mac: MAC address used to find or create peer
- * @need_mutex_lock: flag identify whether mutex needed or not
  *
  * Search peer given an MAC address and create one if not found.
  *
  * Return: Pointer to peer if mac address exist or peer creation
  *         succeeds; NULL if peer creation fails
  */
-hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, const u8 *mac,
-				      bool need_mutex_lock)
+hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, const u8 *mac)
 {
 	struct list_head *head;
 	hddTdlsPeer_t *peer;
@@ -991,22 +989,14 @@ hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, const u8 *mac,
 	if (0 != (wlan_hdd_validate_context(pHddCtx)))
 		return NULL;
 
-	if (need_mutex_lock)
-		mutex_lock(&pHddCtx->tdls_lock);
-
 	/* if already there, just update */
 	peer = wlan_hdd_tdls_find_peer(pAdapter, mac, false);
-	if (peer != NULL) {
-		if (need_mutex_lock)
-			mutex_unlock(&pHddCtx->tdls_lock);
+	if (peer != NULL)
 		return peer;
-	}
 
 	/* not found, allocate and add the list */
 	peer = qdf_mem_malloc(sizeof(hddTdlsPeer_t));
 	if (NULL == peer) {
-		if (need_mutex_lock)
-			mutex_unlock(&pHddCtx->tdls_lock);
 		hdd_err("peer malloc failed!");
 		return NULL;
 	}
@@ -1015,8 +1005,6 @@ hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, const u8 *mac,
 
 	if (NULL == pHddTdlsCtx) {
 		qdf_mem_free(peer);
-		if (need_mutex_lock)
-			mutex_unlock(&pHddCtx->tdls_lock);
 		hdd_notice("pHddTdlsCtx is NULL");
 		return NULL;
 	}
@@ -1033,9 +1021,6 @@ hddTdlsPeer_t *wlan_hdd_tdls_get_peer(hdd_adapter_t *pAdapter, const u8 *mac,
 
 	list_add_tail(&peer->node, head);
 
-	if (need_mutex_lock)
-		mutex_unlock(&pHddCtx->tdls_lock);
-
 	return peer;
 }
 
@@ -1061,7 +1046,7 @@ int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter, const uint8_t *mac,
 	}
 
 	mutex_lock(&hdd_ctx->tdls_lock);
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (curr_peer == NULL) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -1231,7 +1216,7 @@ int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter,
 		goto rel_lock;
 	}
 
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (NULL == curr_peer) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -1328,7 +1313,7 @@ int wlan_hdd_tdls_set_peer_caps(hdd_adapter_t *pAdapter,
 	}
 
 	mutex_lock(&hdd_ctx->tdls_lock);
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (curr_peer == NULL) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -1383,7 +1368,7 @@ int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter,
 	}
 
 	mutex_lock(&hdd_ctx->tdls_lock);
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (curr_peer == NULL) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -1470,7 +1455,7 @@ int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter, const uint8_t *mac,
 		goto ret_status;
 	}
 	mutex_lock(&hdd_ctx->tdls_lock);
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (curr_peer == NULL) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -1506,7 +1491,7 @@ int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter, const uint8_t *mac,
 	}
 
 	mutex_lock(&hdd_ctx->tdls_lock);
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (curr_peer == NULL) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -2166,7 +2151,7 @@ int wlan_hdd_tdls_set_sta_id(hdd_adapter_t *pAdapter, const uint8_t *mac,
 	}
 
 	mutex_lock(&hdd_ctx->tdls_lock);
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (curr_peer == NULL) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -2383,7 +2368,7 @@ int wlan_hdd_tdls_reset_peer(hdd_adapter_t *pAdapter, const uint8_t *mac)
 	}
 
 	mutex_lock(&pHddCtx->tdls_lock);
-	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 	if (curr_peer == NULL) {
 		hdd_err("curr_peer is NULL");
 		status = -EINVAL;
@@ -2545,13 +2530,23 @@ int wlan_hdd_tdls_get_all_peers(hdd_adapter_t *pAdapter, char *buf, int buflen)
  */
 void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter)
 {
-	tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
+	tdlsCtx_t *pHddTdlsCtx;
 	hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
 	uint32_t tx_period_t;
 
-	if ((NULL == pHddCtx) || (NULL == pHddTdlsCtx)) {
+	if (NULL == pHddCtx) {
 		QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
-			  FL("pHddCtx or pHddTdlsCtx points to NULL"));
+			  FL("pHddCtx points to NULL"));
+		return;
+	}
+
+	mutex_lock(&pHddCtx->tdls_lock);
+
+	pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter);
+	if (NULL == pHddTdlsCtx) {
+		mutex_unlock(&pHddCtx->tdls_lock);
+		QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
+			  FL("pHddTdlsCtx points to NULL"));
 		return;
 	}
 
@@ -2559,8 +2554,6 @@ void wlan_hdd_tdls_connection_callback(hdd_adapter_t *pAdapter)
 
 	hdd_notice("update %d", pHddTdlsCtx->threshold_config.tx_period_t);
 
-	mutex_lock(&pHddCtx->tdls_lock);
-
 	if (eTDLS_SUPPORT_ENABLED == pHddCtx->tdls_mode ||
 	    eTDLS_SUPPORT_EXTERNAL_CONTROL == pHddCtx->tdls_mode) {
 		wlan_hdd_tdls_peer_reset_discovery_processed(pHddTdlsCtx);
@@ -3882,7 +3875,7 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
 	}
 
 	mutex_lock(&pHddCtx->tdls_lock);
-	pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
+	pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, mac);
 
 	if (NULL == pTdlsPeer) {
 		mutex_unlock(&pHddCtx->tdls_lock);
@@ -4558,7 +4551,7 @@ int wlan_hdd_tdls_extctrl_config_peer(hdd_adapter_t *pAdapter,
 	}
 
 	mutex_lock(&pHddCtx->tdls_lock);
-	pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer, false);
+	pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
 	if (pTdlsPeer == NULL) {
 		QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
 			  "%s: peer " MAC_ADDRESS_STR " does not exist",
@@ -4605,7 +4598,7 @@ int wlan_hdd_tdls_extctrl_config_peer(hdd_adapter_t *pAdapter,
 	}
 
 	mutex_lock(&pHddCtx->tdls_lock);
-	pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer, false);
+	pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, peer);
 	if (pTdlsPeer == NULL) {
 		QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
 			  "%s: peer " MAC_ADDRESS_STR " does not exist",
@@ -5480,7 +5473,7 @@ static void wlan_hdd_tdls_ct_sampling_tx_rx(hdd_adapter_t *adapter,
 	for (mac_cnt = 0; mac_cnt < valid_mac_entries; mac_cnt++) {
 		memcpy(mac, ct_peer_mac_table[mac_cnt].mac_address.bytes,
 		       QDF_MAC_ADDR_SIZE);
-		curr_peer = wlan_hdd_tdls_get_peer(adapter, mac, false);
+		curr_peer = wlan_hdd_tdls_get_peer(adapter, mac);
 		if (NULL != curr_peer) {
 			curr_peer->tx_pkt =
 			ct_peer_mac_table[mac_cnt].tx_packet_cnt;