diff mbox series

[4/4] console: add console_tstc_check helper function for CONSOLE_MUX

Message ID 20201203102027.4.I810a6b37da2c8aa13ca2e20408a8d54b08e2ef32@changeid
State Superseded
Delegated to: Tom Rini
Headers show
Series console: remove #ifdef CONFIG when it is possible | expand

Commit Message

Patrick DELAUNAY Dec. 3, 2020, 9:20 a.m. UTC
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(-)

Comments

Simon Glass Dec. 12, 2020, 3:39 p.m. UTC | #1
Hi Patrick,

On Thu, 3 Dec 2020 at 02:20, Patrick Delaunay <patrick.delaunay@st.com> wrote:
>
> 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)

This is checking if we actually have a device, right? I think
has_tstcdev() would be better.

Also could you add a comment in the testcdev variable declaration as
to what this variable actually is for?

> +{
> +       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
>

Regards,
Simon
diff mbox series

Patch

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.