From 3f58e4ec10c5df57bad1296bb9a5cbc7bfacaef1 Mon Sep 17 00:00:00 2001 From: Ovidiu Mihalachi Date: Mon, 5 Nov 2018 12:05:51 +0200 Subject: trace levels: Redefine TRACE_MIN level to 0 The global `trace_level` session-wise indicator which is set by `trace_set_level()` [1], could get a wrong value in case of an input `level` set to 0, meaning that all logs need to be disabled by user define `CFG_TEE_TA_LOG_LEVEL=0` when building TA applications. This inconsistency is caused by a rather wrong value of `TRACE_MIN` low boundary value set to 1. According to [1] `trace level` will be set to `TRACE_MAX` (4) in case input level is smaller than `TRACE_MIN` and larger than `TRACE_MAX`. In the scenario when the needed log level is 0, `trace level` would be set to `TRACE_MAX` and will cause a lot of flow log level information dumped by trace functions/macros that are using `trace_printf()` primitive. This patch sets the `TRACE_MIN` to 0 in order to assure a proper trace level setting and completely disable all logs in case `CFG_TEE_TA_LOG_LEVEL=0`. [1] void trace_set_level(int level) { if (((int)level >= TRACE_MIN) && (level <= TRACE_MAX)) trace_level = level; else trace_level = TRACE_MAX; } Acked-by: Christoph Gellner Signed-off-by: Ovidiu Mihalachi Reviewed-by: Jens Wiklander Reviewed-by: Jerome Forissier Reviewed-by: Etienne Carriere --- lib/libutils/ext/include/trace_levels.h | 4 ++-- lib/libutils/ext/trace.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/libutils/ext/include/trace_levels.h b/lib/libutils/ext/include/trace_levels.h index f717880f..7fd51815 100644 --- a/lib/libutils/ext/include/trace_levels.h +++ b/lib/libutils/ext/include/trace_levels.h @@ -23,8 +23,8 @@ * */ -#define TRACE_MIN 1 -#define TRACE_ERROR TRACE_MIN +#define TRACE_MIN 0 +#define TRACE_ERROR 1 #define TRACE_INFO 2 #define TRACE_DEBUG 3 #define TRACE_FLOW 4 diff --git a/lib/libutils/ext/trace.c b/lib/libutils/ext/trace.c index 6ee433ca..e9258fbf 100644 --- a/lib/libutils/ext/trace.c +++ b/lib/libutils/ext/trace.c @@ -15,12 +15,12 @@ #include #include -#if (TRACE_LEVEL > 0) - #if (TRACE_LEVEL < TRACE_MIN) || (TRACE_LEVEL > TRACE_MAX) #error "Invalid value of TRACE_LEVEL" #endif +#if (TRACE_LEVEL >= TRACE_ERROR) + void trace_set_level(int level) { if (((int)level >= TRACE_MIN) && (level <= TRACE_MAX)) -- cgit v1.2.3