diff mbox series

[2/5] log: make debug_cond() function like

Message ID 20210104070256.260002-3-xypron.glpk@gmx.de
State Accepted
Commit 5176365a6bdadd25afdf293eada911443466931d
Delegated to: Tom Rini
Headers show
Series log: convert pr_*() to logging | expand

Commit Message

Heinrich Schuchardt Jan. 4, 2021, 7:02 a.m. UTC
Change debug_cond() such that it can be used instead of a function like
debug().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 include/log.h | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

--
2.29.2

Comments

Simon Glass Jan. 7, 2021, 12:36 p.m. UTC | #1
On Mon, 4 Jan 2021 at 00:03, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Change debug_cond() such that it can be used instead of a function like
> debug().
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  include/log.h | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Jan. 18, 2021, 1:02 p.m. UTC | #2
On Mon, Jan 04, 2021 at 08:02:53AM +0100, Heinrich Schuchardt wrote:

> Change debug_cond() such that it can be used instead of a function like
> debug().
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/include/log.h b/include/log.h
index 29f18a82dc..34cea802a1 100644
--- a/include/log.h
+++ b/include/log.h
@@ -217,10 +217,9 @@  static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
 #if !_DEBUG && CONFIG_IS_ENABLED(LOG)

 #define debug_cond(cond, fmt, args...)			\
-	do {						\
-		if (1)					\
-			log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \
-	} while (0)
+({							\
+	log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args);	\
+})

 #else /* _DEBUG */

@@ -229,11 +228,11 @@  static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
  * computed by a preprocessor in the best case, allowing for the best
  * optimization.
  */
-#define debug_cond(cond, fmt, args...)			\
-	do {						\
-		if (cond)				\
-			printf(pr_fmt(fmt), ##args);	\
-	} while (0)
+#define debug_cond(cond, fmt, args...)		\
+({						\
+	if (cond)				\
+		printf(pr_fmt(fmt), ##args);	\
+})

 #endif /* _DEBUG */