diff options
| author | Nitesh Shah <niteshs@codeaurora.org> | 2017-01-30 18:34:59 +0530 |
|---|---|---|
| committer | qcabuildsw <qcabuildsw@localhost> | 2017-03-03 16:34:47 -0800 |
| commit | f474fc4de458f997d00a6993d077424cefb4a88d (patch) | |
| tree | 4f98078eba5eaf7bb6e0e56b72676055c848ed36 | |
| parent | 8ffb2adac7bf109982933c4f7e1624b3211b6925 (diff) | |
qcacld-3.0: Acquire mutex before accessing tdls context
qcacld-2.0 to qcacld-3.0 propagation
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_get_peer(),
wlan_hdd_tdls_set_cap(), wlan_hdd_tdls_recv_discovery_resp(),
wlan_hdd_tdls_set_peer_caps(), wlan_hdd_tdls_get_link_estab
lish_params(), wlan_hdd_tdls_set_responder() and
wlan_hdd_tdls_set_signature.
Change-Id: I4589eea7f5f97d0e9887e008921a89af05bce329
CRs-Fixed: 1108972
| -rw-r--r-- | core/hdd/src/wlan_hdd_tdls.c | 143 |
1 files changed, 107 insertions, 36 deletions
diff --git a/core/hdd/src/wlan_hdd_tdls.c b/core/hdd/src/wlan_hdd_tdls.c index fc374fc213b5..6b16de9afb75 100644 --- a/core/hdd/src/wlan_hdd_tdls.c +++ b/core/hdd/src/wlan_hdd_tdls.c @@ -982,22 +982,26 @@ 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, need_mutex_lock); + peer = wlan_hdd_tdls_find_peer(pAdapter, mac, false); if (peer != NULL) { + if (need_mutex_lock) + mutex_unlock(&pHddCtx->tdls_lock); 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; } - if (need_mutex_lock) - mutex_lock(&pHddCtx->tdls_lock); - pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter); if (NULL == pHddTdlsCtx) { @@ -1038,16 +1042,28 @@ int wlan_hdd_tdls_set_cap(hdd_adapter_t *pAdapter, const uint8_t *mac, tTDLSCapType cap) { hddTdlsPeer_t *curr_peer; + hdd_context_t *hdd_ctx; + int status = 0; - curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, true); + hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); + if (0 != (wlan_hdd_validate_context(hdd_ctx))) { + status = -EINVAL; + goto ret_status; + } + + mutex_lock(&hdd_ctx->tdls_lock); + curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false); if (curr_peer == NULL) { hdd_err("curr_peer is NULL"); - return -EINVAL; + status = -EINVAL; + goto rel_lock; } curr_peer->tdls_support = cap; - - return 0; +rel_lock: + mutex_unlock(&hdd_ctx->tdls_lock); +ret_status: + return status; } /** @@ -1185,34 +1201,40 @@ int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, const uint8_t *mac) { hddTdlsPeer_t *curr_peer; - tdlsCtx_t *pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter); + tdlsCtx_t *pHddTdlsCtx; hdd_context_t *pHddCtx; - + int status = 0; ENTER(); - if (NULL == pHddTdlsCtx) { - hdd_err("pHddTdlsCtx is NULL"); - return -EINVAL; + + pHddCtx = WLAN_HDD_GET_CTX(pAdapter); + + if (0 != (wlan_hdd_validate_context(pHddCtx))) { + status = -EINVAL; + goto ret_status; } - pHddCtx = WLAN_HDD_GET_CTX(pHddTdlsCtx->pAdapter); + mutex_lock(&pHddCtx->tdls_lock); - if (0 != (wlan_hdd_validate_context(pHddCtx))) - return -EINVAL; + pHddTdlsCtx = WLAN_HDD_GET_TDLS_CTX_PTR(pAdapter); + if (NULL == pHddTdlsCtx) { + hdd_err("pHddTdlsCtx is NULL"); + status = -EINVAL; + goto rel_lock; + } - curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, true); + curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false); if (NULL == curr_peer) { hdd_err("curr_peer is NULL"); - return -EINVAL; + status = -EINVAL; + goto rel_lock; } if (pHddTdlsCtx->discovery_sent_cnt) pHddTdlsCtx->discovery_sent_cnt--; - mutex_lock(&pHddCtx->tdls_lock); wlan_hdd_tdls_check_power_save_prohibited(pAdapter); - mutex_unlock(&pHddCtx->tdls_lock); if (0 == pHddTdlsCtx->discovery_sent_cnt) { qdf_mc_timer_stop(&pHddTdlsCtx->peerDiscoveryTimeoutTimer); } @@ -1230,7 +1252,7 @@ int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, wlan_hdd_tdls_set_peer_link_status(curr_peer, eTDLS_LINK_DISCOVERED, eTDLS_LINK_SUCCESS, - true); + false); hdd_notice("Rssi Threshold met: " MAC_ADDRESS_STR " rssi = %d threshold= %d", MAC_ADDR_ARRAY(curr_peer->peerMac), @@ -1251,7 +1273,7 @@ int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, wlan_hdd_tdls_set_peer_link_status(curr_peer, eTDLS_LINK_IDLE, eTDLS_LINK_UNSPECIFIED, - true); + false); /* if RSSI threshold is not met then allow further discovery * attempts by decrementing count for the last attempt @@ -1262,8 +1284,11 @@ int wlan_hdd_tdls_recv_discovery_resp(hdd_adapter_t *pAdapter, } curr_peer->tdls_support = eTDLS_CAP_SUPPORTED; +rel_lock: + mutex_unlock(&pHddCtx->tdls_lock); +ret_status: EXIT(); - return 0; + return status; } /** @@ -1284,11 +1309,20 @@ int wlan_hdd_tdls_set_peer_caps(hdd_adapter_t *pAdapter, bool is_qos_wmm_sta) { hddTdlsPeer_t *curr_peer; + hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); + int status = 0; - curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, true); + if (0 != (wlan_hdd_validate_context(hdd_ctx))) { + status = -EINVAL; + goto ret_status; + } + + mutex_lock(&hdd_ctx->tdls_lock); + curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false); if (curr_peer == NULL) { hdd_err("curr_peer is NULL"); - return -EINVAL; + status = -EINVAL; + goto rel_lock; } curr_peer->uapsdQueues = StaParams->uapsd_queues; @@ -1309,7 +1343,10 @@ int wlan_hdd_tdls_set_peer_caps(hdd_adapter_t *pAdapter, curr_peer->supported_oper_classes_len = StaParams->supported_oper_classes_len; curr_peer->qos = is_qos_wmm_sta; - return 0; +rel_lock: + mutex_unlock(&hdd_ctx->tdls_lock); +ret_status: + return status; } /** @@ -1327,11 +1364,20 @@ int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter, tdlsLinkEstablishParams) { hddTdlsPeer_t *curr_peer; + hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); + int status = 0; - curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, true); + if (0 != (wlan_hdd_validate_context(hdd_ctx))) { + status = -EINVAL; + goto ret_status; + } + + mutex_lock(&hdd_ctx->tdls_lock); + curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false); if (curr_peer == NULL) { hdd_err("curr_peer is NULL"); - return -EINVAL; + status = -EINVAL; + goto rel_lock; } tdlsLinkEstablishParams->isResponder = curr_peer->is_responder; @@ -1355,7 +1401,10 @@ int wlan_hdd_tdls_get_link_establish_params(hdd_adapter_t *pAdapter, tdlsLinkEstablishParams->supportedOperClassesLen = curr_peer->supported_oper_classes_len; tdlsLinkEstablishParams->qos = curr_peer->qos; - return 0; +rel_lock: + mutex_unlock(&hdd_ctx->tdls_lock); +ret_status: + return status; } /** @@ -1403,16 +1452,27 @@ int wlan_hdd_tdls_set_responder(hdd_adapter_t *pAdapter, const uint8_t *mac, uint8_t responder) { hddTdlsPeer_t *curr_peer; + hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); + int status = 0; - curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, true); + if (0 != (wlan_hdd_validate_context(hdd_ctx))) { + status = -EINVAL; + goto ret_status; + } + mutex_lock(&hdd_ctx->tdls_lock); + curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false); if (curr_peer == NULL) { hdd_err("curr_peer is NULL"); - return -EINVAL; + status = -EINVAL; + goto rel_lock; } curr_peer->is_responder = responder; - return 0; +rel_lock: + mutex_unlock(&hdd_ctx->tdls_lock); +ret_status: + return status; } /** @@ -1427,16 +1487,27 @@ int wlan_hdd_tdls_set_signature(hdd_adapter_t *pAdapter, const uint8_t *mac, uint8_t uSignature) { hddTdlsPeer_t *curr_peer; + hdd_context_t *hdd_ctx = WLAN_HDD_GET_CTX(pAdapter); + int status = 0; - curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, true); + if (0 != (wlan_hdd_validate_context(hdd_ctx))) { + status = -EINVAL; + goto ret_status; + } + + mutex_lock(&hdd_ctx->tdls_lock); + curr_peer = wlan_hdd_tdls_get_peer(pAdapter, mac, false); if (curr_peer == NULL) { hdd_err("curr_peer is NULL"); - return -EINVAL; + status = -EINVAL; + goto rel_lock; } curr_peer->signature = uSignature; - - return 0; +rel_lock: + mutex_unlock(&hdd_ctx->tdls_lock); +ret_status: + return status; } /** |
