mbox series

[00/36] tty: type unifications -- part I.

Message ID 20230810091510.13006-1-jirislaby@kernel.org
Headers show
Series tty: type unifications -- part I. | expand

Message

Jiri Slaby Aug. 10, 2023, 9:14 a.m. UTC
Currently, the tty layer ops and functions use various types for same
things:
* characters and flags: unsigned char, char are used on a random basis,
* counts: int, unsigned int, size_t are used, again more-or-less
  randomly.

This makes it rather hard to remember where each type is required and it
also makes the code harder to follow. Also the code has to do min_t() on
many places simply because the variables hold the same kind of data, but
of different type.

This is the first part of the series to unify the types:
* make characters and flags 'u8'. This is what the hardware expects and
  what feeds the tty layer with. Since we compile with -funsigned-char,
  char and unsigned char are the same types on all platforms. So there
  is no actual change in type.
* make sizes/counts 'size_t'. This is what comes from the VFS layer and
  some tty functions already operate on this. So instead of using
  "shorter" (in term of bytes on 64bit) unsigned int, stick to size_t
  and promote it to most places.

More cleanup and spreading will be done in tty_buffer, n_tty, and
likely other places later.

Patches 1-8 are cleanups only. The rest (the real switch) depends on
those.

Jiri Slaby (SUSE) (36):
  tty: xtensa/iss: drop unneeded tty_operations hooks
  tty: ldisc: document that ldops are optional
  tty: remove dummy tty_ldisc_ops::poll() implementations
  tty: n_null: remove optional ldops
  tty: change tty_write_lock()'s ndelay parameter to bool
  tty: tty_port: rename 'disc' to 'ld'
  tty: drop tty_debug_wait_until_sent()
  tty: make tty_change_softcar() more understandable
  tty: make tty_port_client_operations operate with u8
  tty: make counts in tty_port_client_operations hooks size_t
  tty: switch receive_buf() counts to size_t
  tty: switch count in tty_ldisc_receive_buf() to size_t
  tty: can327: unify error paths in can327_ldisc_rx()
  tty: can327, move overflow test inside can327_ldisc_rx()'s loop
  tty: make tty_ldisc_ops::*buf*() hooks operate on size_t
  tty: use u8 for chars
  tty: use u8 for flags
  misc: ti-st: make st_recv() conforming to tty_ldisc_ops::receive_buf()
  tty: make char_buf_ptr()/flag_buf_ptr()'s offset unsigned
  tty: tty_buffer: make all offsets unsigned
  tty: don't pass write() to do_tty_write()
  tty: rename and de-inline do_tty_write()
  tty: use min() in iterate_tty_write()
  tty: use ssize_t for iterate_tty_read() returned type
  tty: switch size and count types in iterate_tty_read() to size_t
  tty: use min() for size computation in iterate_tty_read()
  tty: propagate u8 data to tty_operations::write()
  tty: propagate u8 data to tty_operations::put_char()
  tty: make tty_operations::write()'s count size_t
  tty: audit: unify to u8
  tty: ldops: unify to u8
  tty: hvc: convert counts to size_t
  tty: vcc: convert counts to size_t
  tty: gdm724x: convert counts to size_t
  tty: hso: simplify hso_serial_write()
  tty: rfcomm: convert counts to size_t

 arch/alpha/kernel/srmcons.c               |  5 +-
 arch/m68k/emu/nfcon.c                     |  8 +--
 arch/sparc/include/asm/vio.h              |  2 +-
 arch/um/drivers/line.c                    |  2 +-
 arch/um/drivers/line.h                    |  3 +-
 arch/xtensa/platforms/iss/console.c       | 27 +--------
 drivers/accessibility/speakup/spk_ttyio.c |  5 +-
 drivers/bluetooth/hci_ldisc.c             | 15 ++---
 drivers/char/ttyprintk.c                  |  5 +-
 drivers/input/serio/serport.c             |  8 +--
 drivers/ipack/devices/ipoctal.c           |  7 +--
 drivers/isdn/capi/capi.c                  |  8 +--
 drivers/misc/bcm-vk/bcm_vk_tty.c          |  5 +-
 drivers/misc/ti-st/st_core.c              | 11 ++--
 drivers/misc/ti-st/st_kim.c               |  6 +-
 drivers/mmc/core/sdio_uart.c              |  4 +-
 drivers/net/caif/caif_serial.c            |  2 +-
 drivers/net/can/can327.c                  | 39 ++++++-------
 drivers/net/can/slcan/slcan-core.c        |  5 +-
 drivers/net/hamradio/6pack.c              |  4 +-
 drivers/net/hamradio/mkiss.c              |  4 +-
 drivers/net/mctp/mctp-serial.c            |  5 +-
 drivers/net/ppp/ppp_async.c               | 26 +++------
 drivers/net/ppp/ppp_synctty.c             | 26 +++------
 drivers/net/slip/slip.c                   |  4 +-
 drivers/net/usb/hso.c                     | 20 +++----
 drivers/s390/char/con3215.c               |  6 +-
 drivers/s390/char/con3270.c               |  6 +-
 drivers/s390/char/sclp_tty.c              | 10 ++--
 drivers/s390/char/sclp_vt220.c            |  6 +-
 drivers/staging/gdm724x/gdm_tty.c         | 14 ++---
 drivers/staging/greybus/uart.c            |  3 +-
 drivers/tty/amiserial.c                   |  4 +-
 drivers/tty/ehv_bytechan.c                |  4 +-
 drivers/tty/goldfish.c                    |  7 +--
 drivers/tty/hvc/hvc_console.c             |  4 +-
 drivers/tty/hvc/hvcs.c                    | 10 ++--
 drivers/tty/hvc/hvsi.c                    | 14 ++---
 drivers/tty/ipwireless/hardware.c         |  2 +-
 drivers/tty/ipwireless/tty.c              |  4 +-
 drivers/tty/mips_ejtag_fdc.c              |  6 +-
 drivers/tty/moxa.c                        |  8 +--
 drivers/tty/mxser.c                       |  4 +-
 drivers/tty/n_gsm.c                       | 14 ++---
 drivers/tty/n_hdlc.c                      | 12 ++--
 drivers/tty/n_null.c                      | 25 +--------
 drivers/tty/n_tty.c                       | 59 ++++++++++----------
 drivers/tty/nozomi.c                      |  6 +-
 drivers/tty/pty.c                         |  2 +-
 drivers/tty/rpmsg_tty.c                   |  5 +-
 drivers/tty/serdev/serdev-ttyport.c       |  4 +-
 drivers/tty/serial/kgdb_nmi.c             |  3 +-
 drivers/tty/serial/serial_core.c          |  5 +-
 drivers/tty/synclink_gt.c                 | 13 ++---
 drivers/tty/tty.h                         |  8 +--
 drivers/tty/tty_audit.c                   |  6 +-
 drivers/tty/tty_buffer.c                  | 35 ++++++------
 drivers/tty/tty_io.c                      | 46 +++++++---------
 drivers/tty/tty_ioctl.c                   | 18 ++----
 drivers/tty/tty_port.c                    | 34 ++++++------
 drivers/tty/ttynull.c                     |  4 +-
 drivers/tty/vcc.c                         | 18 +++---
 drivers/tty/vt/selection.c                |  2 +-
 drivers/tty/vt/vt.c                       |  6 +-
 drivers/usb/class/cdc-acm.c               |  8 +--
 drivers/usb/gadget/function/u_serial.c    |  6 +-
 drivers/usb/host/xhci-dbgtty.c            |  7 +--
 drivers/usb/serial/usb-serial.c           |  5 +-
 include/linux/ti_wilink_st.h              |  2 +-
 include/linux/tty_buffer.h                | 18 +++---
 include/linux/tty_driver.h                |  9 ++-
 include/linux/tty_flip.h                  | 22 ++++----
 include/linux/tty_ldisc.h                 | 67 +++++++++++++++--------
 include/linux/tty_port.h                  |  7 ++-
 net/bluetooth/rfcomm/tty.c                |  9 +--
 net/nfc/nci/uart.c                        | 15 ++---
 sound/soc/codecs/cx20442.c                |  4 +-
 sound/soc/ti/ams-delta.c                  |  2 +-
 78 files changed, 381 insertions(+), 493 deletions(-)

Comments

Ilpo Järvinen Aug. 11, 2023, 10:28 a.m. UTC | #1
On Thu, 10 Aug 2023, Jiri Slaby (SUSE) wrote:

> This makes all those 'unsigned char's an explicit 'u8'. This is part of
> the continuing unification of chars and flags to be consistent u8.
> 
> This approaches tty_port_default_receive_buf(). Flags to be next.
> 
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: William Hubbs <w.d.hubbs@gmail.com>
> Cc: Chris Brannon <chris@the-brannons.com>
> Cc: Kirk Reiser <kirk@reisers.ca>
> Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
> Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Max Staudt <max@enpas.org>
> Cc: Wolfgang Grandegger <wg@grandegger.com>
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Dario Binacchi <dario.binacchi@amarulasolutions.com>
> Cc: Andreas Koensgen <ajk@comnets.uni-bremen.de>
> Cc: Jeremy Kerr <jk@codeconstruct.com.au>
> Cc: Matt Johnston <matt@codeconstruct.com.au>
> Cc: Liam Girdwood <lgirdwood@gmail.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Jaroslav Kysela <perex@perex.cz>
> Cc: Takashi Iwai <tiwai@suse.com>
> Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
> ---
>  drivers/accessibility/speakup/spk_ttyio.c |  5 ++--
>  drivers/input/serio/serport.c             |  5 ++--
>  drivers/misc/ti-st/st_core.c              |  2 +-
>  drivers/net/can/can327.c                  |  2 +-
>  drivers/net/can/slcan/slcan-core.c        |  5 ++--
>  drivers/net/hamradio/6pack.c              |  4 ++--
>  drivers/net/hamradio/mkiss.c              |  2 +-
>  drivers/net/mctp/mctp-serial.c            |  3 +--
>  drivers/net/ppp/ppp_async.c               |  8 +++----
>  drivers/net/ppp/ppp_synctty.c             | 11 ++++-----
>  drivers/net/slip/slip.c                   |  2 +-
>  drivers/tty/n_gsm.c                       |  2 +-
>  drivers/tty/n_hdlc.c                      |  2 +-
>  drivers/tty/n_tty.c                       | 28 +++++++++++------------
>  drivers/tty/tty.h                         |  2 +-
>  drivers/tty/tty_buffer.c                  | 21 ++++++++---------
>  include/linux/tty_buffer.h                |  4 ++--
>  include/linux/tty_flip.h                  | 22 ++++++++----------
>  include/linux/tty_ldisc.h                 | 18 +++++++--------
>  sound/soc/codecs/cx20442.c                |  4 ++--
>  sound/soc/ti/ams-delta.c                  |  2 +-
>  21 files changed, 73 insertions(+), 81 deletions(-)

