Skip to content

Commit 34574f8

Browse files
Nitesh Shahqcabuildsw
authored andcommitted
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 wlan_hdd_tdls_add_station() and wlan_hdd_tdls_set_link_status(). Change-Id: Ibb323d6dccfb91fddf8bde849054cfc331081ff8 CRs-Fixed: 1115781
1 parent 191d3c7 commit 34574f8

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

core/hdd/src/wlan_hdd_tdls.c

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,14 +1158,13 @@ void wlan_hdd_tdls_set_link_status(hdd_adapter_t *pAdapter,
11581158
if (wlan_hdd_validate_context(pHddCtx))
11591159
return;
11601160

1161-
curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, true);
1161+
curr_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, false);
11621162
if (curr_peer == NULL) {
11631163
QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
11641164
FL("curr_peer is NULL"));
11651165
return;
11661166
}
11671167

1168-
mutex_lock(&pHddCtx->tdls_lock);
11691168
curr_peer->link_status = linkStatus;
11701169

11711170
/* If TDLS link status is already passed the discovery state
@@ -1174,7 +1173,7 @@ void wlan_hdd_tdls_set_link_status(hdd_adapter_t *pAdapter,
11741173
if (linkStatus >= eTDLS_LINK_DISCOVERED) {
11751174
curr_peer->discovery_attempt = 0;
11761175
}
1177-
mutex_unlock(&pHddCtx->tdls_lock);
1176+
11781177
if (curr_peer->isForcedPeer && curr_peer->state_change_notification) {
11791178
uint32_t opclass;
11801179
uint32_t channel;
@@ -3856,6 +3855,7 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
38563855
hdd_context_t *pHddCtx = wiphy_priv(wiphy);
38573856
QDF_STATUS status;
38583857
hddTdlsPeer_t *pTdlsPeer;
3858+
tTDLSLinkStatus link_status;
38593859
uint16_t numCurrTdlsPeers;
38603860
unsigned long rc;
38613861
int ret;
@@ -3874,22 +3874,27 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
38743874
return -ENOTSUPP;
38753875
}
38763876

3877-
pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, mac, true);
3877+
mutex_lock(&pHddCtx->tdls_lock);
3878+
pTdlsPeer = wlan_hdd_tdls_get_peer(pAdapter, mac, false);
38783879

38793880
if (NULL == pTdlsPeer) {
3881+
mutex_unlock(&pHddCtx->tdls_lock);
38803882
hdd_err(MAC_ADDRESS_STR " update %d not exist. return invalid",
38813883
MAC_ADDR_ARRAY(mac), update);
3882-
return -EINVAL;
3884+
ret = -EINVAL;
3885+
goto rel_lock;
38833886
}
38843887

3888+
link_status = pTdlsPeer->link_status;
38853889
/* in add station, we accept existing valid staId if there is */
38863890
if ((0 == update) &&
38873891
((pTdlsPeer->link_status >= eTDLS_LINK_CONNECTING) ||
38883892
(TDLS_STA_INDEX_VALID(pTdlsPeer->staId)))) {
38893893
hdd_notice(MAC_ADDRESS_STR " link_status %d. staId %d. add station ignored.",
38903894
MAC_ADDR_ARRAY(mac), pTdlsPeer->link_status,
38913895
pTdlsPeer->staId);
3892-
return 0;
3896+
ret = 0;
3897+
goto rel_lock;
38933898
}
38943899
/* in change station, we accept only when staId is valid */
38953900
if ((1 == update) &&
@@ -3900,13 +3905,16 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
39003905
pTdlsPeer->staId,
39013906
(TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? "ignored" :
39023907
"declined");
3903-
return (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
3908+
ret = (TDLS_STA_INDEX_VALID(pTdlsPeer->staId)) ? 0 : -EPERM;
3909+
goto rel_lock;
39043910
}
39053911

39063912
/* when others are on-going, we want to change link_status to idle */
3907-
if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, true, true)) {
3913+
if (NULL != wlan_hdd_tdls_is_progress(pHddCtx, mac, true, false)) {
3914+
mutex_unlock(&pHddCtx->tdls_lock);
39083915
hdd_notice(MAC_ADDRESS_STR " TDLS setup is ongoing. Request declined.",
39093916
MAC_ADDR_ARRAY(mac));
3917+
ret = -EPERM;
39103918
goto error;
39113919
}
39123920

@@ -3922,16 +3930,25 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
39223930
" Num of peers (%d), Max allowed (%d).",
39233931
__func__, MAC_ADDR_ARRAY(mac), numCurrTdlsPeers,
39243932
pHddCtx->max_num_tdls_sta);
3933+
mutex_unlock(&pHddCtx->tdls_lock);
3934+
ret = -EPERM;
39253935
goto error;
39263936
} else {
39273937
hddTdlsPeer_t *pTdlsPeer;
3928-
pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, true);
3929-
if (pTdlsPeer && TDLS_IS_CONNECTED(pTdlsPeer)) {
3930-
QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
3931-
"%s: " MAC_ADDRESS_STR
3932-
" already connected. Request declined.",
3933-
__func__, MAC_ADDR_ARRAY(mac));
3934-
return -EPERM;
3938+
pTdlsPeer = wlan_hdd_tdls_find_peer(pAdapter, mac, false);
3939+
if (pTdlsPeer) {
3940+
link_status = pTdlsPeer->link_status;
3941+
if (TDLS_IS_CONNECTED(pTdlsPeer)) {
3942+
mutex_unlock(&pHddCtx->tdls_lock);
3943+
QDF_TRACE(QDF_MODULE_ID_HDD,
3944+
QDF_TRACE_LEVEL_ERROR,
3945+
"%s: " MAC_ADDRESS_STR
3946+
" already connected. "
3947+
"Request declined.",
3948+
__func__, MAC_ADDR_ARRAY(mac));
3949+
ret = -EPERM;
3950+
goto ret_status;
3951+
}
39353952
}
39363953
}
39373954
if (0 == update)
@@ -3968,8 +3985,10 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
39683985
StaParams->supported_rates[rate_idx]);
39693986
} /* end debug code */
39703987
else if ((1 == update) && (NULL == StaParams)) {
3988+
mutex_unlock(&pHddCtx->tdls_lock);
39713989
hdd_err("update is true, but staParams is NULL. Error!");
3972-
return -EPERM;
3990+
ret = -EPERM;
3991+
goto ret_status;
39733992
}
39743993

