From fb3588e233efca76da11d4a5d8a6de1410b814ee Mon Sep 17 00:00:00 2001 From: Dong Wang Date: Fri, 14 Mar 2025 15:51:05 +0800 Subject: [PATCH] logging: Ensure atomic update of log filter slot in LOG_FILTER_SLOT_SET Replaced the read-modify-write sequence with a single read and write operation, preventing the intermediate value is wrongly used to filter out logs of another thread with higher priority that preempts the current thread. Signed-off-by: Dong Wang (cherry picked from commit 872f363696a8879b17df34eb8ebfc8fb0b733f02) --- include/zephyr/logging/log_core.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/zephyr/logging/log_core.h b/include/zephyr/logging/log_core.h index 64cd2a6c9e573..8af082fd653fb 100644 --- a/include/zephyr/logging/log_core.h +++ b/include/zephyr/logging/log_core.h @@ -400,12 +400,12 @@ static inline char z_log_minimal_level_to_char(int level) #define LOG_FILTER_SLOT_GET(_filters, _id) \ ((*(_filters) >> LOG_FILTER_SLOT_SHIFT(_id)) & LOG_FILTER_SLOT_MASK) -#define LOG_FILTER_SLOT_SET(_filters, _id, _filter) \ - do { \ - *(_filters) &= ~(LOG_FILTER_SLOT_MASK << \ - LOG_FILTER_SLOT_SHIFT(_id)); \ - *(_filters) |= ((_filter) & LOG_FILTER_SLOT_MASK) << \ - LOG_FILTER_SLOT_SHIFT(_id); \ +#define LOG_FILTER_SLOT_SET(_filters, _id, _filter) \ + do { \ + uint32_t others = *(_filters) & ~(LOG_FILTER_SLOT_MASK << \ + LOG_FILTER_SLOT_SHIFT(_id)); \ + *(_filters) = others | (((_filter) & LOG_FILTER_SLOT_MASK) << \ + LOG_FILTER_SLOT_SHIFT(_id)); \ } while (false) #define LOG_FILTER_AGGR_SLOT_IDX 0