Commit 5a22e461 authored by Antonio Nino Diaz's avatar Antonio Nino Diaz
Browse files

Fix MISRA defects in log helpers



No functional changes.

Change-Id: I850f08718abb69d5d58856b0e3de036266d8c2f4
Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
parent d5ccb754
...@@ -28,19 +28,21 @@ void tf_log(const char *fmt, ...) ...@@ -28,19 +28,21 @@ void tf_log(const char *fmt, ...)
log_level = fmt[0]; log_level = fmt[0];
/* Verify that log_level is one of LOG_MARKER_* macro defined in debug.h */ /* 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 > 0U) && (log_level <= LOG_LEVEL_VERBOSE));
assert(log_level % 10 == 0); assert((log_level % 10U) == 0U);
if (log_level > max_log_level) if (log_level > max_log_level)
return; return;
prefix_str = plat_log_get_prefix(log_level); prefix_str = plat_log_get_prefix(log_level);
while (*prefix_str) while (*prefix_str != '\0') {
putchar(*prefix_str++); (void)putchar(*prefix_str);
prefix_str++;
}
va_start(args, fmt); va_start(args, fmt);
vprintf(fmt + 1, args); (void)vprintf(fmt + 1, args);
va_end(args); va_end(args);
} }
...@@ -52,10 +54,9 @@ void tf_log(const char *fmt, ...) ...@@ -52,10 +54,9 @@ void tf_log(const char *fmt, ...)
void tf_log_set_max_level(unsigned int log_level) void tf_log_set_max_level(unsigned int log_level)
{ {
assert(log_level <= LOG_LEVEL_VERBOSE); assert(log_level <= LOG_LEVEL_VERBOSE);
assert((log_level % 10) == 0); assert((log_level % 10U) == 0U);
/* Cap log_level to the compile time maximum. */ /* 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; max_log_level = log_level;
} }
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#ifndef DEBUG_H #ifndef DEBUG_H
#define DEBUG_H #define DEBUG_H
#include <utils_def.h>
/* /*
* The log output macros print output to the console. These macros produce * 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 * compiled log output only if the LOG_LEVEL defined in the makefile (or the
...@@ -18,12 +20,12 @@ ...@@ -18,12 +20,12 @@
* WARN("Warning %s.\n", "message") -> WARNING: Warning message. * WARN("Warning %s.\n", "message") -> WARNING: Warning message.
*/ */
#define LOG_LEVEL_NONE 0 #define LOG_LEVEL_NONE U(0)
#define LOG_LEVEL_ERROR 10 #define LOG_LEVEL_ERROR U(10)
#define LOG_LEVEL_NOTICE 20 #define LOG_LEVEL_NOTICE U(20)
#define LOG_LEVEL_WARNING 30 #define LOG_LEVEL_WARNING U(30)
#define LOG_LEVEL_INFO 40 #define LOG_LEVEL_INFO U(40)
#define LOG_LEVEL_VERBOSE 50 #define LOG_LEVEL_VERBOSE U(50)
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#include <cdefs.h> #include <cdefs.h>
...@@ -50,10 +52,10 @@ ...@@ -50,10 +52,10 @@
*/ */
#define no_tf_log(fmt, ...) \ #define no_tf_log(fmt, ...) \
do { \ do { \
if (0) { \ if (false) { \
tf_log(fmt, ##__VA_ARGS__); \ tf_log(fmt, ##__VA_ARGS__); \
} \ } \
} while (0) } while (false)
#if LOG_LEVEL >= LOG_LEVEL_NOTICE #if LOG_LEVEL >= LOG_LEVEL_NOTICE
# define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__) # define NOTICE(...) tf_log(LOG_MARKER_NOTICE __VA_ARGS__)
......
/* /*
* 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 * SPDX-License-Identifier: BSD-3-Clause
*/ */
#include <assert.h>
#include <debug.h> #include <debug.h>
#include <platform.h>
/* Allow platforms to override the log prefix string */ /* Allow platforms to override the log prefix string */
#pragma weak plat_log_get_prefix #pragma weak plat_log_get_prefix
static const char *prefix_str[] = { static const char *plat_prefix_str[] = {
"ERROR: ", "NOTICE: ", "WARNING: ", "INFO: ", "VERBOSE: "}; "ERROR: ", "NOTICE: ", "WARNING: ", "INFO: ", "VERBOSE: "};
const char *plat_log_get_prefix(unsigned int log_level) const char *plat_log_get_prefix(unsigned int log_level)
{ {
if (log_level < LOG_LEVEL_ERROR) unsigned int level;
log_level = LOG_LEVEL_ERROR;
else if (log_level > LOG_LEVEL_VERBOSE)
log_level = LOG_LEVEL_VERBOSE;
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];
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment