diff mbox series

[v2,6/9] console: remove duplicated test on gd value

Message ID 20201127102100.11721-5-patrick.delaunay@st.com
State Accepted
Commit 93cdb52b2a06bf5fb2ea02db28a95b5524ab1e6e
Delegated to: Tom Rini
Headers show
Series log: don't build the trace buffer when log is not ready | expand

Commit Message

Patrick DELAUNAY Nov. 27, 2020, 10:20 a.m. UTC
Reorder test on gd value and remove the duplicated test (!gd)
in putc and puts function.

This patch is a preliminary step for rework of this function.

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

Changes in v2:
- update gd test in console function puts and putc (cosmetic)

 common/console.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Sean Anderson Nov. 27, 2020, 3:05 p.m. UTC | #1
On 11/27/20 5:20 AM, Patrick Delaunay wrote:
> Reorder test on gd value and remove the duplicated test (!gd)
> in putc and puts function.
> 
> This patch is a preliminary step for rework of this function.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
> 
> Changes in v2:
> - update gd test in console function puts and putc (cosmetic)
> 
>   common/console.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/common/console.c b/common/console.c
> index 3348436da6..70579af042 100644
> --- a/common/console.c
> +++ b/common/console.c
> @@ -517,22 +517,22 @@ static inline void print_pre_console_buffer(int flushpoint) {}
>   
>   void putc(const char c)
>   {
> +	if (!gd)
> +		return;
>   #ifdef CONFIG_SANDBOX
>   	/* sandbox can send characters to stdout before it has a console */
> -	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
> +	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
>   		os_putc(c);
>   		return;
>   	}
>   #endif
>   #ifdef CONFIG_DEBUG_UART
>   	/* if we don't have a console yet, use the debug UART */
> -	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
> +	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
>   		printch(c);
>   		return;
>   	}
>   #endif
> -	if (!gd)
> -		return;
>   #ifdef CONFIG_CONSOLE_RECORD
>   	if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
>   		membuff_putbyte((struct membuff *)&gd->console_out, c);
> @@ -565,15 +565,17 @@ void putc(const char c)
>   
>   void puts(const char *s)
>   {
> +	if (!gd)
> +		return;
>   #ifdef CONFIG_SANDBOX
>   	/* sandbox can send characters to stdout before it has a console */
> -	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
> +	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
>   		os_puts(s);
>   		return;
>   	}
>   #endif
>   #ifdef CONFIG_DEBUG_UART
> -	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
> +	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
>   		while (*s) {
>   			int ch = *s++;
>   
> @@ -582,8 +584,6 @@ void puts(const char *s)
>   		return;
>   	}
>   #endif
> -	if (!gd)
> -		return;
>   #ifdef CONFIG_CONSOLE_RECORD
>   	if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
>   		membuff_put((struct membuff *)&gd->console_out, s, strlen(s));
> 

Reviewed-by: Sean Anderson <seanga2@gmail.com>
Simon Glass Nov. 30, 2020, 8:12 p.m. UTC | #2
On Fri, 27 Nov 2020 at 03:21, Patrick Delaunay <patrick.delaunay@st.com> wrote:
>
> Reorder test on gd value and remove the duplicated test (!gd)
> in putc and puts function.
>
> This patch is a preliminary step for rework of this function.
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> ---
>
> Changes in v2:
> - update gd test in console function puts and putc (cosmetic)
>
>  common/console.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Jan. 16, 2021, 4:21 p.m. UTC | #3
On Fri, Nov 27, 2020 at 11:20:56AM +0100, Patrick Delaunay wrote:

> Reorder test on gd value and remove the duplicated test (!gd)
> in putc and puts function.
> 
> This patch is a preliminary step for rework of this function.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
> Reviewed-by: Sean Anderson <seanga2@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/console.c b/common/console.c
index 3348436da6..70579af042 100644
--- a/common/console.c
+++ b/common/console.c
@@ -517,22 +517,22 @@  static inline void print_pre_console_buffer(int flushpoint) {}
 
 void putc(const char c)
 {
+	if (!gd)
+		return;
 #ifdef CONFIG_SANDBOX
 	/* sandbox can send characters to stdout before it has a console */
-	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
+	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
 		os_putc(c);
 		return;
 	}
 #endif
 #ifdef CONFIG_DEBUG_UART
 	/* if we don't have a console yet, use the debug UART */
-	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
+	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
 		printch(c);
 		return;
 	}
 #endif
-	if (!gd)
-		return;
 #ifdef CONFIG_CONSOLE_RECORD
 	if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
 		membuff_putbyte((struct membuff *)&gd->console_out, c);
@@ -565,15 +565,17 @@  void putc(const char c)
 
 void puts(const char *s)
 {
+	if (!gd)
+		return;
 #ifdef CONFIG_SANDBOX
 	/* sandbox can send characters to stdout before it has a console */
-	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
+	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
 		os_puts(s);
 		return;
 	}
 #endif
 #ifdef CONFIG_DEBUG_UART
-	if (!gd || !(gd->flags & GD_FLG_SERIAL_READY)) {
+	if (!(gd->flags & GD_FLG_SERIAL_READY)) {
 		while (*s) {
 			int ch = *s++;
 
@@ -582,8 +584,6 @@  void puts(const char *s)
 		return;
 	}
 #endif
-	if (!gd)
-		return;
 #ifdef CONFIG_CONSOLE_RECORD
 	if ((gd->flags & GD_FLG_RECORD) && gd->console_out.start)
 		membuff_put((struct membuff *)&gd->console_out, s, strlen(s));