WiFi-HAL: Unlock mutex before calling framework callback

As part of earlier commit log_handler and alert_handler were
protected by mutex. However, calling framework callback within
mutex context would cause deadlock, thus unlock mutex before
calling the framework callback and reacquire again when required.

Bug: 23530883
Change-Id: If4cd92be906307a9e5ff7a8002b219f93f1bda64
diff --git a/qcwcn/wifi_hal/rb_wrapper.cpp b/qcwcn/wifi_hal/rb_wrapper.cpp
index 4738628..932af06 100644
--- a/qcwcn/wifi_hal/rb_wrapper.cpp
+++ b/qcwcn/wifi_hal/rb_wrapper.cpp
@@ -104,13 +104,7 @@
     struct rb_info *rb_info = (struct rb_info *)cb_ctx;
     hal_info *info = (hal_info *)rb_info->ctx;
     wifi_ring_buffer_status rbs;
-
-    pthread_mutex_lock(&info->lh_lock);
-    if (info->on_ring_buffer_data == NULL) {
-        ALOGE("on_ring_buffer_data handle is not set yet");
-        pthread_mutex_unlock(&info->lh_lock);
-        return;
-    }
+    wifi_ring_buffer_data_handler handler;
 
     while (1) {
         size_t length = 0;
@@ -121,10 +115,15 @@
             break;
         }
         get_rb_status(rb_info, &rbs);
-        info->on_ring_buffer_data(rb_info->name, (char *)buf, length, &rbs);
+        pthread_mutex_lock(&info->lh_lock);
+        handler.on_ring_buffer_data = info->on_ring_buffer_data;
+        pthread_mutex_unlock(&info->lh_lock);
+        if (handler.on_ring_buffer_data) {
+            handler.on_ring_buffer_data(rb_info->name, (char *)buf,
+                                        length, &rbs);
+        }
         free(buf);
     };
-    pthread_mutex_unlock(&info->lh_lock);
     gettimeofday(&rb_info->last_push_time, NULL);
 }
 
diff --git a/qcwcn/wifi_hal/wifilogger.cpp b/qcwcn/wifi_hal/wifilogger.cpp
index 1baaed3..87b1412 100644
--- a/qcwcn/wifi_hal/wifilogger.cpp
+++ b/qcwcn/wifi_hal/wifilogger.cpp
@@ -199,11 +199,15 @@
 
 void send_alert(hal_info *info, int reason_code)
 {
+    wifi_alert_handler handler;
+
     pthread_mutex_lock(&info->ah_lock);
-    if (info->on_alert) {
-        info->on_alert(0, NULL, 0, reason_code);
-    }
+    handler.on_alert = info->on_alert;
     pthread_mutex_unlock(&info->ah_lock);
+
+    if (handler.on_alert) {
+        handler.on_alert(0, NULL, 0, reason_code);
+    }
 }
 
 void WifiLoggerCommand::setFeatureSet(u32 *support) {