Browse Source

Fix MISRA defects in log helpers

No functional changes.

Change-Id: I850f08718abb69d5d58856b0e3de036266d8c2f4
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
pull/1546/head
Antonio Nino Diaz 6 years ago
parent
commit
5a22e461b5
  1. 17
      common/tf_log.c
  2. 18
      include/common/debug.h
  3. 21
      plat/common/plat_log_common.c

17
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;
}

18
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__)

21
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];
}

Loading…
Cancel
Save