39753994
INIT_COMPLETION(pAdapter->tdls_add_station_comp);
@@ -3978,11 +3997,12 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
39783997
if ((NULL != StaParams) && (StaParams->htcap_present)) {
39793998
hddTdlsPeer_t *tdls_peer;
39803999

3981-
tdls_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, true);
4000+
tdls_peer = wlan_hdd_tdls_find_peer(pAdapter, mac, false);
39824001
if (NULL != tdls_peer)
39834002
tdls_peer->spatial_streams =
39844003
StaParams->HTCap.suppMcsSet[1];
39854004
}
4005+
mutex_unlock(&pHddCtx->tdls_lock);
39864006

39874007
if (!update) {
39884008
status = sme_add_tdls_peer_sta(WLAN_HDD_GET_HAL_CTX(pAdapter),
@@ -3999,24 +4019,29 @@ int wlan_hdd_tdls_add_station(struct wiphy *wiphy,
39994019

40004020
if (!rc) {
40014021
hdd_err("timeout waiting for tdls add station indication %ld peer link status %u",
4002-
rc, pTdlsPeer->link_status);
4022+
rc, link_status);
4023+
ret = -EPERM;
40034024
goto error;
40044025
}
40054026

40064027
if (QDF_STATUS_SUCCESS != pAdapter->tdlsAddStaStatus) {
40074028
QDF_TRACE(QDF_MODULE_ID_HDD, QDF_TRACE_LEVEL_ERROR,
40084029
"%s: Add Station is unsuccessful", __func__);
4030+
ret = -EPERM;
40094031
goto error;
40104032
}
40114033

4012-
return 0;
4034+
goto ret_status;
40134035

40144036
error:
40154037
wlan_hdd_tdls_set_link_status(pAdapter,
40164038
mac,
40174039
eTDLS_LINK_IDLE, eTDLS_LINK_UNSPECIFIED);
4018-
return -EPERM;
4019-
4040+
goto ret_status;
4041+
rel_lock:
4042+
mutex_unlock(&pHddCtx->tdls_lock);
4043+
ret_status:
4044+
return ret;
40204045
}
40214046

40224047
#if TDLS_MGMT_VERSION2

0 commit comments

Comments
 (0)