linux-alpha.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/5] tty: srmcons: make srmcons_do_write() return void
       [not found] <20231127123713.14504-1-jirislaby@kernel.org>
@ 2023-11-27 12:37 ` Jiri Slaby (SUSE)
  2023-11-28 13:25   ` Ilpo Järvinen
  2023-11-27 12:37 ` [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write() Jiri Slaby (SUSE)
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-11-27 12:37 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

The return value of srmcons_do_write() is ignored as all characters are
pushed. So make srmcons_do_write() to return void.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---

Notes:
    [v2] reordered so that it makes sense

 arch/alpha/kernel/srmcons.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index b68c5af083cd..de896fa9829e 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -88,7 +88,7 @@ srmcons_receive_chars(struct timer_list *t)
 }
 
 /* called with callback_lock held */
-static int
+static void
 srmcons_do_write(struct tty_port *port, const char *buf, int count)
 {
 	static char str_cr[1] = "\r";
@@ -125,7 +125,6 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
 				need_cr = 0;
 		}
 	}
-	return count;
 }
 
 static ssize_t
-- 
2.42.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write()
       [not found] <20231127123713.14504-1-jirislaby@kernel.org>
  2023-11-27 12:37 ` [PATCH 2/5] tty: srmcons: make srmcons_do_write() return void Jiri Slaby (SUSE)
@ 2023-11-27 12:37 ` Jiri Slaby (SUSE)
  2023-11-28 13:26   ` Ilpo Järvinen
  2023-11-27 12:37 ` [PATCH 4/5] tty: srmcons: switch need_cr to bool Jiri Slaby (SUSE)
  2023-11-27 12:37 ` [PATCH 5/5] tty: srmcons: remove 'str_cr' and use string directly Jiri Slaby (SUSE)
  3 siblings, 1 reply; 8+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-11-27 12:37 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

Similarly to 'buf' in the previous patch, there is no need to have a
separate counter ('remaining') in srmcons_do_write(). 'count' can be
used directly which simplifies the code a bit.

Note that the type of the current count ('c') is changed from 'long' to
'size_t' so that:
1) it is prepared for the upcoming change of 'count's type, and
2) is unsigned.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---

Notes:
    [v2] reordered so that it makes sense

 arch/alpha/kernel/srmcons.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index de896fa9829e..32bc098de7da 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -92,24 +92,24 @@ static void
 srmcons_do_write(struct tty_port *port, const char *buf, int count)
 {
 	static char str_cr[1] = "\r";
-	long c, remaining = count;
+	size_t c;
 	srmcons_result result;
 	int need_cr;
 
-	while (remaining > 0) {
+	while (count > 0) {
 		need_cr = 0;
 		/* 
 		 * Break it up into reasonable size chunks to allow a chance
 		 * for input to get in
 		 */
-		for (c = 0; c < min_t(long, 128L, remaining) && !need_cr; c++)
+		for (c = 0; c < min_t(size_t, 128U, count) && !need_cr; c++)
 			if (buf[c] == '\n')
 				need_cr = 1;
 		
 		while (c > 0) {
 			result.as_long = callback_puts(0, buf, c);
 			c -= result.bits.c;
-			remaining -= result.bits.c;
+			count -= result.bits.c;
 			buf += result.bits.c;
 
 			/*
-- 
2.42.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/5] tty: srmcons: switch need_cr to bool
       [not found] <20231127123713.14504-1-jirislaby@kernel.org>
  2023-11-27 12:37 ` [PATCH 2/5] tty: srmcons: make srmcons_do_write() return void Jiri Slaby (SUSE)
  2023-11-27 12:37 ` [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write() Jiri Slaby (SUSE)
@ 2023-11-27 12:37 ` Jiri Slaby (SUSE)
  2023-11-28 13:25   ` Ilpo Järvinen
  2023-11-27 12:37 ` [PATCH 5/5] tty: srmcons: remove 'str_cr' and use string directly Jiri Slaby (SUSE)
  3 siblings, 1 reply; 8+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-11-27 12:37 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

'need_cr' is a flag, so type it properly to be a 'bool'. Move the
declaration into the loop too. That ensures the variable is initialized
properly even if the code was moved somehow.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---
 arch/alpha/kernel/srmcons.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index 32bc098de7da..c6b821afbfd3 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -94,17 +94,16 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
 	static char str_cr[1] = "\r";
 	size_t c;
 	srmcons_result result;
-	int need_cr;
 
 	while (count > 0) {
-		need_cr = 0;
+		bool need_cr = false;
 		/* 
 		 * Break it up into reasonable size chunks to allow a chance
 		 * for input to get in
 		 */
 		for (c = 0; c < min_t(size_t, 128U, count) && !need_cr; c++)
 			if (buf[c] == '\n')
-				need_cr = 1;
+				need_cr = true;
 		
 		while (c > 0) {
 			result.as_long = callback_puts(0, buf, c);
@@ -122,7 +121,7 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
 		while (need_cr) {
 			result.as_long = callback_puts(0, str_cr, 1);
 			if (result.bits.c > 0)
-				need_cr = 0;
+				need_cr = false;
 		}
 	}
 }
-- 
2.42.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/5] tty: srmcons: remove 'str_cr' and use string directly
       [not found] <20231127123713.14504-1-jirislaby@kernel.org>
                   ` (2 preceding siblings ...)
  2023-11-27 12:37 ` [PATCH 4/5] tty: srmcons: switch need_cr to bool Jiri Slaby (SUSE)
@ 2023-11-27 12:37 ` Jiri Slaby (SUSE)
  2023-11-28 13:26   ` Ilpo Järvinen
  3 siblings, 1 reply; 8+ messages in thread
From: Jiri Slaby (SUSE) @ 2023-11-27 12:37 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby (SUSE), Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

'str_cr' contains a single character: \r. There is no need to declare it
as array. Instead, pass the character (as a string) to callback_puts()
directly. This ensures the string is in proper .rodata (const) section
and makes the code more obvious.

Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: linux-alpha@vger.kernel.org
---

Notes:
    [v2]
      pass "\r" directly to callback_puts() as Richard suggests
      spell correct \r in the commit log as Ilpo noticed

 arch/alpha/kernel/srmcons.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index c6b821afbfd3..42deea53beab 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -91,7 +91,6 @@ srmcons_receive_chars(struct timer_list *t)
 static void
 srmcons_do_write(struct tty_port *port, const char *buf, int count)
 {
-	static char str_cr[1] = "\r";
 	size_t c;
 	srmcons_result result;
 
@@ -119,7 +118,7 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
 		}
 
 		while (need_cr) {
-			result.as_long = callback_puts(0, str_cr, 1);
+			result.as_long = callback_puts(0, "\r", 1);
 			if (result.bits.c > 0)
 				need_cr = false;
 		}
-- 
2.42.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/5] tty: srmcons: make srmcons_do_write() return void
  2023-11-27 12:37 ` [PATCH 2/5] tty: srmcons: make srmcons_do_write() return void Jiri Slaby (SUSE)
@ 2023-11-28 13:25   ` Ilpo Järvinen
  0 siblings, 0 replies; 8+ messages in thread
From: Ilpo Järvinen @ 2023-11-28 13:25 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]

