From 8ddef7dd9a290d4a9b1efd5d3efacf51d78a1a0d Mon Sep 17 00:00:00 2001 From: Dustin Brown Date: Mon, 25 Feb 2019 13:53:18 -0800 Subject: [PATCH] qcacmn: Remove qdf_flex_mem_release() Due to a limitation in the memory leak detection logic when qdf_flex_mem was written, qdf_flex_mem_release() was necessary to free any dynamically allocated memory in the qdf_flex_mem_pool during certain points in the WLAN driver lifecycle. This was done to avoid flagging any dynamically allocated qdf_flex_mem_segments as false positive leaks when the memory domains were changed and leak checking was performed. With the introduction of qdf_talloc(), this workaround is no longer required. Replace the calls to qdf_mem_malloc/free with qdf_talloc/free, and remove qdf_flex_mem_release() altogether. Change-Id: Ia5fd21386b94fc117af5f27853db5d8341601738 CRs-Fixed: 2404955 --- qdf/inc/qdf_flex_mem.h | 12 +------- qdf/linux/src/qdf_nbuf.c | 2 -- qdf/src/qdf_flex_mem.c | 50 ++++++++++------------------------ scheduler/src/scheduler_core.c | 4 +-- 4 files changed, 17 insertions(+), 51 deletions(-) diff --git a/qdf/inc/qdf_flex_mem.h b/qdf/inc/qdf_flex_mem.h index 80842e9c58d8..2170b71458ea 100644 --- a/qdf/inc/qdf_flex_mem.h +++ b/qdf/inc/qdf_flex_mem.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -130,14 +130,4 @@ void *qdf_flex_mem_alloc(struct qdf_flex_mem_pool *pool); */ void qdf_flex_mem_free(struct qdf_flex_mem_pool *pool, void *ptr); -/** - * qdf_flex_mem_release() - release unused segments - * @pool: the pool to operate against - * - * This function physically releases as much unused pool memory as possible. - * - * Return: None - */ -void qdf_flex_mem_release(struct qdf_flex_mem_pool *pool); - #endif /* __QDF_FLEX_MEM_H */ diff --git a/qdf/linux/src/qdf_nbuf.c b/qdf/linux/src/qdf_nbuf.c index b04fd9d5e042..9321bc02f7c7 100644 --- a/qdf/linux/src/qdf_nbuf.c +++ b/qdf/linux/src/qdf_nbuf.c @@ -625,8 +625,6 @@ static void qdf_nbuf_map_leaks_print(void) void qdf_nbuf_map_check_for_leaks(void) { - qdf_flex_mem_release(&qdf_nbuf_map_pool); - qdf_spin_lock_irqsave(&qdf_nbuf_map_lock); if (!hash_empty(qdf_nbuf_map_ht)) qdf_nbuf_map_leaks_print(); diff --git a/qdf/src/qdf_flex_mem.c b/qdf/src/qdf_flex_mem.c index db005e4b5efe..2fcdff6f0cc2 100644 --- a/qdf/src/qdf_flex_mem.c +++ b/qdf/src/qdf_flex_mem.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018 The Linux Foundation. All rights reserved. + * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -21,6 +21,7 @@ #include "qdf_lock.h" #include "qdf_mem.h" #include "qdf_module.h" +#include "qdf_talloc.h" #include "qdf_trace.h" #include "qdf_util.h" @@ -31,7 +32,7 @@ qdf_flex_mem_seg_alloc(struct qdf_flex_mem_pool *pool) size_t total_size = sizeof(struct qdf_flex_mem_segment) + pool->item_size * QDF_FM_BITMAP_BITS; - seg = qdf_mem_malloc(total_size); + seg = qdf_talloc(pool, total_size); if (!seg) return NULL; @@ -56,10 +57,19 @@ qdf_export_symbol(qdf_flex_mem_init); void qdf_flex_mem_deinit(struct qdf_flex_mem_pool *pool) { - qdf_flex_mem_release(pool); - QDF_BUG(!qdf_list_size(&pool->seg_list)); + struct qdf_flex_mem_segment *seg, *next; qdf_spinlock_destroy(&pool->lock); + + qdf_list_for_each_del(&pool->seg_list, seg, next, node) { + QDF_BUG(!seg->used_bitmap); + if (seg->used_bitmap) + continue; + + qdf_list_remove_node(&pool->seg_list, &seg->node); + if (seg->dynamic) + qdf_tfree(seg); + } } qdf_export_symbol(qdf_flex_mem_deinit); @@ -118,9 +128,8 @@ static void qdf_flex_mem_seg_free(struct qdf_flex_mem_pool *pool, if (qdf_list_size(&pool->seg_list) <= pool->reduction_limit) return; - qdf_list_remove_node(&pool->seg_list, &seg->node); - qdf_mem_free(seg); + qdf_tfree(seg); } static void __qdf_flex_mem_free(struct qdf_flex_mem_pool *pool, void *ptr) @@ -166,32 +175,3 @@ void qdf_flex_mem_free(struct qdf_flex_mem_pool *pool, void *ptr) } qdf_export_symbol(qdf_flex_mem_free); -static void __qdf_flex_mem_release(struct qdf_flex_mem_pool *pool) -{ - struct qdf_flex_mem_segment *seg; - struct qdf_flex_mem_segment *next; - - qdf_list_for_each_del(&pool->seg_list, seg, next, node) { - if (!seg->dynamic) - continue; - - if (seg->used_bitmap != 0) - continue; - - qdf_list_remove_node(&pool->seg_list, &seg->node); - qdf_mem_free(seg); - } -} - -void qdf_flex_mem_release(struct qdf_flex_mem_pool *pool) -{ - QDF_BUG(pool); - if (!pool) - return; - - qdf_spin_lock_bh(&pool->lock); - __qdf_flex_mem_release(pool); - qdf_spin_unlock_bh(&pool->lock); -} -qdf_export_symbol(qdf_flex_mem_release); - diff --git a/scheduler/src/scheduler_core.c b/scheduler/src/scheduler_core.c index df7b4dbb0b8e..34db7a1343d2 100644 --- a/scheduler/src/scheduler_core.c +++ b/scheduler/src/scheduler_core.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved. + * Copyright (c) 2014-2019 The Linux Foundation. All rights reserved. * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the @@ -455,7 +455,5 @@ void scheduler_queues_flush(struct scheduler_ctx *sched_ctx) mq = &sched_ctx->queue_ctx.sch_msg_q[i]; scheduler_flush_single_queue(mq); } - - qdf_flex_mem_release(&sched_pool); }