U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] log: Add helpers for calling log_msg_ret() et al
@ 2025-03-19 11:49 Simon Glass
  2025-03-19 12:04 ` Quentin Schulz
  0 siblings, 1 reply; 15+ messages in thread
From: Simon Glass @ 2025-03-19 11:49 UTC (permalink / raw)
  To: U-Boot Mailing List; +Cc: Simon Glass, Quentin Schulz, Tom Rini

Logging of function return-values is used very frequently in U-Boot now.
Add a few helper macros to make it less verbose to use.

It turns out that the log_ret() variants are not so useful, since it is
not obviously where the error is coming from. So only the log_msg_ret()
variants are worthy of these macros.

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

 include/log.h | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/include/log.h b/include/log.h
index 4f6d6a2c2cf..bdda7af570c 100644
--- a/include/log.h
+++ b/include/log.h
@@ -380,6 +380,32 @@ void __assert_fail(const char *assertion, const char *file, unsigned int line,
 #define log_msg_retz(_msg, _ret) ((void)(_msg), _ret)
 #endif
 
+/*
+ * LOGR() - helper macro for calling a function and logging error returns
+ *
+ * Logs if the function returns a negative value
+ *
+ * Usage:   LOGR("abc", my_function(...));
+ */
+#define LOGR(_msg, _expr)	do {		\
+	int _ret = _expr;			\
+	if (_ret < 0)				\
+		return log_msg_ret(_msg, _ret);	\
+	} while (0)
+
+/*
+ * LOGZ() - helper macro for calling a function and logging error returns
+ *
+ * Logs if the function returns a non-zero value
+ *
+ * Usage:   LOGZ("abc", my_function(...));
+ */
+#define LOGZ(_msg, _expr)	do {		\
+	int _ret = _expr;			\
+	if (_ret)				\
+		return log_msg_retz(_msg, _ret);	\
+	} while (0)
+
 /** * enum log_rec_flags - Flags for a log record */
 enum log_rec_flags {
 	/** @LOGRECF_FORCE_DEBUG: Force output of debug record */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2025-04-03 18:06 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-19 11:49 [PATCH] log: Add helpers for calling log_msg_ret() et al Simon Glass
2025-03-19 12:04 ` Quentin Schulz
2025-03-19 15:03   ` Simon Glass
2025-03-19 15:31     ` Quentin Schulz
2025-03-20  3:26       ` Simon Glass
2025-03-25 10:20         ` Quentin Schulz
2025-03-26 16:46           ` Simon Glass
2025-03-27 23:49             ` Tom Rini
2025-03-28 10:44               ` Simon Glass
2025-03-30 14:45                 ` Tom Rini
2025-04-01 15:48                   ` Simon Glass
2025-04-01 17:19                     ` Tom Rini
2025-04-03 17:57                       ` Simon Glass
2025-04-03 18:03                         ` Quentin Schulz
2025-04-03 18:05                           ` Simon Glass

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox