Merge tag 'uniphier-v2020.07' of https://gitlab.denx.de/u-boot/custodians/u-boot...
[oweals/u-boot.git] / common / log.c
index 66d5e3ebf85b773cfb5807b70a9ce4bf387425ce..c5b9b489ca3775f2376a72fa8747e60b5cee1aa3 100644 (file)
@@ -1,10 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Logging support
  *
  * Copyright (c) 2017 Google, Inc
  * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -39,12 +38,16 @@ static const char *log_level_name[LOGL_COUNT] = {
 
 const char *log_get_cat_name(enum log_category_t cat)
 {
-       if (cat > LOGC_COUNT)
-               return "invalid";
+       const char *name;
+
+       if (cat < 0 || cat >= LOGC_COUNT)
+               return "<invalid>";
        if (cat >= LOGC_NONE)
                return log_cat_name[cat - LOGC_NONE];
 
-       return uclass_get_name((enum uclass_id)cat);
+       name = uclass_get_name((enum uclass_id)cat);
+
+       return name ? name : "<missing>";
 }
 
 enum log_category_t log_get_cat_by_name(const char *name)
@@ -230,7 +233,7 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[],
        ldev = log_device_find_by_name(drv_name);
        if (!ldev)
                return -ENOENT;
-       filt = (struct log_filter *)calloc(1, sizeof(*filt));
+       filt = calloc(1, sizeof(*filt));
        if (!filt)
                return -ENOMEM;
 
@@ -312,7 +315,8 @@ int log_init(void)
                drv++;
        }
        gd->flags |= GD_FLG_LOG_READY;
-       gd->default_log_level = LOGL_INFO;
+       if (!gd->default_log_level)
+               gd->default_log_level = CONFIG_LOG_DEFAULT_LEVEL;
        gd->log_fmt = LOGF_DEFAULT;
 
        return 0;