From 4272353e29364c931cdc213915aa6b626f14cfeb Mon Sep 17 00:00:00 2001 From: Anthony Williams Date: Tue, 10 Dec 2024 20:05:16 -0500 Subject: [PATCH] Tracing: Fix extra function calls when using FIFO tracing macros. Fixes issue where function returns being used as data arguments to k_fifo tracing macros were being called mulitple times due to preprocessor copying macro arguments during expansion. Signed-off-by: Anthony Williams --- include/zephyr/kernel.h | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/include/zephyr/kernel.h b/include/zephyr/kernel.h index 82d4b3a6889b57..a8b0b5058e210d 100644 --- a/include/zephyr/kernel.h +++ b/include/zephyr/kernel.h @@ -2544,9 +2544,10 @@ struct k_fifo { */ #define k_fifo_put(fifo, data) \ ({ \ - SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, put, fifo, data); \ - k_queue_append(&(fifo)->_queue, data); \ - SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, put, fifo, data); \ + void *_data = data; \ + SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, put, fifo, _data); \ + k_queue_append(&(fifo)->_queue, _data); \ + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, put, fifo, _data); \ }) /** @@ -2567,9 +2568,10 @@ struct k_fifo { */ #define k_fifo_alloc_put(fifo, data) \ ({ \ - SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, alloc_put, fifo, data); \ - int fap_ret = k_queue_alloc_append(&(fifo)->_queue, data); \ - SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, alloc_put, fifo, data, fap_ret); \ + void *_data = data; \ + SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_fifo, alloc_put, fifo, _data); \ + int fap_ret = k_queue_alloc_append(&(fifo)->_queue, _data); \ + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_fifo, alloc_put, fifo, _data, fap_ret); \ fap_ret; \ }) @@ -2766,9 +2768,10 @@ struct k_lifo { */ #define k_lifo_put(lifo, data) \ ({ \ - SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, put, lifo, data); \ - k_queue_prepend(&(lifo)->_queue, data); \ - SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, put, lifo, data); \ + void *_data = data; \ + SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, put, lifo, _data); \ + k_queue_prepend(&(lifo)->_queue, _data); \ + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, put, lifo, _data); \ }) /** @@ -2789,9 +2792,10 @@ struct k_lifo { */ #define k_lifo_alloc_put(lifo, data) \ ({ \ - SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, alloc_put, lifo, data); \ - int lap_ret = k_queue_alloc_prepend(&(lifo)->_queue, data); \ - SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, alloc_put, lifo, data, lap_ret); \ + void *_data = data; \ + SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_lifo, alloc_put, lifo, _data); \ + int lap_ret = k_queue_alloc_prepend(&(lifo)->_queue, _data); \ + SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_lifo, alloc_put, lifo, _data, lap_ret); \ lap_ret; \ })