Message ID | 20201203102027.4.I810a6b37da2c8aa13ca2e20408a8d54b08e2ef32@changeid |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
Series | console: remove #ifdef CONFIG when it is possible | expand |
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 --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.
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(-)