summaryrefslogtreecommitdiff
path: root/qdf/linux/src
diff options
context:
space:
mode:
authorDustin Brown <dustinb@codeaurora.org>2017-03-08 15:06:20 -0800
committerqcabuildsw <qcabuildsw@localhost>2017-03-09 10:34:13 -0800
commite16fb84094106b2260d917632d1e8b177a9bd7cd (patch)
tree1200b8015bf6751557db68b76c4d3de08091a61c /qdf/linux/src
parentc827bd2fc2f10d2fc28c132ac05999754c170d3f (diff)
qcacmn: Remove CONFIG_CNSS ifdef for memory proallocatation
Memory preallocation is hidden behind two flags, CONFIG_CNSS and CONFIG_WCNSS_MEM_PRE_ALLOC. Remove the check for CONFIG_CNSS, as the presence of CONFIG_WCNSS_MEM_PRE_ALLOC is enough. Change-Id: I233f6f31065c2d1da1ffb25a5013a17ac0b99246 CRs-Fixed: 2016844
Diffstat (limited to 'qdf/linux/src')
-rw-r--r--qdf/linux/src/qdf_mem.c70
1 files changed, 54 insertions, 16 deletions
diff --git a/qdf/linux/src/qdf_mem.c b/qdf/linux/src/qdf_mem.c
index f924925ebedb..616f8c793771 100644
--- a/qdf/linux/src/qdf_mem.c
+++ b/qdf/linux/src/qdf_mem.c
@@ -826,6 +826,47 @@ void qdf_mem_exit(void)
}
EXPORT_SYMBOL(qdf_mem_exit);
+#ifdef CONFIG_WCNSS_MEM_PRE_ALLOC
+/**
+ * qdf_mem_prealloc_get() - conditionally pre-allocate memory
+ * @size: the number of bytes to allocate
+ *
+ * If size if greater than WCNSS_PRE_ALLOC_GET_THRESHOLD, this function returns
+ * a chunk of pre-allocated memory. If size if less than or equal to
+ * WCNSS_PRE_ALLOC_GET_THRESHOLD, or an error occurs, NULL is returned instead.
+ *
+ * Return: NULL on failure, non-NULL on success
+ */
+static void *qdf_mem_prealloc_get(size_t size)
+{
+ void *mem;
+
+ if (size <= WCNSS_PRE_ALLOC_GET_THRESHOLD)
+ return NULL;
+
+ mem = wcnss_prealloc_get(size);
+ if (mem)
+ memset(mem, 0, size);
+
+ return mem;
+}
+
+static inline bool qdf_mem_prealloc_put(void *ptr)
+{
+ return wcnss_prealloc_put(ptr);
+}
+#else
+static inline void *qdf_mem_prealloc_get(size_t size)
+{
+ return NULL;
+}
+
+static inline bool qdf_mem_prealloc_put(void *ptr)
+{
+ return false;
+}
+#endif /* CONFIG_WCNSS_MEM_PRE_ALLOC */
+
/**
* qdf_mem_malloc_debug() - debug version of QDF memory allocation API
* @size: Number of bytes of memory to allocate.
@@ -858,16 +899,9 @@ void *qdf_mem_malloc_debug(size_t size,
return NULL;
}
-#if defined(CONFIG_CNSS) && defined(CONFIG_WCNSS_MEM_PRE_ALLOC)
- if (size > WCNSS_PRE_ALLOC_GET_THRESHOLD) {
- void *pmem;
- pmem = wcnss_prealloc_get(size);
- if (NULL != pmem) {
- memset(pmem, 0, size);
- return pmem;
- }
- }
-#endif
+ mem_ptr = qdf_mem_prealloc_get(size);
+ if (mem_ptr)
+ return mem_ptr;
if (in_interrupt() || irqs_disabled() || in_atomic())
flags = GFP_ATOMIC;
@@ -983,10 +1017,9 @@ void qdf_mem_free(void *ptr)
QDF_BUG(0);
}
-#if defined(CONFIG_CNSS) && defined(CONFIG_WCNSS_MEM_PRE_ALLOC)
- if (wcnss_prealloc_put(ptr))
+ if (qdf_mem_prealloc_put(ptr))
return;
-#endif
+
if (!qdf_atomic_dec_and_test(&mem_struct->in_use))
return;
@@ -1085,6 +1118,11 @@ EXPORT_SYMBOL(qdf_mem_free);
void *qdf_mem_malloc(size_t size)
{
int flags = GFP_KERNEL;
+ void *mem;
+
+ mem = qdf_mem_prealloc_get(size);
+ if (mem)
+ return mem;
if (in_interrupt() || irqs_disabled())
flags = GFP_ATOMIC;
@@ -1105,10 +1143,10 @@ void qdf_mem_free(void *ptr)
{
if (ptr == NULL)
return;
-#if defined(CONFIG_CNSS) && defined(CONFIG_WCNSS_MEM_PRE_ALLOC)
- if (wcnss_prealloc_put(ptr))
+
+ if (qdf_mem_prealloc_put(ptr))
return;
-#endif
+
kfree(ptr);
}
EXPORT_SYMBOL(qdf_mem_free);