diff options
author | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2018-08-28 11:44:44 +0100 |
---|---|---|
committer | Antonio Nino Diaz <antonio.ninodiaz@arm.com> | 2018-08-30 16:22:52 +0100 |
commit | 5a22e461b5841795c592a08b14c949c46c74e261 (patch) | |
tree | 13d08f9f1a47f8fd736f4780db190bcf3fa00734 | |
parent | d5ccb754af8664af33a1f5924ccbd75aa905587a (diff) |
Fix MISRA defects in log helpers
No functional changes.
Change-Id: I850f08718abb69d5d58856b0e3de036266d8c2f4
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
-rw-r--r-- | common/tf_log.c | 17 | ||||
-rw-r--r-- | include/common/debug.h | 18 | ||||
-rw-r--r-- | plat/common/plat_log_common.c | 21 |
3 files changed, 31 insertions, 25 deletions
diff --git a/common/tf_log.c b/common/tf_log.c index 6da1e85b..422959f6 100644 --- a/common/tf_log.c +++ b/common/tf_log.c @@ -28,19 +28,21 @@ void tf_log(const char *fmt, ...) log_level = fmt[0]; /* Verify that log_level is one of LOG_MARKER_* macro defined in debug.h */ - assert(log_level && log_level <= LOG_LEVEL_VERBOSE); - assert(log_level % 10 == 0); + assert((log_level > 0U) && (log_level <= LOG_LEVEL_VERBOSE)); + assert((log_level % 10U) == 0U); if (log_level > max_log_level) return; prefix_str = plat_log_get_prefix(log_level); - while (*prefix_str) - putchar(*prefix_str++); + while (*prefix_str != '\0') { + (void)putchar(*prefix_str); + prefix_str++; + } va_start(args, fmt); - vprintf(fmt + 1, args); + (void)vprintf(fmt + 1, args); va_end(args); } @@ -52,10 +54,9 @@ void tf_log(const char *fmt, ...) void tf_log_set_max_level(unsigned int log_level) { assert(log_level <= LOG_LEVEL_VERBOSE); - assert((log_level % 10) == 0); + assert((log_level % 10U) == 0U); /* Cap log_level to the compile time maximum. */ - if (log_level < LOG_LEVEL) + if (log_level < (unsigned int)LOG_LEVEL) max_log_level = log_level; - } diff --git a/include/common/debug.h b/include/common/debug.h index ab3e15a7..8ee55b88 100644 --- a/include/common/debug.h +++ b/include/common/debug.h @@ -7,6 +7,8 @@ #ifndef DEBUG_H #define DEBUG_H +#include <utils_def.h> + /* * The log output macros print output to the console. These macros produce * compiled log output only if the LOG_LEVEL defined in the makefile (or the @@ -18,12 +20,12 @@ * WARN("Warning %s.\n", "message") -> WARNING: Warning message. */ -#define LOG_LEVEL_NONE 0 -#define LOG_LEVEL_ERROR 10 -#define LOG_LEVEL_NOTICE 20 -#define LOG_LEVEL_WARNING 30 -#define LOG_LEVEL_INFO 40 -#define LOG_LEVEL_VERBOSE 50 +#define LOG_LEVEL_NONE U(0) +#define LOG_LEVEL_ERROR U(10) +#define LOG_LEVEL_NOTICE U(20) +#define LOG_LEVEL_WARNING U(30) +#define LOG_LEVEL_INFO U(40) +#define LOG_LEVEL_VERBOSE U(50) #ifndef __ASSEMBLY__ #include <cdefs.h> @@ -50,10 +52,10 @@ */ #define no_tf_log(fmt, ...) \ do { \ - if (0) { \ + if (false) { \ tf_log(fmt, ##__VA_ARGS__); \ } \ - } while (0) + } while (false) #if LOG_LEVEL >= LOG_LEVEL_NOTICE # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__) diff --git a/plat/common/plat_log_common.c b/plat/common/plat_log_common.c index 30dcb121..49e1c152 100644 --- a/plat/common/plat_log_common.c +++ b/plat/common/plat_log_common.c @@ -1,25 +1,28 @@ /* - * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ -#include <assert.h> #include <debug.h> -#include <platform.h> /* Allow platforms to override the log prefix string */ #pragma weak plat_log_get_prefix -static const char *prefix_str[] = { +static const char *plat_prefix_str[] = { "ERROR: ", "NOTICE: ", "WARNING: ", "INFO: ", "VERBOSE: "}; const char *plat_log_get_prefix(unsigned int log_level) { - if (log_level < LOG_LEVEL_ERROR) - log_level = LOG_LEVEL_ERROR; - else if (log_level > LOG_LEVEL_VERBOSE) - log_level = LOG_LEVEL_VERBOSE; + unsigned int level; - return prefix_str[(log_level/10) - 1]; + if (log_level < LOG_LEVEL_ERROR) { + level = LOG_LEVEL_ERROR; + } else if (log_level > LOG_LEVEL_VERBOSE) { + level = LOG_LEVEL_VERBOSE; + } else { + level = log_level; + } + + return plat_prefix_str[(level / 10U) - 1U]; } |