> diff --git a/include/linux/tty_buffer.h b/include/linux/tty_buffer.h
> index 6ceb2789e6c8..6f2966b15093 100644
> --- a/include/linux/tty_buffer.h
> +++ b/include/linux/tty_buffer.h
> @@ -22,9 +22,9 @@ struct tty_buffer {
>  	unsigned long data[];
>  };
>  
> -static inline unsigned char *char_buf_ptr(struct tty_buffer *b, int ofs)
> +static inline u8 *char_buf_ptr(struct tty_buffer *b, int ofs)
>  {
> -	return ((unsigned char *)b->data) + ofs;
> +	return ((u8 *)b->data) + ofs;
>  }

Any particular reason why b->data is left unsigned long?
Max Staudt Aug. 11, 2023, 9:32 p.m. UTC | #2
Thank you for simplifying this!

Reviewed-by: Max Staudt <max@enpas.org>


In case you're re-sending this series, may I ask for one empty line between the final "return;" and the new label "uart_failure:"?
Max Staudt Aug. 11, 2023, 9:34 p.m. UTC | #3
Acked-by: Max Staudt <max@enpas.org>
Max Staudt Aug. 11, 2023, 9:34 p.m. UTC | #4
Acked-by: Max Staudt <max@enpas.org>
Max Staudt Aug. 11, 2023, 9:35 p.m. UTC | #5
Acked-by: Max Staudt <max@enpas.org>
Jiri Slaby Aug. 14, 2023, 6:35 a.m. UTC | #6
On 11. 08. 23, 12:28, Ilpo Järvinen wrote:
> On Thu, 10 Aug 2023, Jiri Slaby (SUSE) wrote:
> 
>> This makes all those 'unsigned char's an explicit 'u8'. This is part of
>> the continuing unification of chars and flags to be consistent u8.
>>
>> This approaches tty_port_default_receive_buf(). Flags to be next.
...>> diff --git a/include/linux/tty_buffer.h b/include/linux/tty_buffer.h
>> index 6ceb2789e6c8..6f2966b15093 100644
>> --- a/include/linux/tty_buffer.h
>> +++ b/include/linux/tty_buffer.h
>> @@ -22,9 +22,9 @@ struct tty_buffer {
>>   	unsigned long data[];
>>   };
>>   
>> -static inline unsigned char *char_buf_ptr(struct tty_buffer *b, int ofs)
>> +static inline u8 *char_buf_ptr(struct tty_buffer *b, int ofs)
>>   {
>> -	return ((unsigned char *)b->data) + ofs;
>> +	return ((u8 *)b->data) + ofs;
>>   }
> 
> Any particular reason why b->data is left unsigned long?

