]> git.ipfire.org Git - thirdparty/u-boot.git/blobdiff - lib/trace.c
efi_loader: correct OpenProtocol()
[thirdparty/u-boot.git] / lib / trace.c
index 711e5b5836cbc2b5f98dab8bf634df0969ea6328..9956442fefe6b422fb5b048f9aa039a0acb44aad 100644 (file)
@@ -1,10 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2012 The Chromium OS Authors.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <mapmem.h>
 #include <trace.h>
 #include <asm/io.h>
 #include <asm/sections.h>
@@ -183,7 +183,8 @@ int trace_list_functions(void *buff, int buff_size, unsigned int *needed)
        /* Work out how must of the buffer we used */
        *needed = ptr - buff;
        if (ptr > end)
-               return -1;
+               return -ENOSPC;
+
        return 0;
 }
 
@@ -227,7 +228,8 @@ int trace_list_calls(void *buff, int buff_size, unsigned *needed)
        /* Work out how must of the buffer we used */
        *needed = ptr - buff;
        if (ptr > end)
-               return -1;
+               return -ENOSPC;
+
        return 0;
 }
 
@@ -294,7 +296,8 @@ int __attribute__((no_instrument_function)) trace_init(void *buff,
                trace_enabled = 0;
                hdr = map_sysmem(CONFIG_TRACE_EARLY_ADDR,
                                 CONFIG_TRACE_EARLY_SIZE);
-               end = (char *)&hdr->ftrace[hdr->ftrace_count];
+               end = (char *)&hdr->ftrace[min(hdr->ftrace_count,
+                                              hdr->ftrace_size)];
                used = end - (char *)hdr;
                printf("trace: copying %08lx bytes of early data from %x to %08lx\n",
                       used, CONFIG_TRACE_EARLY_ADDR,
@@ -302,7 +305,7 @@ int __attribute__((no_instrument_function)) trace_init(void *buff,
                memcpy(buff, hdr, used);
 #else
                puts("trace: already enabled\n");
-               return -1;
+               return -EALREADY;
 #endif
        }
        hdr = (struct trace_hdr *)buff;
@@ -310,7 +313,7 @@ int __attribute__((no_instrument_function)) trace_init(void *buff,
        if (needed > buff_size) {
                printf("trace: buffer size %zd bytes: at least %zd needed\n",
                       buff_size, needed);
-               return -1;
+               return -ENOSPC;
        }
 
        if (was_disabled)
@@ -327,6 +330,7 @@ int __attribute__((no_instrument_function)) trace_init(void *buff,
        hdr->depth_limit = 15;
        trace_enabled = 1;
        trace_inited = 1;
+
        return 0;
 }
 
@@ -346,7 +350,7 @@ int __attribute__((no_instrument_function)) trace_early_init(void)
        if (needed > buff_size) {
                printf("trace: buffer size is %zd bytes, at least %zd needed\n",
                       buff_size, needed);
-               return -1;
+               return -ENOSPC;
        }
 
        memset(hdr, '\0', needed);
@@ -361,6 +365,7 @@ int __attribute__((no_instrument_function)) trace_early_init(void)
        printf("trace: early enable at %08x\n", CONFIG_TRACE_EARLY_ADDR);
 
        trace_enabled = 1;
+
        return 0;
 }
 #endif