Fix more bugs found during static code analysis

Fix miscellaneous bugs found by static source code analysis

Change-Id: Ia84018c213d4731d51044f84c74407a5aac51326
diff --git a/CORE/HDD/src/wlan_hdd_cfg80211.c b/CORE/HDD/src/wlan_hdd_cfg80211.c
index 338c816..765620e 100644
--- a/CORE/HDD/src/wlan_hdd_cfg80211.c
+++ b/CORE/HDD/src/wlan_hdd_cfg80211.c
@@ -3951,6 +3951,7 @@
     if(chan == NULL)
     {
        hddLog(VOS_TRACE_LEVEL_INFO, "%s chan pointer is NULL", __func__);
+       kfree(mgmt);
        return NULL;
     }
     /*To keep the rssi icon of the connected AP in the scan window
@@ -7106,10 +7107,10 @@
         "NL80211_TDLS_UNKONW_OPER"};
 #endif
 
-    if( NULL == pHddCtx || NULL == pHddCtx->cfg_ini )
+    if ( NULL == pHddCtx || NULL == pHddCtx->cfg_ini || NULL == peer )
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                "Invalid arguments");
+                   "%s: Invalid arguments", __func__);
         return -EINVAL;
     }
 
@@ -7134,8 +7135,8 @@
         FALSE == sme_IsFeatureSupportedByFW(TDLS))
     {
         VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_ERROR,
-                "TDLS Disabled in INI OR not enabled in FW.\
-                Cannot process TDLS commands \n");
+                "TDLS Disabled in INI OR not enabled in FW. "
+                "Cannot process TDLS commands");
         return -ENOTSUPP;
     }
 
diff --git a/CORE/HDD/src/wlan_hdd_early_suspend.c b/CORE/HDD/src/wlan_hdd_early_suspend.c
index 30fb48d..7984a35 100644
--- a/CORE/HDD/src/wlan_hdd_early_suspend.c
+++ b/CORE/HDD/src/wlan_hdd_early_suspend.c
@@ -640,6 +640,8 @@
 
     wlanRxpFilterParam->setMcstBcstFilter = setfilter;
     halStatus = sme_ConfigureRxpFilter(pHddCtx->hHal, wlanRxpFilterParam);
+    if (eHAL_STATUS_SUCCESS != halStatus)
+        vos_mem_free(wlanRxpFilterParam);
     if(setfilter && (eHAL_STATUS_SUCCESS == halStatus))
        pHddCtx->hdd_mcastbcast_filter_set = TRUE;
 }
@@ -715,28 +717,32 @@
     if(eHAL_STATUS_SUCCESS == halStatus)
     {
         pHddCtx->hdd_mcastbcast_filter_set = TRUE;
+    } else {
+        vos_mem_free(wlanSuspendParam);
     }
 }
 
 static void hdd_conf_resume_ind(hdd_adapter_t *pAdapter)
 {
+    eHalStatus halStatus = eHAL_STATUS_FAILURE;
     VOS_STATUS vstatus;
     hdd_context_t* pHddCtx = WLAN_HDD_GET_CTX(pAdapter);
-    tpSirWlanResumeParam wlanResumeParam =
-      vos_mem_malloc(sizeof(tSirWlanResumeParam));
-
-    if(NULL == wlanResumeParam)
-    {
-        hddLog(VOS_TRACE_LEVEL_FATAL,
-           "%s: vos_mem_alloc failed ", __func__);
-        return;
-    }
+    tpSirWlanResumeParam wlanResumeParam;
 
     hddLog(VOS_TRACE_LEVEL_INFO,
       "%s: send wlan resume indication", __func__);
 
     if (pHddCtx->hdd_mcastbcast_filter_set == TRUE)
     {
+        wlanResumeParam = vos_mem_malloc(sizeof(tSirWlanResumeParam));
+
+        if(NULL == wlanResumeParam)
+        {
+            hddLog(VOS_TRACE_LEVEL_FATAL,
+               "%s: vos_mem_alloc failed ", __func__);
+            return;
+        }
+
         if (pHddCtx->cfg_ini->fhostArpOffload)
         {
             vstatus = hdd_conf_hostarpoffload(pAdapter, FALSE);
@@ -756,10 +762,13 @@
             wlanResumeParam->configuredMcstBcstFilterSetting =
                                         pHddCtx->cfg_ini->mcastBcastFilterSetting;
         }
-        sme_ConfigureResumeReq(pHddCtx->hHal, wlanResumeParam);
+        halStatus = sme_ConfigureResumeReq(pHddCtx->hHal, wlanResumeParam);
+        if (eHAL_STATUS_SUCCESS != halStatus)
+            vos_mem_free(wlanResumeParam);
         pHddCtx->hdd_mcastbcast_filter_set = FALSE;
     }
 
+
 #ifdef WLAN_FEATURE_PACKET_FILTERING    
     if (pHddCtx->cfg_ini->isMcAddrListFilter)
     {
diff --git a/CORE/HDD/src/wlan_hdd_hostapd.c b/CORE/HDD/src/wlan_hdd_hostapd.c
index f28680d..bfe4715 100644
--- a/CORE/HDD/src/wlan_hdd_hostapd.c
+++ b/CORE/HDD/src/wlan_hdd_hostapd.c
@@ -1456,6 +1456,12 @@
                          pConfig->RSNEncryptType, pConfig->mcRSNEncryptType);
     }
 
+    if (pConfig->RSNWPAReqIELength > QCSAP_MAX_OPT_IE) {
+        hddLog(LOGE, FL("RSNWPAReqIELength: %d too large"), pConfig->RSNWPAReqIELength);
+        kfree(pConfig);
+        return -EIO;
+    }
+
     pConfig->SSIDinfo.ssidHidden = pCommitConfig->SSIDinfo.ssidHidden; 
     pConfig->SSIDinfo.ssid.length = pCommitConfig->SSIDinfo.ssid.length;
     vos_mem_copy(pConfig->SSIDinfo.ssid.ssId, pCommitConfig->SSIDinfo.ssid.ssId, pConfig->SSIDinfo.ssid.length);
diff --git a/CORE/HDD/src/wlan_hdd_main.c b/CORE/HDD/src/wlan_hdd_main.c
index 0bdbcf3..49db421 100644
--- a/CORE/HDD/src/wlan_hdd_main.c
+++ b/CORE/HDD/src/wlan_hdd_main.c
@@ -1441,7 +1441,7 @@
     }
 
     /*getting the first argument ie the country code */