Nope :):
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=57c9d0cbe1ad69957a2092b66dc31dc1da4d1d4b

I am dumb not mentioning it in 00/36, see my e-mail there.

thanks,
Jiri Slaby Aug. 14, 2023, 6:59 a.m. UTC | #7
On 11. 08. 23, 12:26, Ilpo Järvinen wrote:
> On Thu, 10 Aug 2023, Jiri Slaby (SUSE) wrote:
> 
>> Currently, the tty layer ops and functions use various types for same
>> things:
>> * characters and flags: unsigned char, char are used on a random basis,
>> * counts: int, unsigned int, size_t are used, again more-or-less
>>    randomly.
>>
>> This makes it rather hard to remember where each type is required and it
>> also makes the code harder to follow. Also the code has to do min_t() on
>> many places simply because the variables hold the same kind of data, but
>> of different type.
>>
>> This is the first part of the series to unify the types:
>> * make characters and flags 'u8'. This is what the hardware expects and
>>    what feeds the tty layer with. Since we compile with -funsigned-char,
>>    char and unsigned char are the same types on all platforms. So there
>>    is no actual change in type.
>> * make sizes/counts 'size_t'. This is what comes from the VFS layer and
>>    some tty functions already operate on this. So instead of using
>>    "shorter" (in term of bytes on 64bit) unsigned int, stick to size_t
>>    and promote it to most places.
>>
>> More cleanup and spreading will be done in tty_buffer, n_tty, and
>> likely other places later.
>>
>> Patches 1-8 are cleanups only. The rest (the real switch) depends on
>> those.
> 
> Yeah, very much needed change and step into the right direction!
> 
> It's a bit tedious to review all this and comment a particular subchange
> but e.g. n_tty_receive_buf_common() still seems to still have int count
> which I think fall into the same call chain about size/count (probably
> most related change is #15). Note though that it also has room which I
> think can actually become negative so it might not be as straightforward
> search and replace like some other parts are.

tl;dr
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=9abb593df5a9b9b72d13438f1862ca67936f6b66

----

Yes, sorry, my bad -- I forgot to elaborate on why this is "part I." and 
what is going to be part II., III., ...

So yeah, I have more in my queue which is growing a lot. I had to cut it 
at some point as I was losing myself in all the changes already. So I 
flushed this "part I.". It is only a minimalistic change in the core and 
necessary changes in drivers' hooks. Parts II. and on will spread this 
more, of course. Ideally, to every single loop in every driver ;) (in 
long-term).

I still have a bunch of changes for tty_buffer and n_tty in my queue. As 
soon as I rebase on the today's -next which is already supposed to 
contain this part I., I will send part II. with these changes. I could 
have merged those II. changes to some earlier I. patches. At first, I 
actually did try, but the patches were growing with more and more 
dependencies, so I stopped this approach. Instead, I separated the 
changes per the core/ldisc/drivers. The parts are self-contained, 
despite it might look like the changes are incomplete (i.e. not 
everything is changed everywhere). After all, I wanted to avoid one 
hundred+ patches series.