On Mon, 27 Nov 2023, Jiri Slaby (SUSE) wrote:

> The return value of srmcons_do_write() is ignored as all characters are
> pushed. So make srmcons_do_write() to return void.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: linux-alpha@vger.kernel.org
> ---
> 
> Notes:
>     [v2] reordered so that it makes sense
> 
>  arch/alpha/kernel/srmcons.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index b68c5af083cd..de896fa9829e 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -88,7 +88,7 @@ srmcons_receive_chars(struct timer_list *t)
>  }
>  
>  /* called with callback_lock held */
> -static int
> +static void
>  srmcons_do_write(struct tty_port *port, const char *buf, int count)
>  {
>  	static char str_cr[1] = "\r";
> @@ -125,7 +125,6 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
>  				need_cr = 0;
>  		}
>  	}
> -	return count;
>  }
>  
>  static ssize_t
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 4/5] tty: srmcons: switch need_cr to bool
  2023-11-27 12:37 ` [PATCH 4/5] tty: srmcons: switch need_cr to bool Jiri Slaby (SUSE)
@ 2023-11-28 13:25   ` Ilpo Järvinen
  0 siblings, 0 replies; 8+ messages in thread
From: Ilpo Järvinen @ 2023-11-28 13:25 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

[-- Attachment #1: Type: text/plain, Size: 1679 bytes --]

On Mon, 27 Nov 2023, Jiri Slaby (SUSE) wrote:

> 'need_cr' is a flag, so type it properly to be a 'bool'. Move the
> declaration into the loop too. That ensures the variable is initialized
> properly even if the code was moved somehow.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: linux-alpha@vger.kernel.org
> ---
>  arch/alpha/kernel/srmcons.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index 32bc098de7da..c6b821afbfd3 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -94,17 +94,16 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
>  	static char str_cr[1] = "\r";
>  	size_t c;
>  	srmcons_result result;
> -	int need_cr;
>  
>  	while (count > 0) {
> -		need_cr = 0;
> +		bool need_cr = false;
>  		/* 
>  		 * Break it up into reasonable size chunks to allow a chance
>  		 * for input to get in
>  		 */
>  		for (c = 0; c < min_t(size_t, 128U, count) && !need_cr; c++)
>  			if (buf[c] == '\n')
> -				need_cr = 1;
> +				need_cr = true;
>  		
>  		while (c > 0) {
>  			result.as_long = callback_puts(0, buf, c);
> @@ -122,7 +121,7 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
>  		while (need_cr) {
>  			result.as_long = callback_puts(0, str_cr, 1);
>  			if (result.bits.c > 0)
> -				need_cr = 0;
> +				need_cr = false;
>  		}
>  	}
>  }
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write()
  2023-11-27 12:37 ` [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write() Jiri Slaby (SUSE)
@ 2023-11-28 13:26   ` Ilpo Järvinen
  0 siblings, 0 replies; 8+ messages in thread
From: Ilpo Järvinen @ 2023-11-28 13:26 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

[-- Attachment #1: Type: text/plain, Size: 1894 bytes --]

On Mon, 27 Nov 2023, Jiri Slaby (SUSE) wrote:

> Similarly to 'buf' in the previous patch, there is no need to have a
> separate counter ('remaining') in srmcons_do_write(). 'count' can be
> used directly which simplifies the code a bit.
> 
> Note that the type of the current count ('c') is changed from 'long' to
> 'size_t' so that:
> 1) it is prepared for the upcoming change of 'count's type, and
> 2) is unsigned.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: linux-alpha@vger.kernel.org
> ---
> 
> Notes:
>     [v2] reordered so that it makes sense
> 
>  arch/alpha/kernel/srmcons.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index de896fa9829e..32bc098de7da 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -92,24 +92,24 @@ static void
>  srmcons_do_write(struct tty_port *port, const char *buf, int count)
>  {
>  	static char str_cr[1] = "\r";
> -	long c, remaining = count;
> +	size_t c;
>  	srmcons_result result;
>  	int need_cr;
>  
> -	while (remaining > 0) {
> +	while (count > 0) {
>  		need_cr = 0;
>  		/* 
>  		 * Break it up into reasonable size chunks to allow a chance
>  		 * for input to get in
>  		 */
> -		for (c = 0; c < min_t(long, 128L, remaining) && !need_cr; c++)
> +		for (c = 0; c < min_t(size_t, 128U, count) && !need_cr; c++)
>  			if (buf[c] == '\n')
>  				need_cr = 1;
>  		
>  		while (c > 0) {
>  			result.as_long = callback_puts(0, buf, c);
>  			c -= result.bits.c;
> -			remaining -= result.bits.c;
> +			count -= result.bits.c;
>  			buf += result.bits.c;
>  
>  			/*
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5/5] tty: srmcons: remove 'str_cr' and use string directly
  2023-11-27 12:37 ` [PATCH 5/5] tty: srmcons: remove 'str_cr' and use string directly Jiri Slaby (SUSE)
@ 2023-11-28 13:26   ` Ilpo Järvinen
  0 siblings, 0 replies; 8+ messages in thread
From: Ilpo Järvinen @ 2023-11-28 13:26 UTC (permalink / raw)
  To: Jiri Slaby (SUSE)
  Cc: gregkh, linux-serial, linux-kernel, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, linux-alpha

[-- Attachment #1: Type: text/plain, Size: 1569 bytes --]

On Mon, 27 Nov 2023, Jiri Slaby (SUSE) wrote:

> 'str_cr' contains a single character: \r. There is no need to declare it
> as array. Instead, pass the character (as a string) to callback_puts()
> directly. This ensures the string is in proper .rodata (const) section
> and makes the code more obvious.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: Richard Henderson <richard.henderson@linaro.org>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: linux-alpha@vger.kernel.org
> ---
> 
> Notes:
>     [v2]
>       pass "\r" directly to callback_puts() as Richard suggests
>       spell correct \r in the commit log as Ilpo noticed
> 
>  arch/alpha/kernel/srmcons.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index c6b821afbfd3..42deea53beab 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -91,7 +91,6 @@ srmcons_receive_chars(struct timer_list *t)
>  static void
>  srmcons_do_write(struct tty_port *port, const char *buf, int count)
>  {
> -	static char str_cr[1] = "\r";
>  	size_t c;
>  	srmcons_result result;
>  
> @@ -119,7 +118,7 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
>  		}
>  
>  		while (need_cr) {
> -			result.as_long = callback_puts(0, str_cr, 1);
> +			result.as_long = callback_puts(0, "\r", 1);
>  			if (result.bits.c > 0)
>  				need_cr = false;
>  		}
> 

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

-- 
 i.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-28 13:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20231127123713.14504-1-jirislaby@kernel.org>
2023-11-27 12:37 ` [PATCH 2/5] tty: srmcons: make srmcons_do_write() return void Jiri Slaby (SUSE)
2023-11-28 13:25   ` Ilpo Järvinen
2023-11-27 12:37 ` [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write() Jiri Slaby (SUSE)
2023-11-28 13:26   ` Ilpo Järvinen
2023-11-27 12:37 ` [PATCH 4/5] tty: srmcons: switch need_cr to bool Jiri Slaby (SUSE)
2023-11-28 13:25   ` Ilpo Järvinen
2023-11-27 12:37 ` [PATCH 5/5] tty: srmcons: remove 'str_cr' and use string directly Jiri Slaby (SUSE)
2023-11-28 13:26   ` Ilpo Järvinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).