All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick Delaunay <patrick.delaunay@st.com>
To: u-boot@lists.denx.de
Subject: [PATCH 4/4] console: add console_tstc_check helper function for CONSOLE_MUX
Date: Thu, 3 Dec 2020 10:20:31 +0100	[thread overview]
Message-ID: <20201203102027.4.I810a6b37da2c8aa13ca2e20408a8d54b08e2ef32@changeid> (raw)
In-Reply-To: <20201203092032.8124-1-patrick.delaunay@st.com>

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.delaunay@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

  parent reply	other threads:[~2020-12-03  9:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03  9:20 [PATCH 0/4] console: remove #ifdef CONFIG when it is possible Patrick Delaunay
2020-12-03  9:20 ` [PATCH 1/4] " Patrick Delaunay
2020-12-12 15:39   ` Simon Glass
2020-12-03  9:20 ` [PATCH 2/4] console: add function console_devices_set Patrick Delaunay
2020-12-12 15:39   ` Simon Glass
2020-12-03  9:20 ` [PATCH 3/4] console: remove #ifdef CONFIG_CONSOLE_RECORD Patrick Delaunay
2020-12-12 15:39   ` Simon Glass
2020-12-15 14:47     ` Patrick DELAUNAY
2020-12-03  9:20 ` Patrick Delaunay [this message]
2020-12-12 15:39   ` [PATCH 4/4] console: add console_tstc_check helper function for CONSOLE_MUX Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201203102027.4.I810a6b37da2c8aa13ca2e20408a8d54b08e2ef32@changeid \
    --to=patrick.delaunay@st.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.