thanks,
Geert Uytterhoeven Aug. 14, 2023, 2:44 p.m. UTC | #8
On Thu, Aug 10, 2023 at 11:16 AM Jiri Slaby (SUSE) <jirislaby@kernel.org> wrote:
> Data are now typed as u8. Propagate this change to
> tty_operations::put_char().
>
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

>  arch/m68k/emu/nfcon.c                  | 4 ++--
>  drivers/tty/amiserial.c                | 2 +-

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> # m68k
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> # m68k

Gr{oetje,eeting}s,

                        Geert
Ilpo Järvinen Aug. 14, 2023, 2:47 p.m. UTC | #9
On Mon, 14 Aug 2023, Jiri Slaby wrote:

> On 11. 08. 23, 12:26, Ilpo Järvinen wrote:
> > On Thu, 10 Aug 2023, Jiri Slaby (SUSE) wrote:
> > 
> > > Currently, the tty layer ops and functions use various types for same
> > > things:
> > > * characters and flags: unsigned char, char are used on a random basis,
> > > * counts: int, unsigned int, size_t are used, again more-or-less
> > >    randomly.
> > > 
> > > This makes it rather hard to remember where each type is required and it
> > > also makes the code harder to follow. Also the code has to do min_t() on
> > > many places simply because the variables hold the same kind of data, but
> > > of different type.
> > > 
> > > This is the first part of the series to unify the types:
> > > * make characters and flags 'u8'. This is what the hardware expects and
> > >    what feeds the tty layer with. Since we compile with -funsigned-char,
> > >    char and unsigned char are the same types on all platforms. So there
> > >    is no actual change in type.
> > > * make sizes/counts 'size_t'. This is what comes from the VFS layer and
> > >    some tty functions already operate on this. So instead of using
> > >    "shorter" (in term of bytes on 64bit) unsigned int, stick to size_t
> > >    and promote it to most places.
> > > 
> > > More cleanup and spreading will be done in tty_buffer, n_tty, and
> > > likely other places later.
> > > 
> > > Patches 1-8 are cleanups only. The rest (the real switch) depends on
> > > those.
> > 
> > Yeah, very much needed change and step into the right direction!
> > 
> > It's a bit tedious to review all this and comment a particular subchange
> > but e.g. n_tty_receive_buf_common() still seems to still have int count
> > which I think fall into the same call chain about size/count (probably
> > most related change is #15). Note though that it also has room which I
> > think can actually become negative so it might not be as straightforward
> > search and replace like some other parts are.
> 
> tl;dr
> https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=9abb593df5a9b9b72d13438f1862ca67936f6b66
> 
> ----
> 
> Yes, sorry, my bad -- I forgot to elaborate on why this is "part I." and what
> is going to be part II., III., ...
> 
> So yeah, I have more in my queue which is growing a lot. I had to cut it at
> some point as I was losing myself in all the changes already. So I flushed
> this "part I.". It is only a minimalistic change in the core and necessary
> changes in drivers' hooks. Parts II. and on will spread this more, of course.
> Ideally, to every single loop in every driver ;) (in long-term).
> 
> I still have a bunch of changes for tty_buffer and n_tty in my queue. As soon
> as I rebase on the today's -next which is already supposed to contain this
> part I., I will send part II. with these changes. I could have merged those
> II. changes to some earlier I. patches. At first, I actually did try, but the
> patches were growing with more and more dependencies, so I stopped this
> approach. Instead, I separated the changes per the core/ldisc/drivers. The
> parts are self-contained, despite it might look like the changes are
> incomplete (i.e. not everything is changed everywhere). After all, I wanted to
> avoid one hundred+ patches series.

Yeah, right. Very much understandable. I realized you probably had more 
patches somewhere due to "Part I" designation but I couldn't check so I 
just noted the things that I came up during the review.
Geert Uytterhoeven Aug. 14, 2023, 5:58 p.m. UTC | #10
On Thu, Aug 10, 2023 at 11:39 AM Jiri Slaby (SUSE) <jirislaby@kernel.org> wrote:
> Unify with the rest of the code. Use size_t for counts and ssize_t for
> retval.
>
> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>

