MINOR: pools: replace DEBUG_POOL_TRACING with runtime POOL_DBG_CALLER
This option used to allow to store a pointer to the caller of the last
pool_alloc() or pool_free() at the end of the area. Now that we can
compute the offsets at runtime, let's check it at run time and continue
the code simplification. In __pool_alloc() we now always calculate the
return address (which is quite cheap), and the POOL_DEBUG_TRACE_CALLER()
calls are conditionned on the status of debugging option.
diff --git a/src/pool.c b/src/pool.c
index 0fb3f08..afe3d51 100644
--- a/src/pool.c
+++ b/src/pool.c
@@ -54,6 +54,9 @@
#ifndef CONFIG_HAP_POOLS
POOL_DBG_NO_CACHE |
#endif
+#if defined(DEBUG_POOL_TRACING)
+ POOL_DBG_CALLER |
+#endif
0;
static int mem_fail_rate __read_mostly = 0;
@@ -204,7 +207,7 @@
*/
extra_mark = POOL_EXTRA_MARK;
- extra_caller = POOL_EXTRA_CALLER;
+ extra_caller = (pool_debugging & POOL_DBG_CALLER) ? POOL_EXTRA_CALLER : 0;
extra = extra_mark + extra_caller;
if (!(flags & MEM_F_EXACT)) {
@@ -679,15 +682,12 @@
void *__pool_alloc(struct pool_head *pool, unsigned int flags)
{
void *p = NULL;
- void *caller = NULL;
+ void *caller = __builtin_return_address(0);
if (unlikely(pool_debugging & POOL_DBG_FAIL_ALLOC))
if (!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool))
return NULL;
-#if defined(DEBUG_POOL_TRACING)
- caller = __builtin_return_address(0);
-#endif
if (likely(!(pool_debugging & POOL_DBG_NO_CACHE)) && !p)
p = pool_get_from_cache(pool, caller);
@@ -709,11 +709,8 @@
*/
void __pool_free(struct pool_head *pool, void *ptr)
{
- const void *caller = NULL;
+ const void *caller = __builtin_return_address(0);
-#if defined(DEBUG_POOL_TRACING)
- caller = __builtin_return_address(0);
-#endif
/* we'll get late corruption if we refill to the wrong pool or double-free */
POOL_DEBUG_CHECK_MARK(pool, ptr);
POOL_DEBUG_RESET_MARK(pool, ptr);