Snap for 11041982 from 1ce89f702faf0228507f62d20e91a026d80b67e1 to mainline-uwb-release

Change-Id: Ia0680c02f2fc582e56216a44cb3f70be29060a1f
diff --git a/bcmdhd/wifi_hal/wifi_hal.cpp b/bcmdhd/wifi_hal/wifi_hal.cpp
index f746f09..f3039ca 100644
--- a/bcmdhd/wifi_hal/wifi_hal.cpp
+++ b/bcmdhd/wifi_hal/wifi_hal.cpp
@@ -608,7 +608,6 @@
 static void internal_cleaned_up_handler(wifi_handle handle)
 {
     hal_info *info = getHalInfo(handle);
-    wifi_cleaned_up_handler cleaned_up_handler = info->cleaned_up_handler;
 
     ALOGI("internal clean up");
 
@@ -622,12 +621,6 @@
         info->event_sock = NULL;
     }
 
-    if (cleaned_up_handler) {
-        ALOGI("cleanup_handler cb");
-        (*cleaned_up_handler)(handle);
-    } else {
-        ALOGI("!! clean up handler is null!!");
-    }
     DestroyResponseLock();
     pthread_mutex_destroy(&info->cb_lock);
     free(info);
@@ -641,7 +634,7 @@
     twt_deinit_handler();
 }
 
-void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler handler)
+void wifi_cleanup(wifi_handle handle, wifi_cleaned_up_handler cleaned_up_handler)
 {
     if (!handle) {
         ALOGE("Handle is null");
@@ -655,8 +648,6 @@
     wifi_interface_handle *ifaceHandles = NULL;
     wifi_interface_handle wlan0Handle;
 
-    info->cleaned_up_handler = handler;
-
     wlan0Handle = wifi_get_wlan_interface((wifi_handle) info, ifaceHandles, numIfaceHandles);
 
     if (wlan0Handle != NULL) {
@@ -728,6 +719,14 @@
 
     info->clean_up = true;
 
+    /* global func ptr be invalidated and will not call any command from legacy hal */
+    if (cleaned_up_handler) {
+        ALOGI("cleaned_up_handler to invalidates func ptr");
+        cleaned_up_handler(handle);
+    } else {
+        ALOGI("cleaned up handler is null");
+    }
+
     if (TEMP_FAILURE_RETRY(write(info->cleanup_socks[0], "Exit", 4)) < 1) {
         // As a fallback set the cleanup flag to TRUE
         ALOGE("could not write to the cleanup socket");