>  arch/m68k/emu/nfcon.c                  | 3 ++-
>  drivers/tty/amiserial.c                | 2 +-

Reviewed-by: Geert Uytterhoeven <geert@linux-m68k.org> # m68k
Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> # m68k

Gr{oetje,eeting}s,

                        Geert
Nathan Chancellor Aug. 15, 2023, 5:22 p.m. UTC | #11
On Thu, Aug 10, 2023 at 11:15:08AM +0200, Jiri Slaby (SUSE) wrote:
> Unify the type of tty_operations::write() counters with the 'count'
> parameter. I.e. use size_t for them.
> 
> This includes changing constants to UL to keep min() and avoid min_t().

This patch appears to cause a warning/error on 32-bit architectures now
due to this part of the change, as size_t is 'unsigned int' there:

  In file included from include/linux/kernel.h:27,
                   from drivers/staging/gdm724x/gdm_tty.c:6:
  drivers/staging/gdm724x/gdm_tty.c: In function 'gdm_tty_write':
  include/linux/minmax.h:21:35: error: comparison of distinct pointer types lacks a cast [-Werror]
     21 |         (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
        |                                   ^~
  include/linux/minmax.h:27:18: note: in expansion of macro '__typecheck'
     27 |                 (__typecheck(x, y) && __no_side_effects(x, y))
        |                  ^~~~~~~~~~~
  include/linux/minmax.h:37:31: note: in expansion of macro '__safe_cmp'
     37 |         __builtin_choose_expr(__safe_cmp(x, y), \
        |                               ^~~~~~~~~~
  include/linux/minmax.h:68:25: note: in expansion of macro '__careful_cmp'
     68 | #define min(x, y)       __careful_cmp(x, y, <)
        |                         ^~~~~~~~~~~~~
  drivers/staging/gdm724x/gdm_tty.c:162:38: note: in expansion of macro 'min'
    162 |                 size_t sending_len = min(MUX_TX_MAX_SIZE, remain);
        |                                      ^~~
  cc1: all warnings being treated as errors

> Signed-off-by: Jiri Slaby (SUSE) <jirislaby@kernel.org>
> Cc: linux-staging@lists.linux.dev
> ---
>  drivers/staging/gdm724x/gdm_tty.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
> index b31f2afb0286..cbaaa8fa7474 100644
> --- a/drivers/staging/gdm724x/gdm_tty.c
> +++ b/drivers/staging/gdm724x/gdm_tty.c
> @@ -17,9 +17,9 @@
>  #define GDM_TTY_MAJOR 0
>  #define GDM_TTY_MINOR 32
>  
> -#define WRITE_SIZE 2048
> +#define WRITE_SIZE 2048UL
>  
> -#define MUX_TX_MAX_SIZE 2048
> +#define MUX_TX_MAX_SIZE 2048UL
>  
>  static inline bool gdm_tty_ready(struct gdm *gdm)
>  {
> @@ -152,9 +152,8 @@ static void gdm_tty_send_complete(void *arg)
>  static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
>  {
>  	struct gdm *gdm = tty->driver_data;
> -	int remain = len;
> -	int sent_len = 0;
> -	int sending_len = 0;
> +	size_t remain = len;
> +	size_t sent_len = 0;
>  
>  	if (!gdm_tty_ready(gdm))
>  		return -ENODEV;
> @@ -163,7 +162,7 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
>  		return 0;
>  
>  	while (1) {
> -		sending_len = min(MUX_TX_MAX_SIZE, remain);
> +		size_t sending_len = min(MUX_TX_MAX_SIZE, remain);
>  		gdm->tty_dev->send_func(gdm->tty_dev->priv_dev,
>  					(void *)(buf + sent_len),
>  					sending_len,
> -- 
> 2.41.0
>
Jiri Slaby Aug. 16, 2023, 6:46 a.m. UTC | #12
On 15. 08. 23, 19:22, Nathan Chancellor wrote:
> On Thu, Aug 10, 2023 at 11:15:08AM +0200, Jiri Slaby (SUSE) wrote:
>> Unify the type of tty_operations::write() counters with the 'count'
>> parameter. I.e. use size_t for them.
>>
>> This includes changing constants to UL to keep min() and avoid min_t().
> 
> This patch appears to cause a warning/error on 32-bit architectures now
> due to this part of the change, as size_t is 'unsigned int' there:

Right, this is my brain fart thinking ulong is the same as size_t 
everywhere. No, size_t is uint on 32bit.

I will fix this -- kernel build bot seems to be slow -- it didn't find 
the issue out in my queue, nor in tty-testing.

thanks,
David Laight Aug. 16, 2023, 8:40 a.m. UTC | #13
From: Jiri Slaby
> Sent: Wednesday, August 16, 2023 7:47 AM
> 
> On 15. 08. 23, 19:22, Nathan Chancellor wrote:
> > On Thu, Aug 10, 2023 at 11:15:08AM +0200, Jiri Slaby (SUSE) wrote:
> >> Unify the type of tty_operations::write() counters with the 'count'
> >> parameter. I.e. use size_t for them.
> >>
> >> This includes changing constants to UL to keep min() and avoid min_t().
> >
> > This patch appears to cause a warning/error on 32-bit architectures now
> > due to this part of the change, as size_t is 'unsigned int' there:
> 
> Right, this is my brain fart thinking ulong is the same as size_t
> everywhere. No, size_t is uint on 32bit.
> 
> I will fix this -- kernel build bot seems to be slow -- it didn't find
> the issue out in my queue, nor in tty-testing.

'Vote up' my patches to minmax.h that make this all work.
Then it won't care provided both values have the same signedness.
(or, with patch 5, are non-negative 31bit compile time constants.)

Pretty much the only other patch is casting the constants to (size_t).

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Jiri Slaby Aug. 16, 2023, 8:58 a.m. UTC | #14
On 16. 08. 23, 10:40, David Laight wrote:
> From: Jiri Slaby
>> Sent: Wednesday, August 16, 2023 7:47 AM
>>
>> On 15. 08. 23, 19:22, Nathan Chancellor wrote:
>>> On Thu, Aug 10, 2023 at 11:15:08AM +0200, Jiri Slaby (SUSE) wrote:
>>>> Unify the type of tty_operations::write() counters with the 'count'
>>>> parameter. I.e. use size_t for them.
>>>>
>>>> This includes changing constants to UL to keep min() and avoid min_t().
>>>
>>> This patch appears to cause a warning/error on 32-bit architectures now
>>> due to this part of the change, as size_t is 'unsigned int' there:
>>
>> Right, this is my brain fart thinking ulong is the same as size_t
>> everywhere. No, size_t is uint on 32bit.
>>
>> I will fix this -- kernel build bot seems to be slow -- it didn't find
>> the issue out in my queue, nor in tty-testing.
> 
> 'Vote up' my patches to minmax.h that make this all work.
> Then it won't care provided both values have the same signedness.
> (or, with patch 5, are non-negative 31bit compile time constants.)

Oh yeah, that [1] looks great. Why should one care in min(4096, 
sizeof()) after all…

So what's the current status of those?

[1] 
https://lore.kernel.org/all/b4ce9dad748e489f9314a2dc95615033@AcuMS.aculab.com/

thanks,
David Laight Aug. 16, 2023, 9:18 a.m. UTC | #15
From: Jiri Slaby
> Sent: Wednesday, August 16, 2023 9:59 AM
...
> > 'Vote up' my patches to minmax.h that make this all work.
> > Then it won't care provided both values have the same signedness.
> > (or, with patch 5, are non-negative 31bit compile time constants.)
> 
> Oh yeah, that [1] looks great. Why should one care in min(4096,
> sizeof()) after all…
> 
> So what's the current status of those?

Waiting... :-(

The only comment is from Linus who really doesn't like the idea
that min(signed_var, 4u) should be the same as min(signed_var, 4).
I think he is ok with min(unsigned_var, 4) though.

The min_t(u16,...) I quoted from the console buffer code is
a real bug that was identified by someone else last week.

Really min_t() is just an accident waiting to happen.

	David

> 
> [1]
> https://lore.kernel.org/all/b4ce9dad748e489f9314a2dc95615033@AcuMS.aculab.com/
> 
> thanks,
> --
> js
> suse labs

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Alexander Gordeev Aug. 17, 2023, 10:55 a.m. UTC | #16
On Thu, Aug 10, 2023 at 11:15:02AM +0200, Jiri Slaby (SUSE) wrote:
...
>  drivers/s390/char/con3215.c            | 2 +-
>  drivers/s390/char/con3270.c            | 2 +-
>  drivers/s390/char/sclp_tty.c           | 6 +++---
>  drivers/s390/char/sclp_vt220.c         | 2 +-
...
> diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
> index 16b6f430dfd3..8bbce6a4d7f5 100644
> --- a/drivers/s390/char/con3215.c
> +++ b/drivers/s390/char/con3215.c
> @@ -1030,7 +1030,7 @@ static int tty3215_write(struct tty_struct *tty, const u8 *buf, int count)
>  /*
>   * Put character routine for 3215 ttys
>   */
> -static int tty3215_put_char(struct tty_struct *tty, unsigned char ch)
> +static int tty3215_put_char(struct tty_struct *tty, u8 ch)
>  {
>  	struct raw3215_info *raw = tty->driver_data;
>  
> diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
> index 123524bff734..6374555a0937 100644
> --- a/drivers/s390/char/con3270.c
> +++ b/drivers/s390/char/con3270.c
> @@ -1821,7 +1821,7 @@ static int tty3270_write(struct tty_struct *tty, const u8 *buf, int count)
>  /*
>   * Put single characters to the ttys character buffer
>   */
> -static int tty3270_put_char(struct tty_struct *tty, unsigned char ch)
> +static int tty3270_put_char(struct tty_struct *tty, u8 ch)
>  {
>  	struct tty3270 *tp;
>  
> diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
> index cc0f6a97124e..831a8c7cacc2 100644
> --- a/drivers/s390/char/sclp_tty.c
> +++ b/drivers/s390/char/sclp_tty.c
> @@ -48,7 +48,7 @@ static struct sclp_buffer *sclp_ttybuf;
>  static struct timer_list sclp_tty_timer;
>  
>  static struct tty_port sclp_port;
> -static unsigned char sclp_tty_chars[SCLP_TTY_BUF_SIZE];
> +static u8 sclp_tty_chars[SCLP_TTY_BUF_SIZE];
>  static unsigned short int sclp_tty_chars_count;
>  
>  struct tty_driver *sclp_tty_driver;
> @@ -168,7 +168,7 @@ sclp_tty_timeout(struct timer_list *unused)
>  /*
>   * Write a string to the sclp tty.
>   */
> -static int sclp_tty_write_string(const unsigned char *str, int count, int may_fail)
> +static int sclp_tty_write_string(const u8 *str, int count, int may_fail)
>  {
>  	unsigned long flags;
>  	void *page;
> @@ -250,7 +250,7 @@ sclp_tty_write(struct tty_struct *tty, const u8 *buf, int count)
>   * sclp_write() without final '\n' - will be written.
>   */
>  static int
> -sclp_tty_put_char(struct tty_struct *tty, unsigned char ch)
> +sclp_tty_put_char(struct tty_struct *tty, u8 ch)
>  {
>  	sclp_tty_chars[sclp_tty_chars_count++] = ch;
>  	if (ch == '\n' || sclp_tty_chars_count >= SCLP_TTY_BUF_SIZE) {
> diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
> index 44974d801c1e..e148350c1e2c 100644
> --- a/drivers/s390/char/sclp_vt220.c
> +++ b/drivers/s390/char/sclp_vt220.c
> @@ -579,7 +579,7 @@ sclp_vt220_close(struct tty_struct *tty, struct file *filp)
>   * done stuffing characters into the driver.
>   */
>  static int
> -sclp_vt220_put_char(struct tty_struct *tty, unsigned char ch)
> +sclp_vt220_put_char(struct tty_struct *tty, u8 ch)
>  {
>  	return __sclp_vt220_write(&ch, 1, 0, 0, 1);
>  }

For s390 part:

Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>

Thanks!