[PATCH 14/27] console: Consolidate DEBUG_LL and CONSOLE_* puts() implementations

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Similar to previous commit, consolidate DEBUG_LL and CONSOLE_* puts()
implementations by putting them into a shared macro.

Signed-off-by: Andrey Smirnov <andrew.smirnov@xxxxxxxxx>
---
 include/debug_ll.h | 23 +++++++++++++++++++----
 lib/console.c      | 13 ++++++-------
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/include/debug_ll.h b/include/debug_ll.h
index 4032ced95..4dcbd0434 100644
--- a/include/debug_ll.h
+++ b/include/debug_ll.h
@@ -54,6 +54,24 @@
 		__n;				\
 	})
 
+/**
+ * __do_puts - Macro implementing puts()
+ *
+ * @__putc:	Single argument or a macro that implements putc()
+ * @___s:	String to print
+ *
+ * Internal macro used to implement puts_ll() and __console_puts()
+ */
+#define __do_puts(__putc, ___s)			\
+	({					\
+		const char *__s = (___s);	\
+		int __n = 0;			\
+						\
+		while (*__s)			\
+			__n += __putc(*__s++);	\
+		__n;				\
+	})
+
 #if defined (CONFIG_DEBUG_LL)
 
 static inline void __putc_ll(char value)
@@ -80,10 +98,7 @@ static inline int putc_ll(char value);
  */
 static inline void puts_ll(const char * str)
 {
-	while (*str) {
-		putc_ll(*str);
-		str++;
-	}
+	__do_puts(putc_ll, str);
 }
 
 #else
diff --git a/lib/console.c b/lib/console.c
index f97deca97..91c446d6e 100644
--- a/lib/console.c
+++ b/lib/console.c
@@ -177,14 +177,13 @@ __weak void console_putc(unsigned int ch, char c)
  */
 int __console_puts(struct console_device *cdev, const char *str)
 {
-	int n = 0;
-
-	while (*str) {
-		n += __console_putc(cdev, *str);
-		str++;
-	}
+/*
+ * __do_puts expects a macro or a function of a single argument so we
+ * create this dummy adapter to work around that
+ */
+#define __CONSOLE_PUTC(__c)	__console_putc(cdev, __c)
 
-	return n;
+	return __do_puts(__CONSOLE_PUTC, str);
 }
 
 /**
-- 
2.17.0


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux