Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5d61ede9 authored by gaurank kathpalia's avatar gaurank kathpalia Committed by Gerrit - the friendly Code Review server
Browse files

qcacmn: Use atomic allocation for all scheduler context allocations

In low memory environments using GFP_KERNEL flag may cause
scheduler thread to sleep. Scheduler thread callback handlers
are expected to be atomic in nature to ensure timely execution
of different commands.

Change-Id: Iee3eafbc00a3afea0687ba67b3041ec0816094cc
CRs-Fixed: 2232553
parent 53f8143c
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -95,6 +95,7 @@ void qdf_mem_exit(void);
 * @file: File name of the call site
 * @line: Line number of the call site
 * @caller: Address of the caller function
 * @@flag: GFP flag
 *
 * This function will dynamicallly allocate the specified number of bytes of
 * memory and add it to the qdf tracking list to check for memory leaks and
@@ -103,11 +104,13 @@ void qdf_mem_exit(void);
 * Return: A valid memory location on success, or NULL on failure
 */
void *qdf_mem_malloc_debug(size_t size, const char *file, uint32_t line,
			   void *caller);
			   void *caller, uint32_t flag);

#define qdf_mem_malloc(size) \
	qdf_mem_malloc_debug(size, __FILE__, __LINE__, QDF_RET_IP)
	qdf_mem_malloc_debug(size, __FILE__, __LINE__, QDF_RET_IP, 0)

#define qdf_mem_malloc_atomic(size) \
	qdf_mem_malloc_debug(size, __FILE__, __LINE__, QDF_RET_IP, GFP_ATOMIC)
/**
 * qdf_mem_free_debug() - debug version of qdf_mem_free
 * @ptr: Pointer to the starting address of the memory to be freed.
@@ -198,6 +201,7 @@ void qdf_mem_free_consistent_debug(qdf_device_t osdev, void *dev,
				  __FILE__, __LINE__)
#else
void *qdf_mem_malloc(qdf_size_t size);
void *qdf_mem_malloc_atomic(qdf_size_t size);

/**
 * qdf_mem_free() - free QDF memory
+35 −3
Original line number Diff line number Diff line
@@ -1059,7 +1059,7 @@ static void qdf_mem_debug_exit(void)
}

void *qdf_mem_malloc_debug(size_t size, const char *file, uint32_t line,
			   void *caller)
			   void *caller, uint32_t flag)
{
	QDF_STATUS status;
	enum qdf_debug_domain current_domain = qdf_debug_domain_get();
@@ -1076,9 +1076,10 @@ void *qdf_mem_malloc_debug(size_t size, const char *file, uint32_t line,
	ptr = qdf_mem_prealloc_get(size);
	if (ptr)
		return ptr;

	if (!flag)
		flag = qdf_mem_malloc_flags();
	start = qdf_mc_timer_get_system_time();
	header = kzalloc(size + QDF_MEM_DEBUG_SIZE, qdf_mem_malloc_flags());
	header = kzalloc(size + QDF_MEM_DEBUG_SIZE, flag);
	duration = qdf_mc_timer_get_system_time() - start;

	if (duration > QDF_MEM_WARN_THRESHOLD)
@@ -1191,6 +1192,37 @@ void *qdf_mem_malloc(size_t size)
}
qdf_export_symbol(qdf_mem_malloc);

/**
 * qdf_mem_malloc_atomic() - allocation QDF memory atomically
 * @size: Number of bytes of memory to allocate.
 *
 * This function will dynamicallly allocate the specified number of bytes of
 * memory.
 *
 * Return:
 * Upon successful allocate, returns a non-NULL pointer to the allocated
 * memory.  If this function is unable to allocate the amount of memory
 *specified (for any reason) it returns NULL.
*/
void *qdf_mem_malloc_atomic(size_t size)
{
	void *ptr;

	ptr = qdf_mem_prealloc_get(size);
	if (ptr)
		return ptr;

	ptr = kzalloc(size, GFP_ATOMIC);
	if (!ptr)
		return NULL;

	qdf_mem_kmalloc_inc(ksize(ptr));

	return ptr;
}

qdf_export_symbol(qdf_mem_malloc_atomic);

/**
 * qdf_mem_free() - free QDF memory
 * @ptr: Pointer to the starting address of the memory to be free'd.