qcacld-3.0: Redefine dfs data structure to fix prealloc size concern

Redefine dfs filter type to avoid prealloc problem by making one
large chunk into multiple smaller chunks.

With current data structure, dfs attach was requesting huge chunk
of memory from the heap which results in failure. This change set
fixes the issue by modifying the data structure so that one
large chunk is made as multiple smaller chunks.

Change-Id: If944747de63a68d55a83b8595d0a07dd05f53dbe
CRs-Fixed: 975903
diff --git a/core/sap/dfs/src/dfs.c b/core/sap/dfs/src/dfs.c
index 4d7fbbc..d938c01 100644
--- a/core/sap/dfs/src/dfs.c
+++ b/core/sap/dfs/src/dfs.c
@@ -215,6 +215,44 @@
 	return (int)dfs->dfs_proc_phyerr;
 }
 
+/**
+ * dfs_alloc_mem_filter() - allocate memory for dfs ft_filters
+ * @radarf: pointer holding ft_filters
+ *
+ * Return: 0-success and 1-failure
+*/
+static int dfs_alloc_mem_filter(struct dfs_filtertype *radarf)
+{
+	int status = 0, n, i;
+
+	for (i = 0; i < DFS_MAX_NUM_RADAR_FILTERS; i++) {
+		radarf->ft_filters[i] = qdf_mem_malloc(sizeof(struct
+							      dfs_filter));
+		if (NULL == radarf->ft_filters[i]) {
+			DFS_PRINTK("%s[%d]: mem alloc failed\n",
+				    __func__, __LINE__);
+			status = 1;
+			goto error;
+		}
+	}
+
+	return status;
+
+error:
+	/* free up allocated memory */
+	for (n = 0; n < i; n++) {
+		if (radarf->ft_filters[n]) {
+			qdf_mem_free(radarf->ft_filters[n]);
+			radarf->ft_filters[i] = NULL;
+		}
+	}
+
+	DFS_PRINTK("%s[%d]: cannot allocate memory for radar filter types\n",
+		    __func__, __LINE__);
+
+	return status;
+}
+
 int dfs_attach(struct ieee80211com *ic)
 {
 	int i, n;
@@ -325,18 +363,20 @@
 
 	/* Allocate memory for radar filters */
 	for (n = 0; n < DFS_MAX_RADAR_TYPES; n++) {
-		dfs->dfs_radarf[n] =
-			(struct dfs_filtertype *)os_malloc(NULL,
-							   sizeof(struct
-								  dfs_filtertype),
-							   GFP_ATOMIC);
+		dfs->dfs_radarf[n] = (struct dfs_filtertype *)
+			os_malloc(NULL, sizeof(struct dfs_filtertype),
+				  GFP_ATOMIC);
 		if (dfs->dfs_radarf[n] == NULL) {
 			DFS_PRINTK
 				("%s: cannot allocate memory for radar filter types\n",
 				__func__);
 			goto bad1;
+		} else {
+			qdf_mem_zero(dfs->dfs_radarf[n],
+				   sizeof(struct dfs_filtertype));
+			if (0 != dfs_alloc_mem_filter(dfs->dfs_radarf[n]))
+				goto bad1;
 		}
-		OS_MEMZERO(dfs->dfs_radarf[n], sizeof(struct dfs_filtertype));
 	}
 	/* Allocate memory for radar table */
 	dfs->dfs_radartable =
@@ -431,6 +471,23 @@
 #undef N
 }
 
+/**
+ * dfs_free_filter() - free memory allocated for dfs ft_filters
+ * @radarf: pointer holding ft_filters
+ *
+ * Return: NA
+*/
+static void dfs_free_filter(struct dfs_filtertype *radarf)
+{
+	int i;
+
+	for (i = 0; i < DFS_MAX_NUM_RADAR_FILTERS; i++) {
+		if (radarf->ft_filters[i]) {
+			qdf_mem_free(radarf->ft_filters[i]);
+			radarf->ft_filters[i] = NULL;
+		}
+	}
+}
 void dfs_detach(struct ieee80211com *ic)
 {
 	struct ath_dfs *dfs = (struct ath_dfs *)ic->ic_dfs;
@@ -496,6 +553,7 @@
 
 	for (n = 0; n < DFS_MAX_RADAR_TYPES; n++) {
 		if (dfs->dfs_radarf[n] != NULL) {
+			dfs_free_filter(dfs->dfs_radarf[n]);
 			OS_FREE(dfs->dfs_radarf[n]);
 			dfs->dfs_radarf[n] = NULL;
 		}