-    sscanf(inPtr, "%s ", pCountryCode);
+    sscanf(inPtr, "%3s ", pCountryCode);
 
     VOS_TRACE( VOS_MODULE_ID_HDD, VOS_TRACE_LEVEL_INFO_HIGH,
                "Country code is : %s", pCountryCode);
@@ -1529,7 +1529,7 @@
     }
 
     /*getting the first argument ie the number of channels*/
-    sscanf(inPtr, "%s ", buf);
+    sscanf(inPtr, "%32s ", buf);
     v = kstrtos32(buf, 10, &tempInt);
     if ((v < 0) || (tempInt <= 0)) return -EINVAL;
 
@@ -5440,10 +5440,10 @@
 {
    switch(mode)
    {
-       case WLAN_HDD_INFRA_STATION:
-       case WLAN_HDD_P2P_CLIENT:
-       case WLAN_HDD_P2P_GO:
-       case WLAN_HDD_SOFTAP:
+       case VOS_STA_MODE:
+       case VOS_P2P_CLIENT_MODE:
+       case VOS_P2P_GO_MODE:
+       case VOS_STA_SAP_MODE:
             pHddCtx->concurrency_mode |= (1 << mode);
             pHddCtx->no_of_sessions[mode]++;
             break;
@@ -5460,10 +5460,10 @@
 {
    switch(mode)
    {
-       case WLAN_HDD_INFRA_STATION:
-       case WLAN_HDD_P2P_CLIENT:
-       case WLAN_HDD_P2P_GO:
-       case WLAN_HDD_SOFTAP:
+       case VOS_STA_MODE:
+       case VOS_P2P_CLIENT_MODE:
+       case VOS_P2P_GO_MODE:
+       case VOS_STA_SAP_MODE:
     pHddCtx->no_of_sessions[mode]--;
     if (!(pHddCtx->no_of_sessions[mode]))
             pHddCtx->concurrency_mode &= (~(1 << mode));
diff --git a/CORE/HDD/src/wlan_hdd_wext.c b/CORE/HDD/src/wlan_hdd_wext.c
index 3278dcb..60b2c28 100644
--- a/CORE/HDD/src/wlan_hdd_wext.c
+++ b/CORE/HDD/src/wlan_hdd_wext.c
@@ -4957,13 +4957,13 @@
 
     switch ( pWapiKey->keyType )
     {
-        case HDD_PAIRWISE_WAPI_KEY:
+        case PAIRWISE_KEY:
         {
             isConnected = hdd_connIsConnected(pHddStaCtx);
             vos_mem_copy(setKey.peerMac,&pHddStaCtx->conn_info.bssId,WNI_CFG_BSSID_LEN);
             break;
         }
-        case HDD_GROUP_WAPI_KEY:
+        case GROUP_KEY:
         {
             vos_set_macaddr_broadcast( (v_MACADDR_t *)setKey.peerMac );
             break;
@@ -5125,6 +5125,7 @@
     tpSirRcvFltMcAddrList mc_addr_list_ptr;
     int idx;
     eHalStatus ret_val;
+    tANI_U8 mcastBcastFilterSetting;
 
     if (pHddCtx->isLogpInProgress)
     {
@@ -5227,17 +5228,20 @@
                    wlanRxpFilterParam->configuredMcstBcstFilterSetting,
                    wlanRxpFilterParam->setMcstBcstFilter);
 
+            mcastBcastFilterSetting = wlanRxpFilterParam->configuredMcstBcstFilterSetting;
+
             if (eHAL_STATUS_SUCCESS != sme_ConfigureRxpFilter(WLAN_HDD_GET_HAL_CTX(pAdapter),
                                                               wlanRxpFilterParam))
             {
                 hddLog(VOS_TRACE_LEVEL_ERROR,
                        "%s: Failure to execute set HW MC/BC Filter request",
                        __func__);
+                vos_mem_free(wlanRxpFilterParam);
                 return -EINVAL;
             }
 
             pHddCtx->dynamic_mcbc_filter.mcBcFilterSuspend =
-                wlanRxpFilterParam->configuredMcstBcstFilterSetting;
+                mcastBcastFilterSetting;
         }
     }