TDLS: Check for the connected state while extracing the first peer.

commit I6dad95ce4f453d774b4f6bea99cccca46b95aa5f did not consider peer link
connection status while extracting first peer from the peer list.

Address this issue by checking if peer link status is connected.

Klockwork Issue: pAdapter NULL Pointer Dereference in
wlan_hdd_tdls_indicate_teardown function is also fixed as part of this
commit.

CRs-Fixed: 685956
Change-Id: I5ef55f91dd20c0bb934e9dad90fe901a63480853
diff --git a/CORE/HDD/src/wlan_hdd_tdls.c b/CORE/HDD/src/wlan_hdd_tdls.c
index 75e0ddd..2b40444 100644
--- a/CORE/HDD/src/wlan_hdd_tdls.c
+++ b/CORE/HDD/src/wlan_hdd_tdls.c
@@ -1638,9 +1638,12 @@
 
         list_for_each(pos, head) {
             curr_peer= list_entry (pos, hddTdlsPeer_t, node);
-            if (curr_peer)
+            if (curr_peer && (curr_peer->link_status == eTDLS_LINK_CONNECTED))
             {
                mutex_unlock(&pHddCtx->tdls_lock);
+               VOS_TRACE( VOS_MODULE_ID_HDD, TDLS_LOG_LEVEL,
+                          "%s: " MAC_ADDRESS_STR " eTDLS_LINK_CONNECTED",
+                           __func__, MAC_ADDR_ARRAY(curr_peer->peerMac));
                return curr_peer;
             }
         }
@@ -2490,7 +2493,7 @@
                                            hddTdlsPeer_t *curr_peer,
                                            tANI_U16 reason)
 {
-    hdd_context_t *pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
+    hdd_context_t *pHddCtx;
 
     if (NULL == pAdapter || NULL == curr_peer)
     {
@@ -2499,6 +2502,8 @@
         return;
     }
 
+    pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
+
     if (eTDLS_LINK_CONNECTED != curr_peer->link_status)
         return;
 
@@ -2508,7 +2513,7 @@
      * to be operational, explicitly make it false to enable
      * throughput monitor takes the control of split scan.
      */
-    if (pHddCtx->isTdlsScanCoexistence == TRUE)
+    if (pHddCtx && (pHddCtx->isTdlsScanCoexistence == TRUE))
     {
         pHddCtx->isTdlsScanCoexistence = FALSE;
     }