2023-11-27 12:37:31

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write()

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) <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Cc: Ivan Kokshaysky <[email protected]>
Cc: Matt Turner <[email protected]>
Cc: [email protected]
---

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


2023-11-28 13:26:52

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 3/5] tty: srmcons: use 'count' directly in srmcons_do_write()

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) <[email protected]>
> Reviewed-by: Richard Henderson <[email protected]>
> Cc: Ivan Kokshaysky <[email protected]>
> Cc: Matt Turner <[email protected]>
> Cc: [email protected]
> ---
>
> 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 <[email protected]>

--
i.