diff mbox series

[1/3] log: don't build the trace buffer when log is not ready

Message ID 20201106175339.30683-1-patrick.delaunay@st.com
State Superseded
Delegated to: Tom Rini
Headers show
Series [1/3] log: don't build the trace buffer when log is not ready | expand

Commit Message

Patrick DELAUNAY Nov. 6, 2020, 5:53 p.m. UTC
Update _log function to drop any traces when log is yet initialized:
vsnprintf is no more executed in this case.

This patch allows to reduce the cost for the dropped early debug trace.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
---

 common/log.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

Comments

Simon Glass Nov. 11, 2020, 2:32 p.m. UTC | #1
Hi Patrick,

On Fri, 6 Nov 2020 at 10:55, Patrick Delaunay <patrick.delaunay@st.com> wrote:
>
> Update _log function to drop any traces when log is yet initialized:
> vsnprintf is no more executed in this case.
>
> This patch allows to reduce the cost for the dropped early debug trace.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
>  common/log.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>

But this needs a test.
diff mbox series

Patch

diff --git a/common/log.c b/common/log.c
index 4b6f3fcd04..aadf533fb2 100644
--- a/common/log.c
+++ b/common/log.c
@@ -227,6 +227,9 @@  int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 	struct log_rec rec;
 	va_list args;
 
+	if (!gd)
+		return -ENOSYS;
+
 	/* Check for message continuation */
 	if (cat == LOGC_CONT)
 		cat = gd->logc_prev;
@@ -239,15 +242,15 @@  int _log(enum log_category_t cat, enum log_level_t level, const char *file,
 	rec.file = file;
 	rec.line = line;
 	rec.func = func;
+
+	if (!(gd->flags & GD_FLG_LOG_READY)) {
+		gd->log_drop_count++;
+		return -ENOSYS;
+	}
 	va_start(args, fmt);
 	vsnprintf(buf, sizeof(buf), fmt, args);
 	va_end(args);
 	rec.msg = buf;
-	if (!gd || !(gd->flags & GD_FLG_LOG_READY)) {
-		if (gd)
-			gd->log_drop_count++;
-		return -ENOSYS;
-	}
 	if (!log_dispatch(&rec)) {
 		gd->logc_prev = cat;
 		gd->logl_prev = level;