Browse Source

qcacmn: Allocate gplog_msg dynamically

Allocate memory for gplog_msg buffer dynamically.

Change-Id: I70b79215b5f318217de180a53c4bad5f237be37d
CRs-Fixed: 2266814
Rachit Kankane 6 years ago
parent
commit
97c4e1efcc
1 changed files with 37 additions and 1 deletions
  1. 37 1
      utils/logging/src/wlan_logging_sock_svc.c

+ 37 - 1
utils/logging/src/wlan_logging_sock_svc.c

@@ -174,9 +174,37 @@ struct wlan_logging {
 };
 
 static struct wlan_logging gwlan_logging;
-static struct log_msg gplog_msg[MAX_LOGMSG_COUNT];
 static struct pkt_stats_msg *gpkt_stats_buffers;
 
+#ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY
+
+static struct log_msg *gplog_msg;
+
+static inline QDF_STATUS allocate_log_msg_buffer(void)
+{
+	gplog_msg = vzalloc(MAX_LOGMSG_COUNT * sizeof(*gplog_msg));
+
+	return gplog_msg ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM;
+}
+
+static inline void free_log_msg_buffer(void)
+{
+	vfree(gplog_msg);
+	gplog_msg = NULL;
+}
+
+#else
+static struct log_msg gplog_msg[MAX_LOGMSG_COUNT];
+
+static inline QDF_STATUS allocate_log_msg_buffer(void)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline void free_log_msg_buffer(void)
+{ }
+#endif
+
 /* Need to call this with spin_lock acquired */
 static int wlan_queue_logmsg_for_app(void)
 {
@@ -840,6 +868,12 @@ int wlan_logging_sock_init_svc(void)
 	INIT_LIST_HEAD(&gwlan_logging.free_list);
 	INIT_LIST_HEAD(&gwlan_logging.filled_list);
 
+	if (allocate_log_msg_buffer() != QDF_STATUS_SUCCESS) {
+		pr_err("%s: Could not allocate memory for log_msg\n",
+		       __func__);
+		return -ENOMEM;
+	}
+
 	for (i = 0; i < gwlan_logging.num_buf; i++) {
 		list_add(&gplog_msg[i].node, &gwlan_logging.free_list);
 		gplog_msg[i].index = i;
@@ -922,6 +956,7 @@ err1:
 	spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag);
 	gwlan_logging.pcur_node = NULL;
 	spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag);
+	free_log_msg_buffer();
 
 	return -ENOMEM;
 }
@@ -965,6 +1000,7 @@ int wlan_logging_sock_deinit_svc(void)
 
 	vfree(gpkt_stats_buffers);
 	gpkt_stats_buffers = NULL;
+	free_log_msg_buffer();
 
 	return 0;
 }