wlan: Fix for null pointer dereference.

Access the pAdapter after the value is assigned from the pAdapter node.

CRs-Fixed: 509299
Change-Id: Ic57dc44ac5bb1d57cb3a4981f6822d36e94a3e89
diff --git a/CORE/HDD/src/wlan_hdd_early_suspend.c b/CORE/HDD/src/wlan_hdd_early_suspend.c
index cf441dc..d875926 100644
--- a/CORE/HDD/src/wlan_hdd_early_suspend.c
+++ b/CORE/HDD/src/wlan_hdd_early_suspend.c
@@ -945,6 +945,7 @@
    VOS_STATUS status;
    hdd_adapter_t *pAdapter = NULL;
    hdd_adapter_list_node_t *pAdapterNode = NULL, *pNext = NULL;
+   bool hdd_enter_bmps = FALSE;
 
    hddLog(VOS_TRACE_LEVEL_INFO, "%s: WLAN being suspended by Android OS",__func__);
 
@@ -970,18 +971,6 @@
    }
 
    hdd_set_pwrparams(pHddCtx);
-
-   if (BMPS == pmcGetPmcState(pHddCtx->hHal))
-   {
-       /* put the device into full power */
-       wlan_hdd_enter_bmps(pAdapter, DRIVER_POWER_MODE_ACTIVE);
-
-       /* put the device back into BMPS */
-       wlan_hdd_enter_bmps(pAdapter, DRIVER_POWER_MODE_AUTO);
-
-       pHddCtx->hdd_ignore_dtim_enabled = TRUE;
-   }
-
    status =  hdd_get_front_adapter ( pHddCtx, &pAdapterNode );
    while ( NULL != pAdapterNode && VOS_STATUS_SUCCESS == status )
    {
@@ -995,7 +984,22 @@
            pAdapterNode = pNext;
            continue;
        }
+       /* Avoid multiple enter/exit BMPS in this while loop using
+        * hdd_enter_bmps flag
+        */
+       if (FALSE == hdd_enter_bmps && (BMPS == pmcGetPmcState(pHddCtx->hHal)))
+       {
+            hdd_enter_bmps = TRUE;
 
+           /* If device was already in BMPS, and dynamic DTIM is set,
+            * exit(set the device to full power) and enter BMPS again
+            * to reflect new DTIM value */
+           wlan_hdd_enter_bmps(pAdapter, DRIVER_POWER_MODE_ACTIVE);
+
+           wlan_hdd_enter_bmps(pAdapter, DRIVER_POWER_MODE_AUTO);
+
+           pHddCtx->hdd_ignore_dtim_enabled = TRUE;
+       }
 #ifdef SUPPORT_EARLY_SUSPEND_STANDBY_DEEPSLEEP
        if (pHddCtx->cfg_ini->nEnableSuspend == WLAN_MAP_SUSPEND_TO_STANDBY)
        {