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

Commit 8d640b6c authored by Sarada Prasanna Garnayak's avatar Sarada Prasanna Garnayak Committed by Gerrit - the friendly Code Review server
Browse files

cnss_prealloc: add api to check memory leak and memory pool reset



WLAN module interface with high latency bus need pre-alloc memory
for the socket buffer descriptor. Wlan host diver request for
pre-alloc memory from the skb pre-alloc memory pool for socket
buffer initialization and release the memory back to socket buffer
memory pool on descriptor deinit.

Add api to check the memory leak in socket buffer memory pool
and reset the socket buffer memory pool on memory leak detection.

CRs-Fixed: 1080107
Change-Id: Ic754883ffdfb718c6082e1038a751fde7c49fa08
Signed-off-by: default avatarSarada Prasanna Garnayak <sgarna@codeaurora.org>
parent 86691680
Loading
Loading
Loading
Loading
+53 −3
Original line number Diff line number Diff line
@@ -310,15 +310,16 @@ EXPORT_SYMBOL(wcnss_skb_prealloc_put);
#ifdef CONFIG_SLUB_DEBUG
void wcnss_prealloc_check_memory_leak(void)
{
	int i, j = 0;
	int i;
	bool leak_detected = false;

	for (i = 0; i < ARRAY_SIZE(wcnss_allocs); i++) {
		if (!wcnss_allocs[i].occupied)
			continue;

		if (j == 0) {
		if (!leak_detected) {
			pr_err("wcnss_prealloc: Memory leak detected\n");
			j++;
			leak_detected = true;
		}

		pr_err("Size: %u, addr: %pK, backtrace:\n",
@@ -327,6 +328,55 @@ void wcnss_prealloc_check_memory_leak(void)
	}

}

/* Check memory leak for socket buffer pre-alloc memeory pool */
#ifdef CONFIG_WCNSS_SKB_PRE_ALLOC
void wcnss_skb_prealloc_check_memory_leak(void)
{
	int i;
	bool leak_detected = false;

	for (i = 0; i < ARRAY_SIZE(wcnss_skb_allocs); i++) {
		if (!wcnss_skb_allocs[i].occupied)
			continue;

		if (!leak_detected) {
			pr_err("wcnss_skb_prealloc: Memory leak detected\n");
			leak_detected = true;
		}

		pr_err(
			"Size: %u, addr: %pK, backtrace:\n",
			wcnss_skb_allocs[i].size, wcnss_skb_allocs[i].ptr);
		print_stack_trace(&wcnss_skb_allocs[i].trace, 1);
	}
}
#else
void wcnss_skb_prealloc_check_memory_leak(void) {}
#endif
#endif

#ifdef CONFIG_WCNSS_SKB_PRE_ALLOC
/* Reset socket buffer pre-allock memory pool */
int wcnss_skb_pre_alloc_reset(void)
{
	int i, n = 0;

	for (i = 0; i < ARRAY_SIZE(wcnss_skb_allocs); i++) {
		if (!wcnss_skb_allocs[i].occupied)
			continue;

		wcnss_skb_allocs[i].occupied = 0;
		n++;
	}

	return n;
}
#else
int wcnss_skb_pre_alloc_reset(void)
{
	return 0;
}
#endif

int wcnss_pre_alloc_reset(void)
+3 −0
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ extern int wcnss_prealloc_put(void *ptr);
extern int wcnss_pre_alloc_reset(void);
void wcnss_prealloc_check_memory_leak(void);

extern void wcnss_skb_prealloc_check_memory_leak(void);
extern int wcnss_skb_pre_alloc_reset(void);

#ifdef CONFIG_WCNSS_SKB_PRE_ALLOC
extern struct sk_buff *wcnss_skb_prealloc_get(unsigned int size);
extern int wcnss_skb_prealloc_put(struct sk_buff *skb);