Add the helper function console_tstc_check() and replace the test
#if CONFIG_IS_ENABLED(CONSOLE_MUX) to a simple if to respect the
U-Boot coding rule.

No functional change.

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

 common/console.c | 36 ++++++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/common/console.c b/common/console.c
index 0b864444bb..c570cd88cf 100644
--- a/common/console.c
+++ b/common/console.c
@@ -248,6 +248,12 @@ static int console_getc(int file)
        return ret;
 }
 
+/*  Upper layer may have already called tstc(): check the saved result */
+static bool console_tstc_check(void)
+{
+       return !!tstcdev;
+}
+
 static int console_tstc(int file)
 {
        int i, ret;
@@ -340,6 +346,11 @@ static inline int console_getc(int file)
        return stdio_devices[file]->getc(stdio_devices[file]);
 }
 
+static bool console_tstc_check(void)
+{
+       return false;
+}
+
 static inline int console_tstc(int file)
 {
        return stdio_devices[file]->tstc(stdio_devices[file]);
@@ -397,18 +408,19 @@ int fgetc(int file)
                 */
                for (;;) {
                        WATCHDOG_RESET();
-#if CONFIG_IS_ENABLED(CONSOLE_MUX)
-                       /*
-                        * Upper layer may have already called tstc() so
-                        * check for that first.
-                        */
-                       if (tstcdev != NULL)
-                               return console_getc(file);
-                       console_tstc(file);
-#else
-                       if (console_tstc(file))
-                               return console_getc(file);
-#endif
+                       if (CONFIG_IS_ENABLED(CONSOLE_MUX)) {
+                               /*
+                                * Upper layer may have already called tstc() so
+                                * check for that first.
+                                */
+                               if (console_tstc_check())
+                                       return console_getc(file);
+                               console_tstc(file);
+                       } else {
+                               if (console_tstc(file))
+                                       return console_getc(file);
+                       }
+
                        /*
                         * If the watchdog must be rate-limited then it should
                         * already be handled in board-specific code.
-- 
2.17.1

Reply via email to