2023-08-10 09:39:06

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 00/36] tty: type unifications -- part I.

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(-)

--
2.41.0



2023-08-10 09:40:21

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 04/36] tty: n_null: remove optional ldops

Only tty_ldisc_ops::read() and ::write() of n_null behave differently than
the default ldops implementations. They return %EOPNOTSUPP instead of
%EIO. So keep only those two and remove the rest ldops as they are
superfluous.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/n_null.c | 18 ------------------
1 file changed, 18 deletions(-)

diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c
index f913b665af72..4a0d8bb2fb4c 100644
--- a/drivers/tty/n_null.c
+++ b/drivers/tty/n_null.c
@@ -10,15 +10,6 @@
* Copyright (C) Intel 2017
*/

-static int n_null_open(struct tty_struct *tty)
-{
- return 0;
-}
-
-static void n_null_close(struct tty_struct *tty)
-{
-}
-
static ssize_t n_null_read(struct tty_struct *tty, struct file *file,
unsigned char *buf, size_t nr,
void **cookie, unsigned long offset)
@@ -32,21 +23,12 @@ static ssize_t n_null_write(struct tty_struct *tty, struct file *file,
return -EOPNOTSUPP;
}

-static void n_null_receivebuf(struct tty_struct *tty,
- const unsigned char *cp, const char *fp,
- int cnt)
-{
-}
-
static struct tty_ldisc_ops null_ldisc = {
.owner = THIS_MODULE,
.num = N_NULL,
.name = "n_null",
- .open = n_null_open,
- .close = n_null_close,
.read = n_null_read,
.write = n_null_write,
- .receive_buf = n_null_receivebuf
};

static int __init n_null_init(void)
--
2.41.0


2023-08-10 09:40:56

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 22/36] tty: rename and de-inline do_tty_write()

Make do_tty_write()'s name sound similar to iterate_tty_read(). They
both do similar things, so there is no reason for so distinct names. The
new name is therefore iterate_tty_write().

Drop the unnedeed inline modifier too. Let the compiler decide.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_io.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index ea5041fbbf28..846460c02c58 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -961,8 +961,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay)
* Split writes up in sane blocksizes to avoid
* denial-of-service type attacks
*/
-static inline ssize_t do_tty_write(struct tty_ldisc *ld, struct tty_struct *tty,
- struct file *file, struct iov_iter *from)
+static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty,
+ struct file *file, struct iov_iter *from)
{
size_t count = iov_iter_count(from);
ssize_t ret, written = 0;
@@ -1090,7 +1090,7 @@ static ssize_t file_tty_write(struct file *file, struct kiocb *iocb, struct iov_
if (!ld->ops->write)
ret = -EIO;
else
- ret = do_tty_write(ld, tty, file, from);
+ ret = iterate_tty_write(ld, tty, file, from);
tty_ldisc_deref(ld);
return ret;
}
--
2.41.0


2023-08-10 09:42:59

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 27/36] tty: propagate u8 data to tty_operations::write()

Data are now typed as u8. Propagate this change to
tty_operations::write().

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Ivan Kokshaysky <[email protected]>
Cc: Matt Turner <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Anton Ivanov <[email protected]>
Cc: Johannes Berg <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Vaibhav Gupta <[email protected]>
Cc: Jens Taprogge <[email protected]>
Cc: Karsten Keil <[email protected]>
Cc: Scott Branden <[email protected]>
Cc: Ulf Hansson <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: Alexander Gordeev <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Sven Schnelle <[email protected]>
Cc: David Lin <[email protected]>
Cc: Johan Hovold <[email protected]>
Cc: Alex Elder <[email protected]>
Cc: Laurentiu Tudor <[email protected]>
Cc: Jiri Kosina <[email protected]>
Cc: David Sterba <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Arnaud Pouliquen <[email protected]>
Cc: Oliver Neukum <[email protected]>
Cc: Mathias Nyman <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>
---
arch/alpha/kernel/srmcons.c | 3 +--
arch/m68k/emu/nfcon.c | 3 +--
arch/um/drivers/line.c | 2 +-
arch/um/drivers/line.h | 3 +--
arch/xtensa/platforms/iss/console.c | 3 +--
drivers/char/ttyprintk.c | 5 ++---
drivers/ipack/devices/ipoctal.c | 6 ++----
drivers/isdn/capi/capi.c | 3 +--
drivers/misc/bcm-vk/bcm_vk_tty.c | 4 +---
drivers/mmc/core/sdio_uart.c | 3 +--
drivers/net/usb/hso.c | 3 +--
drivers/s390/char/con3215.c | 3 +--
drivers/s390/char/con3270.c | 3 +--
drivers/s390/char/sclp_tty.c | 2 +-
drivers/s390/char/sclp_vt220.c | 2 +-
drivers/staging/gdm724x/gdm_tty.c | 3 +--
drivers/staging/greybus/uart.c | 3 +--
drivers/tty/amiserial.c | 2 +-
drivers/tty/ehv_bytechan.c | 3 +--
drivers/tty/goldfish.c | 6 ++----
drivers/tty/hvc/hvc_console.c | 2 +-
drivers/tty/hvc/hvcs.c | 3 +--
drivers/tty/hvc/hvsi.c | 3 +--
drivers/tty/ipwireless/hardware.c | 2 +-
drivers/tty/ipwireless/tty.c | 3 +--
drivers/tty/mips_ejtag_fdc.c | 4 ++--
drivers/tty/moxa.c | 8 +++-----
drivers/tty/mxser.c | 2 +-
drivers/tty/n_gsm.c | 3 +--
drivers/tty/nozomi.c | 5 ++---
drivers/tty/pty.c | 2 +-
drivers/tty/serial/kgdb_nmi.c | 2 +-
drivers/tty/serial/serial_core.c | 3 +--
drivers/tty/synclink_gt.c | 7 +++----
drivers/tty/ttynull.c | 3 +--
drivers/tty/vcc.c | 3 +--
drivers/tty/vt/vt.c | 4 ++--
drivers/usb/class/cdc-acm.c | 3 +--
drivers/usb/gadget/function/u_serial.c | 2 +-
drivers/usb/host/xhci-dbgtty.c | 4 +---
drivers/usb/serial/usb-serial.c | 3 +--
include/linux/tty_driver.h | 3 +--
net/bluetooth/rfcomm/tty.c | 2 +-
43 files changed, 53 insertions(+), 88 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index 6dc952b0df4a..dea39008d93e 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -130,8 +130,7 @@ srmcons_do_write(struct tty_port *port, const char *buf, int count)
}

static int
-srmcons_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+srmcons_write(struct tty_struct *tty, const u8 *buf, int count)
{
unsigned long flags;

diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c
index 6fdc13610565..e7a21234b481 100644
--- a/arch/m68k/emu/nfcon.c
+++ b/arch/m68k/emu/nfcon.c
@@ -70,8 +70,7 @@ static void nfcon_tty_close(struct tty_struct *tty, struct file *filp)
{
}

-static int nfcon_tty_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int nfcon_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
nfputs(buf, count);
return count;
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 02b0befd6763..e5393b4ba9f8 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -184,7 +184,7 @@ void line_flush_chars(struct tty_struct *tty)
line_flush_buffer(tty);
}

-int line_write(struct tty_struct *tty, const unsigned char *buf, int len)
+int line_write(struct tty_struct *tty, const u8 *buf, int len)
{
struct line *line = tty->driver_data;
unsigned long flags;
diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
index f15be75a3bf3..8354024b6b35 100644
--- a/arch/um/drivers/line.h
+++ b/arch/um/drivers/line.h
@@ -64,8 +64,7 @@ extern void line_cleanup(struct tty_struct *tty);
extern void line_hangup(struct tty_struct *tty);
extern int line_setup(char **conf, unsigned nlines, char **def,
char *init, char *name);
-extern int line_write(struct tty_struct *tty, const unsigned char *buf,
- int len);
+extern int line_write(struct tty_struct *tty, const u8 *buf, int len);
extern unsigned int line_chars_in_buffer(struct tty_struct *tty);
extern void line_flush_buffer(struct tty_struct *tty);
extern void line_flush_chars(struct tty_struct *tty);
diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index b40b73809dd8..182ec57e2d5c 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -52,8 +52,7 @@ static void rs_close(struct tty_struct *tty, struct file * filp)
}


-static int rs_write(struct tty_struct * tty,
- const unsigned char *buf, int count)
+static int rs_write(struct tty_struct * tty, const u8 *buf, int count)
{
/* see drivers/char/serialX.c to reference original version */

diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index ed45d04905c2..4f3dd93f1fd8 100644
--- a/drivers/char/ttyprintk.c
+++ b/drivers/char/ttyprintk.c
@@ -51,7 +51,7 @@ static void tpk_flush(void)
}
}

-static int tpk_printk(const unsigned char *buf, int count)
+static int tpk_printk(const u8 *buf, int count)
{
int i;

@@ -103,8 +103,7 @@ static void tpk_close(struct tty_struct *tty, struct file *filp)
/*
* TTY operations write function.
*/
-static int tpk_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int tpk_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct ttyprintk_port *tpkp = tty->driver_data;
unsigned long flags;
diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index a01c15812b70..c3cf086e7e36 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -437,8 +437,7 @@ static int ipoctal_inst_slot(struct ipoctal *ipoctal, unsigned int bus_nr,
}

static inline int ipoctal_copy_write_buffer(struct ipoctal_channel *channel,
- const unsigned char *buf,
- int count)
+ const u8 *buf, int count)
{
unsigned long flags;
int i;
@@ -459,8 +458,7 @@ static inline int ipoctal_copy_write_buffer(struct ipoctal_channel *channel,
return i;
}

-static int ipoctal_write_tty(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int ipoctal_write_tty(struct tty_struct *tty, const u8 *buf, int count)
{
struct ipoctal_channel *channel = tty->driver_data;
unsigned int char_copied;
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 45a4043c5042..cf6daf79c1a2 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1077,8 +1077,7 @@ static void capinc_tty_close(struct tty_struct *tty, struct file *filp)
tty_port_close(&mp->port, tty, filp);
}

-static int capinc_tty_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int capinc_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct capiminor *mp = tty->driver_data;
struct sk_buff *skb;
diff --git a/drivers/misc/bcm-vk/bcm_vk_tty.c b/drivers/misc/bcm-vk/bcm_vk_tty.c
index 6669625ba4c8..44851b607cce 100644
--- a/drivers/misc/bcm-vk/bcm_vk_tty.c
+++ b/drivers/misc/bcm-vk/bcm_vk_tty.c
@@ -186,9 +186,7 @@ static void bcm_vk_tty_doorbell(struct bcm_vk *vk, u32 db_val)
VK_BAR0_REGSEG_DB_BASE + VK_BAR0_REGSEG_TTY_DB_OFFSET);
}

-static int bcm_vk_tty_write(struct tty_struct *tty,
- const unsigned char *buffer,
- int count)
+static int bcm_vk_tty_write(struct tty_struct *tty, const u8 *buffer, int count)
{
int index;
struct bcm_vk *vk;
diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c
index aa659758563f..90d2fe00c0b9 100644
--- a/drivers/mmc/core/sdio_uart.c
+++ b/drivers/mmc/core/sdio_uart.c
@@ -760,8 +760,7 @@ static void sdio_uart_hangup(struct tty_struct *tty)
tty_port_hangup(&port->port);
}

-static int sdio_uart_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int sdio_uart_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct sdio_uart_port *port = tty->driver_data;
int ret;
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index ce1f6081d582..014a9d29bab5 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1322,8 +1322,7 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
}

/* close the requested serial port */
-static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int hso_serial_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct hso_serial *serial = tty->driver_data;
int space, tx_bytes;
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index a1fef666c9b0..16b6f430dfd3 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -1021,8 +1021,7 @@ static unsigned int tty3215_write_room(struct tty_struct *tty)
/*
* String write routine for 3215 ttys
*/
-static int tty3215_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int tty3215_write(struct tty_struct *tty, const u8 *buf, int count)
{
handle_write(tty->driver_data, buf, count);
return count;
diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
index d9983550062d..123524bff734 100644
--- a/drivers/s390/char/con3270.c
+++ b/drivers/s390/char/con3270.c
@@ -1803,8 +1803,7 @@ static void tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
/*
* String write routine for 3270 ttys
*/
-static int tty3270_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int tty3270_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct tty3270 *tp;

diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index 971fbb52740b..cc0f6a97124e 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -230,7 +230,7 @@ static int sclp_tty_write_string(const unsigned char *str, int count, int may_fa
* routine will return the number of characters actually accepted for writing.
*/
static int
-sclp_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
+sclp_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
if (sclp_tty_chars_count > 0) {
sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index a32f34a1c6d2..44974d801c1e 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -463,7 +463,7 @@ __sclp_vt220_write(const unsigned char *buf, int count, int do_schedule,
* number of characters actually accepted for writing.
*/
static int
-sclp_vt220_write(struct tty_struct *tty, const unsigned char *buf, int count)
+sclp_vt220_write(struct tty_struct *tty, const u8 *buf, int count)
{
return __sclp_vt220_write(buf, count, 1, 0, 1);
}
diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
index e1a84d6020f4..ae9978b73d9b 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -149,8 +149,7 @@ static void gdm_tty_send_complete(void *arg)
tty_port_tty_wakeup(&gdm->port);
}

-static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,
- int len)
+static int gdm_tty_write(struct tty_struct *tty, const u8 *buf, int len)
{
struct gdm *gdm = tty->driver_data;
int remain = len;
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 20a34599859f..97c7ddd0f53e 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -427,8 +427,7 @@ static void gb_tty_hangup(struct tty_struct *tty)
tty_port_hangup(&gb_tty->port);
}

-static int gb_tty_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int gb_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct gb_tty *gb_tty = tty->driver_data;

diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index c06ad0a0744b..1dd8b86f4a32 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -741,7 +741,7 @@ static void rs_flush_chars(struct tty_struct *tty)
local_irq_restore(flags);
}

-static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count)
+static int rs_write(struct tty_struct * tty, const u8 *buf, int count)
{
int c, ret = 0;
struct serial_state *info = tty->driver_data;
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
index 8595483f4697..de36347e2145 100644
--- a/drivers/tty/ehv_bytechan.c
+++ b/drivers/tty/ehv_bytechan.c
@@ -466,8 +466,7 @@ static irqreturn_t ehv_bc_tty_tx_isr(int irq, void *data)
* ehv_bc_tty_write_room() will never lie, so the tty layer will never send us
* too much data.
*/
-static int ehv_bc_tty_write(struct tty_struct *ttys, const unsigned char *s,
- int count)
+static int ehv_bc_tty_write(struct tty_struct *ttys, const u8 *s, int count)
{
struct ehv_bc_data *bc = ttys->driver_data;
unsigned long flags;
diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c
index d02de3f0326f..faa597ffbaf9 100644
--- a/drivers/tty/goldfish.c
+++ b/drivers/tty/goldfish.c
@@ -125,8 +125,7 @@ static void goldfish_tty_rw(struct goldfish_tty *qtty,
}
}

-static void goldfish_tty_do_write(int line, const char *buf,
- unsigned int count)
+static void goldfish_tty_do_write(int line, const u8 *buf, unsigned int count)
{
struct goldfish_tty *qtty = &goldfish_ttys[line];
unsigned long address = (unsigned long)(void *)buf;
@@ -186,8 +185,7 @@ static void goldfish_tty_hangup(struct tty_struct *tty)
tty_port_hangup(tty->port);
}

-static int goldfish_tty_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int goldfish_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
goldfish_tty_do_write(tty->index, buf, count);
return count;
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index 10c10cfdf92a..4c60d15c7a6f 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -496,7 +496,7 @@ static int hvc_push(struct hvc_struct *hp)
return n;
}

-static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count)
+static int hvc_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct hvc_struct *hp = tty->driver_data;
unsigned long flags;
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 1de1a09bf82d..2465d61b4e76 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -1257,8 +1257,7 @@ static void hvcs_hangup(struct tty_struct * tty)
* tty_hangup will allow hvcs_write time to complete execution before it
* terminates our device.
*/
-static int hvcs_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int hvcs_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct hvcs_struct *hvcsd = tty->driver_data;
unsigned int unit_address;
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index c1b8a4fd8b1e..46dd62df2442 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -904,8 +904,7 @@ static unsigned int hvsi_chars_in_buffer(struct tty_struct *tty)
return hp->n_outbuf;
}

-static int hvsi_write(struct tty_struct *tty,
- const unsigned char *source, int count)
+static int hvsi_write(struct tty_struct *tty, const u8 *source, int count)
{
struct hvsi_struct *hp = tty->driver_data;
unsigned long flags;
diff --git a/drivers/tty/ipwireless/hardware.c b/drivers/tty/ipwireless/hardware.c
index f5d3e68f5750..001ec318a918 100644
--- a/drivers/tty/ipwireless/hardware.c
+++ b/drivers/tty/ipwireless/hardware.c
@@ -1292,7 +1292,7 @@ static void *alloc_ctrl_packet(int header_size,
}

int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
- const unsigned char *data, unsigned int length,
+ const u8 *data, unsigned int length,
void (*callback) (void *cb, unsigned int length),
void *callback_data)
{
diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
index 9edd5ae17580..cd43208c523c 100644
--- a/drivers/tty/ipwireless/tty.c
+++ b/drivers/tty/ipwireless/tty.c
@@ -186,8 +186,7 @@ static void ipw_write_packet_sent_callback(void *callback_data,
tty->tx_bytes_queued -= packet_length;
}

-static int ipw_write(struct tty_struct *linux_tty,
- const unsigned char *buf, int count)
+static int ipw_write(struct tty_struct *linux_tty, const u8 *buf, int count)
{
struct ipw_tty *tty = linux_tty->driver_data;
int room, ret;
diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c
index e81701a66429..cf4ef0c38624 100644
--- a/drivers/tty/mips_ejtag_fdc.c
+++ b/drivers/tty/mips_ejtag_fdc.c
@@ -796,8 +796,8 @@ static void mips_ejtag_fdc_tty_hangup(struct tty_struct *tty)
tty_port_hangup(tty->port);
}

-static int mips_ejtag_fdc_tty_write(struct tty_struct *tty,
- const unsigned char *buf, int total)
+static int mips_ejtag_fdc_tty_write(struct tty_struct *tty, const u8 *buf,
+ int total)
{
int count, block;
struct mips_ejtag_fdc_tty_port *dport = tty->driver_data;
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 42fa4c878b2e..d94cf1be651b 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -487,7 +487,7 @@ module_param(ttymajor, int, 0);
*/
static int moxa_open(struct tty_struct *, struct file *);
static void moxa_close(struct tty_struct *, struct file *);
-static int moxa_write(struct tty_struct *, const unsigned char *, int);
+static int moxa_write(struct tty_struct *, const u8 *, int);
static unsigned int moxa_write_room(struct tty_struct *);
static void moxa_flush_buffer(struct tty_struct *);
static unsigned int moxa_chars_in_buffer(struct tty_struct *);
@@ -1499,8 +1499,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
tty_port_close(&ch->port, tty, filp);
}

-static int moxa_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int moxa_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct moxa_port *ch = tty->driver_data;
unsigned long flags;
@@ -2164,8 +2163,7 @@ static int MoxaPortLineStatus(struct moxa_port *port)
return val;
}

-static int MoxaPortWriteData(struct tty_struct *tty,
- const unsigned char *buffer, int len)
+static int MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer, int len)
{
struct moxa_port *port = tty->driver_data;
void __iomem *baseAddr, *ofsAddr, *ofs;
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 10855e66fda1..8b4b8493fed5 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -901,7 +901,7 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
tty_port_close(tty->port, tty, filp);
}

-static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
+static int mxser_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct mxser_port *info = tty->driver_data;
unsigned long flags;
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index a3bd1fc52aed..d167e36873fe 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -4256,8 +4256,7 @@ static void gsmtty_hangup(struct tty_struct *tty)
gsm_dlci_begin_close(dlci);
}

-static int gsmtty_write(struct tty_struct *tty, const unsigned char *buf,
- int len)
+static int gsmtty_write(struct tty_struct *tty, const u8 *buf, int len)
{
int sent;
struct gsm_dlci *dlci = tty->driver_data;
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index 0454c78deee6..b3756402f5d9 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -1599,8 +1599,7 @@ static void ntty_hangup(struct tty_struct *tty)
* called when the userspace process writes to the tty (/dev/noz*).
* Data is inserted into a fifo, which is then read and transferred to the modem.
*/
-static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
- int count)
+static int ntty_write(struct tty_struct *tty, const u8 *buffer, int count)
{
int rval = -EINVAL;
struct nozomi *dc = get_dc_by_tty(tty);
@@ -1610,7 +1609,7 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
if (!dc || !port)
return -ENODEV;

- rval = kfifo_in(&port->fifo_ul, (unsigned char *)buffer, count);
+ rval = kfifo_in(&port->fifo_ul, buffer, count);

spin_lock_irqsave(&dc->spin_mutex, flags);
/* CTS is only valid on the modem channel */
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 2b1c8ab99dba..335f5744f320 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -108,7 +108,7 @@ static void pty_unthrottle(struct tty_struct *tty)
* the other side of the pty/tty pair.
*/

-static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
+static int pty_write(struct tty_struct *tty, const u8 *buf, int c)
{
struct tty_struct *to = tty->link;

diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
index 55c3c9db7462..2a04d19d5ec0 100644
--- a/drivers/tty/serial/kgdb_nmi.c
+++ b/drivers/tty/serial/kgdb_nmi.c
@@ -304,7 +304,7 @@ static unsigned int kgdb_nmi_tty_write_room(struct tty_struct *tty)
return 2048;
}

-static int kgdb_nmi_tty_write(struct tty_struct *tty, const unchar *buf, int c)
+static int kgdb_nmi_tty_write(struct tty_struct *tty, const u8 *buf, int c)
{
int i;

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index e31c9b6bd8ab..33df5b08d992 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -580,8 +580,7 @@ static void uart_flush_chars(struct tty_struct *tty)
uart_start(tty);
}

-static int uart_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int uart_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct uart_state *state = tty->driver_data;
struct uart_port *port;
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index 4c6366fe015c..c7cecea38ca8 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -431,7 +431,7 @@ static void tx_set_idle(struct slgt_info *info);
static unsigned int tbuf_bytes(struct slgt_info *info);
static void reset_tbufs(struct slgt_info *info);
static void tdma_reset(struct slgt_info *info);
-static bool tx_load(struct slgt_info *info, const char *buf, unsigned int count);
+static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int count);

static void get_gtsignals(struct slgt_info *info);
static void set_gtsignals(struct slgt_info *info);
@@ -745,8 +745,7 @@ static void update_tx_timer(struct slgt_info *info)
}
}

-static int write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int write(struct tty_struct *tty, const u8 *buf, int count)
{
int ret = 0;
struct slgt_info *info = tty->driver_data;
@@ -4767,7 +4766,7 @@ static unsigned int tbuf_bytes(struct slgt_info *info)
* load data into transmit DMA buffer ring and start transmitter if needed
* return true if data accepted, otherwise false (buffers full)
*/
-static bool tx_load(struct slgt_info *info, const char *buf, unsigned int size)
+static bool tx_load(struct slgt_info *info, const u8 *buf, unsigned int size)
{
unsigned short count;
unsigned int i;
diff --git a/drivers/tty/ttynull.c b/drivers/tty/ttynull.c
index 1d4438472442..6b74ebaa0f2d 100644
--- a/drivers/tty/ttynull.c
+++ b/drivers/tty/ttynull.c
@@ -29,8 +29,7 @@ static void ttynull_hangup(struct tty_struct *tty)
tty_port_hangup(&ttynull_port);
}

-static int ttynull_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int ttynull_write(struct tty_struct *tty, const u8 *buf, int count)
{
return count;
}
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index 34ba6e54789a..c223879039b8 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -804,8 +804,7 @@ static void vcc_hangup(struct tty_struct *tty)
tty_port_hangup(tty->port);
}

-static int vcc_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int vcc_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct vcc_port *port;
struct vio_vcc *pkt;
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index cf77011a8f4e..2f28612aee91 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2845,7 +2845,7 @@ static int vc_con_write_normal(struct vc_data *vc, int tc, int c,
}

/* acquires console_lock */
-static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count)
+static int do_con_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct vc_draw_region draw = {
.x = -1,
@@ -3238,7 +3238,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
* /dev/ttyN handling
*/

-static int con_write(struct tty_struct *tty, const unsigned char *buf, int count)
+static int con_write(struct tty_struct *tty, const u8 *buf, int count)
{
int retval;

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 11da5fb284d0..913b07b30d33 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -789,8 +789,7 @@ static void acm_tty_close(struct tty_struct *tty, struct file *filp)
tty_port_close(&acm->port, tty, filp);
}

-static int acm_tty_write(struct tty_struct *tty,
- const unsigned char *buf, int count)
+static int acm_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct acm *acm = tty->driver_data;
int stat;
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 1115396b46a0..1d08a1d8d3cd 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -734,7 +734,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
spin_unlock_irq(&port->port_lock);
}

-static int gs_write(struct tty_struct *tty, const unsigned char *buf, int count)
+static int gs_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct gs_port *port = tty->driver_data;
unsigned long flags;
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index d3acc0829ee5..f5f2d0e12e69 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -208,9 +208,7 @@ static void dbc_tty_close(struct tty_struct *tty, struct file *file)
tty_port_close(&port->port, tty, file);
}

-static int dbc_tty_write(struct tty_struct *tty,
- const unsigned char *buf,
- int count)
+static int dbc_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct dbc_port *port = tty->driver_data;
unsigned long flags;
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 7b4805c1004d..51f738ea3f77 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -361,8 +361,7 @@ static void serial_cleanup(struct tty_struct *tty)
module_put(owner);
}

-static int serial_write(struct tty_struct *tty, const unsigned char *buf,
- int count)
+static int serial_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct usb_serial_port *port = tty->driver_data;
int retval = -ENODEV;
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index e00034118c7b..a7bd8060ac96 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -356,8 +356,7 @@ struct tty_operations {
void (*close)(struct tty_struct * tty, struct file * filp);
void (*shutdown)(struct tty_struct *tty);
void (*cleanup)(struct tty_struct *tty);
- int (*write)(struct tty_struct * tty,
- const unsigned char *buf, int count);
+ int (*write)(struct tty_struct *tty, const u8 *buf, int count);
int (*put_char)(struct tty_struct *tty, unsigned char ch);
void (*flush_chars)(struct tty_struct *tty);
unsigned int (*write_room)(struct tty_struct *tty);
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index d73eec146529..3b5f8404dc84 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -779,7 +779,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
tty_port_close(&dev->port, tty, filp);
}

-static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
+static int rfcomm_tty_write(struct tty_struct *tty, const u8 *buf, int count)
{
struct rfcomm_dev *dev = tty->driver_data;
struct rfcomm_dlc *dlc = dev->dlc;
--
2.41.0


2023-08-10 09:44:54

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 21/36] tty: don't pass write() to do_tty_write()

write() passed to do_tty_write() is always ld->ops->write(). Instead,
align with iterate_tty_read() and pass the whole ld instead. This makes
the code easier to follow as it is clear what the write is. And also the
function signature is more readable.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_io.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 54036a20a102..ea5041fbbf28 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -961,11 +961,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay)
* Split writes up in sane blocksizes to avoid
* denial-of-service type attacks
*/
-static inline ssize_t do_tty_write(
- ssize_t (*write)(struct tty_struct *, struct file *, const unsigned char *, size_t),
- struct tty_struct *tty,
- struct file *file,
- struct iov_iter *from)
+static inline ssize_t do_tty_write(struct tty_ldisc *ld, struct tty_struct *tty,
+ struct file *file, struct iov_iter *from)
{
size_t count = iov_iter_count(from);
ssize_t ret, written = 0;
@@ -1022,7 +1019,7 @@ static inline ssize_t do_tty_write(
if (copy_from_iter(tty->write_buf, size, from) != size)
break;

- ret = write(tty, file, tty->write_buf, size);
+ ret = ld->ops->write(tty, file, tty->write_buf, size);
if (ret <= 0)
break;

@@ -1093,7 +1090,7 @@ static ssize_t file_tty_write(struct file *file, struct kiocb *iocb, struct iov_
if (!ld->ops->write)
ret = -EIO;
else
- ret = do_tty_write(ld->ops->write, tty, file, from);
+ ret = do_tty_write(ld, tty, file, from);
tty_ldisc_deref(ld);
return ret;
}
--
2.41.0


2023-08-10 09:45:10

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 10/36] tty: make counts in tty_port_client_operations hooks size_t

The counts in tty_port_client_operations hooks' are currently
represented by all 'int', 'unsigned int', and 'size_t'. Unify them all
to unsigned 'size_t' for clarity. Note that size_t is used already in
tty_buffer.c. So, eventually, it is spread for counts everywhere and
this is the beginning.

So the two changes namely:
* ::receive_buf() is called from tty_ldisc_receive_buf(). And that
expects values ">= 0" from ::receive_buf(), so switch its rettype to
size_t is fine. tty_ldisc_receive_buf() types will be changed
separately.
* ::lookahead_buf()'s count comes from lookahead_bufs() and is already
'unsigned int'.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Rob Herring <[email protected]>
---
drivers/tty/serdev/serdev-ttyport.c | 4 ++--
drivers/tty/tty_port.c | 11 +++++------
include/linux/tty_port.h | 6 +++---
3 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
index f69ae27838e3..e3856814ce77 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -22,8 +22,8 @@ struct serport {
* Callback functions from the tty port.
*/

-static int ttyport_receive_buf(struct tty_port *port, const u8 *cp,
- const u8 *fp, size_t count)
+static size_t ttyport_receive_buf(struct tty_port *port, const u8 *cp,
+ const u8 *fp, size_t count)
{
struct serdev_controller *ctrl = port->client_data;
struct serport *serport = serdev_controller_get_drvdata(ctrl);
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 6bf58980c81d..7fd171b7c844 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -20,10 +20,9 @@
#include <linux/serdev.h>
#include "tty.h"

-static int tty_port_default_receive_buf(struct tty_port *port, const u8 *p,
- const u8 *f, size_t count)
+static size_t tty_port_default_receive_buf(struct tty_port *port, const u8 *p,
+ const u8 *f, size_t count)
{
- int ret;
struct tty_struct *tty;
struct tty_ldisc *ld;

@@ -35,15 +34,15 @@ static int tty_port_default_receive_buf(struct tty_port *port, const u8 *p,
if (!ld)
return 0;

- ret = tty_ldisc_receive_buf(ld, p, (char *)f, count);
+ count = tty_ldisc_receive_buf(ld, p, (char *)f, count);

tty_ldisc_deref(ld);

- return ret;
+ return count;
}

static void tty_port_default_lookahead_buf(struct tty_port *port, const u8 *p,
- const u8 *f, unsigned int count)
+ const u8 *f, size_t count)
{
struct tty_struct *tty;
struct tty_ldisc *ld;
diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h
index 726575743367..6b367eb17979 100644
--- a/include/linux/tty_port.h
+++ b/include/linux/tty_port.h
@@ -39,10 +39,10 @@ struct tty_port_operations {
};

struct tty_port_client_operations {
- int (*receive_buf)(struct tty_port *port, const u8 *cp, const u8 *fp,
- size_t count);
+ size_t (*receive_buf)(struct tty_port *port, const u8 *cp, const u8 *fp,
+ size_t count);
void (*lookahead_buf)(struct tty_port *port, const u8 *cp,
- const u8 *fp, unsigned int count);
+ const u8 *fp, size_t count);
void (*write_wakeup)(struct tty_port *port);
};

--
2.41.0


2023-08-10 09:47:41

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 18/36] misc: ti-st: make st_recv() conforming to tty_ldisc_ops::receive_buf()

That is change data type to u8 and count to unsigned int. And propagate
to both hooks (st_kim_recv() and kim_int_recv()).

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Arnd Bergmann <[email protected]>
---
drivers/misc/ti-st/st_core.c | 7 +++----
drivers/misc/ti-st/st_kim.c | 6 +++---
include/linux/ti_wilink_st.h | 2 +-
3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 4467c5b94ae8..c1a134bd8ba7 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -21,7 +21,7 @@
* st_kim_recv during registration to receive fw download responses
* st_int_recv after registration to receive proto stack responses
*/
-static void (*st_recv) (void *, const unsigned char *, long);
+static void (*st_recv)(void *disc_data, const u8 *ptr, size_t count);

/********************************************************************/
static void add_channel_to_table(struct st_data_s *st_gdata,
@@ -223,8 +223,7 @@ static inline void st_wakeup_ack(struct st_data_s *st_gdata,
* HCI-Events, ACL, SCO, 4 types of HCI-LL PM packets
* CH-8 packets from FM, CH-9 packets from GPS cores.
*/
-static void st_int_recv(void *disc_data,
- const unsigned char *ptr, long count)
+static void st_int_recv(void *disc_data, const u8 *ptr, size_t count)
{
struct st_proto_s *proto;
unsigned short payload_len = 0;
@@ -239,7 +238,7 @@ static void st_int_recv(void *disc_data,
return;
}

- pr_debug("count %ld rx_state %ld"
+ pr_debug("count %zu rx_state %ld"
"rx_count %ld", count, st_gdata->rx_state,
st_gdata->rx_count);

diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 5431a89924aa..fe682e0553b2 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -127,8 +127,8 @@ static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
* have been observed to come in bursts of different
* tty_receive and hence the logic
*/
-static void kim_int_recv(struct kim_data_s *kim_gdata,
- const unsigned char *ptr, long count)
+static void kim_int_recv(struct kim_data_s *kim_gdata, const u8 *ptr,
+ size_t count)
{
int len = 0;
unsigned char *plen;
@@ -417,7 +417,7 @@ static long download_firmware(struct kim_data_s *kim_gdata)
* 1. response to read local version
* 2. during send/recv's of firmware download
*/
-void st_kim_recv(void *disc_data, const unsigned char *data, long count)
+void st_kim_recv(void *disc_data, const u8 *data, size_t count)
{
struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
struct kim_data_s *kim_gdata = st_gdata->kim_data;
diff --git a/include/linux/ti_wilink_st.h b/include/linux/ti_wilink_st.h
index 44a7f9169ac6..10642d4844f0 100644
--- a/include/linux/ti_wilink_st.h
+++ b/include/linux/ti_wilink_st.h
@@ -271,7 +271,7 @@ long st_kim_stop(void *);

void st_kim_complete(void *);
void kim_st_list_protocols(struct st_data_s *, void *);
-void st_kim_recv(void *, const unsigned char *, long);
+void st_kim_recv(void *disc_data, const u8 *data, size_t count);


/*
--
2.41.0


2023-08-10 09:49:16

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 28/36] tty: propagate u8 data to tty_operations::put_char()

Data are now typed as u8. Propagate this change to
tty_operations::put_char().

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Geert Uytterhoeven <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: Alexander Gordeev <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Cc: Sven Schnelle <[email protected]>
Cc: Karsten Keil <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Jiri Slaby <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Fabio Estevam <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Mathias Nyman <[email protected]>
---
arch/m68k/emu/nfcon.c | 4 ++--
drivers/isdn/capi/capi.c | 2 +-
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 +-
drivers/tty/amiserial.c | 2 +-
drivers/tty/mxser.c | 2 +-
drivers/tty/serial/serial_core.c | 2 +-
drivers/tty/synclink_gt.c | 4 ++--
drivers/tty/vt/vt.c | 2 +-
drivers/usb/gadget/function/u_serial.c | 2 +-
drivers/usb/host/xhci-dbgtty.c | 2 +-
include/linux/tty_driver.h | 2 +-
14 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c
index e7a21234b481..87398f834e36 100644
--- a/arch/m68k/emu/nfcon.c
+++ b/arch/m68k/emu/nfcon.c
@@ -76,9 +76,9 @@ static int nfcon_tty_write(struct tty_struct *tty, const u8 *buf, int count)
return count;
}

-static int nfcon_tty_put_char(struct tty_struct *tty, unsigned char ch)
+static int nfcon_tty_put_char(struct tty_struct *tty, u8 ch)
{
- char temp[2] = { ch, 0 };
+ u8 temp[2] = { ch, 0 };

nf_call(stderr_id, virt_to_phys(temp));
return 1;
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index cf6daf79c1a2..2f38e1cfe97a 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1111,7 +1111,7 @@ static int capinc_tty_write(struct tty_struct *tty, const u8 *buf, int count)
return count;
}

-static int capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
+static int capinc_tty_put_char(struct tty_struct *tty, u8 ch)
{
struct capiminor *mp = tty->driver_data;
bool invoke_send = false;
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);
}
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index 1dd8b86f4a32..91cf294ec8c1 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -696,7 +696,7 @@ static void change_speed(struct tty_struct *tty, struct serial_state *info,
local_irq_restore(flags);
}

-static int rs_put_char(struct tty_struct *tty, unsigned char ch)
+static int rs_put_char(struct tty_struct *tty, u8 ch)
{
struct serial_state *info;
unsigned long flags;
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 8b4b8493fed5..a5dfd08d4ea2 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -920,7 +920,7 @@ static int mxser_write(struct tty_struct *tty, const u8 *buf, int count)
return written;
}

-static int mxser_put_char(struct tty_struct *tty, unsigned char ch)
+static int mxser_put_char(struct tty_struct *tty, u8 ch)
{
struct mxser_port *info = tty->driver_data;
unsigned long flags;
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 33df5b08d992..d5b682ff20b3 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -551,7 +551,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
}
EXPORT_SYMBOL(uart_get_divisor);

-static int uart_put_char(struct tty_struct *tty, unsigned char c)
+static int uart_put_char(struct tty_struct *tty, u8 c)
{
struct uart_state *state = tty->driver_data;
struct uart_port *port;
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index c7cecea38ca8..0264e9f7699c 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -780,7 +780,7 @@ static int write(struct tty_struct *tty, const u8 *buf, int count)
return ret;
}

-static int put_char(struct tty_struct *tty, unsigned char ch)
+static int put_char(struct tty_struct *tty, u8 ch)
{
struct slgt_info *info = tty->driver_data;
unsigned long flags;
@@ -788,7 +788,7 @@ static int put_char(struct tty_struct *tty, unsigned char ch)

if (sanity_check(info, tty->name, "put_char"))
return 0;
- DBGINFO(("%s put_char(%d)\n", info->device_name, ch));
+ DBGINFO(("%s put_char(%u)\n", info->device_name, ch));
if (!info->tx_buf)
return 0;
spin_lock_irqsave(&info->lock,flags);
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 2f28612aee91..ea7c20d66acb 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3248,7 +3248,7 @@ static int con_write(struct tty_struct *tty, const u8 *buf, int count)
return retval;
}

-static int con_put_char(struct tty_struct *tty, unsigned char ch)
+static int con_put_char(struct tty_struct *tty, u8 ch)
{
return do_con_write(tty, &ch, 1);
}
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 1d08a1d8d3cd..3e6b750aa4fc 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -753,7 +753,7 @@ static int gs_write(struct tty_struct *tty, const u8 *buf, int count)
return count;
}

-static int gs_put_char(struct tty_struct *tty, unsigned char ch)
+static int gs_put_char(struct tty_struct *tty, u8 ch)
{
struct gs_port *port = tty->driver_data;
unsigned long flags;
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index f5f2d0e12e69..5b82bdd82ba9 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -222,7 +222,7 @@ static int dbc_tty_write(struct tty_struct *tty, const u8 *buf, int count)
return count;
}

-static int dbc_tty_put_char(struct tty_struct *tty, unsigned char ch)
+static int dbc_tty_put_char(struct tty_struct *tty, u8 ch)
{
struct dbc_port *port = tty->driver_data;
unsigned long flags;
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index a7bd8060ac96..c5299d952e59 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -357,7 +357,7 @@ struct tty_operations {
void (*shutdown)(struct tty_struct *tty);
void (*cleanup)(struct tty_struct *tty);
int (*write)(struct tty_struct *tty, const u8 *buf, int count);
- int (*put_char)(struct tty_struct *tty, unsigned char ch);
+ int (*put_char)(struct tty_struct *tty, u8 ch);
void (*flush_chars)(struct tty_struct *tty);
unsigned int (*write_room)(struct tty_struct *tty);
unsigned int (*chars_in_buffer)(struct tty_struct *tty);
--
2.41.0


2023-08-10 09:50:07

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 01/36] tty: xtensa/iss: drop unneeded tty_operations hooks

All ::flush_chars(), ::hangup(), and ::wait_until_sent() from struct
tty_operations are optional. There is no need to provide them with
empty bodies.

tty_operations::put_char() needs not be provided if it is the same as
tty_operations::write(tty, &ch, 1).

So drop all of them.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Chris Zankel <[email protected]>
Cc: Max Filippov <[email protected]>
---
arch/xtensa/platforms/iss/console.c | 24 ------------------------
1 file changed, 24 deletions(-)

diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index 10b79d3c74e0..b40b73809dd8 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -82,32 +82,12 @@ static void rs_poll(struct timer_list *unused)
mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE);
}

-
-static int rs_put_char(struct tty_struct *tty, unsigned char ch)
-{
- return rs_write(tty, &ch, 1);
-}
-
-static void rs_flush_chars(struct tty_struct *tty)
-{
-}
-
static unsigned int rs_write_room(struct tty_struct *tty)
{
/* Let's say iss can always accept 2K characters.. */
return 2 * 1024;
}

-static void rs_hangup(struct tty_struct *tty)
-{
- /* Stub, once again.. */
-}
-
-static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
-{
- /* Stub, once again.. */
-}
-
static int rs_proc_show(struct seq_file *m, void *v)
{
seq_printf(m, "serinfo:1.0 driver:0.1\n");
@@ -118,11 +98,7 @@ static const struct tty_operations serial_ops = {
.open = rs_open,
.close = rs_close,
.write = rs_write,
- .put_char = rs_put_char,
- .flush_chars = rs_flush_chars,
.write_room = rs_write_room,
- .hangup = rs_hangup,
- .wait_until_sent = rs_wait_until_sent,
.proc_show = rs_proc_show,
};

--
2.41.0


2023-08-10 09:51:14

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 09/36] tty: make tty_port_client_operations operate with u8

The parameters are already unsigned chars. So make them explicitly u8s,
as the rest is going to be unified to u8 eventually too.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Rob Herring <[email protected]>
---
drivers/tty/serdev/serdev-ttyport.c | 4 ++--
drivers/tty/tty_buffer.c | 4 ++--
drivers/tty/tty_port.c | 9 ++++-----
include/linux/tty_port.h | 7 ++++---
4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serdev/serdev-ttyport.c b/drivers/tty/serdev/serdev-ttyport.c
index 8033ef19669c..f69ae27838e3 100644
--- a/drivers/tty/serdev/serdev-ttyport.c
+++ b/drivers/tty/serdev/serdev-ttyport.c
@@ -22,8 +22,8 @@ struct serport {
* Callback functions from the tty port.
*/

-static int ttyport_receive_buf(struct tty_port *port, const unsigned char *cp,
- const unsigned char *fp, size_t count)
+static int ttyport_receive_buf(struct tty_port *port, const u8 *cp,
+ const u8 *fp, size_t count)
{
struct serdev_controller *ctrl = port->client_data;
struct serport *serport = serdev_controller_get_drvdata(ctrl);
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 2df86ed90574..42464c37125a 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -505,8 +505,8 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)
static int
receive_buf(struct tty_port *port, struct tty_buffer *head, int count)
{
- unsigned char *p = char_buf_ptr(head, head->read);
- const char *f = NULL;
+ u8 *p = char_buf_ptr(head, head->read);
+ const u8 *f = NULL;
int n;

if (head->flags)
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index cda33dec73c3..6bf58980c81d 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -20,9 +20,8 @@
#include <linux/serdev.h>
#include "tty.h"

-static int tty_port_default_receive_buf(struct tty_port *port,
- const unsigned char *p,
- const unsigned char *f, size_t count)
+static int tty_port_default_receive_buf(struct tty_port *port, const u8 *p,
+ const u8 *f, size_t count)
{
int ret;
struct tty_struct *tty;
@@ -43,8 +42,8 @@ static int tty_port_default_receive_buf(struct tty_port *port,
return ret;
}

-static void tty_port_default_lookahead_buf(struct tty_port *port, const unsigned char *p,
- const unsigned char *f, unsigned int count)
+static void tty_port_default_lookahead_buf(struct tty_port *port, const u8 *p,
+ const u8 *f, unsigned int count)
{
struct tty_struct *tty;
struct tty_ldisc *ld;
diff --git a/include/linux/tty_port.h b/include/linux/tty_port.h
index edf685a24f7c..726575743367 100644
--- a/include/linux/tty_port.h
+++ b/include/linux/tty_port.h
@@ -39,9 +39,10 @@ struct tty_port_operations {
};

struct tty_port_client_operations {
- int (*receive_buf)(struct tty_port *port, const unsigned char *, const unsigned char *, size_t);
- void (*lookahead_buf)(struct tty_port *port, const unsigned char *cp,
- const unsigned char *fp, unsigned int count);
+ int (*receive_buf)(struct tty_port *port, const u8 *cp, const u8 *fp,
+ size_t count);
+ void (*lookahead_buf)(struct tty_port *port, const u8 *cp,
+ const u8 *fp, unsigned int count);
void (*write_wakeup)(struct tty_port *port);
};

--
2.41.0


2023-08-10 09:54:16

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 02/36] tty: ldisc: document that ldops are optional

There is no need to provide any hook in struct tty_ldisc_ops. Document
that and write down that read/write return EIO in that case. The rest is
simply ignored.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
include/linux/tty_ldisc.h | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index 49dc172dedc7..62e089434995 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -71,7 +71,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* call to @receive_buf(). Returning an error will prevent the ldisc from
* being attached.
*
- * Can sleep.
+ * Optional. Can sleep.
*
* @close: [TTY] ``void ()(struct tty_struct *tty)``
*
@@ -80,7 +80,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* changed to use a new line discipline. At the point of execution no
* further users will enter the ldisc code for this tty.
*
- * Can sleep.
+ * Optional. Can sleep.
*
* @flush_buffer: [TTY] ``void ()(struct tty_struct *tty)``
*
@@ -88,6 +88,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* input characters it may have queued to be delivered to the user mode
* process. It may be called at any point between open and close.
*
+ * Optional.
+ *
* @read: [TTY] ``ssize_t ()(struct tty_struct *tty, struct file *file,
* unsigned char *buf, size_t nr)``
*
@@ -97,7 +99,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* an %EIO error. Multiple read calls may occur in parallel and the ldisc
* must deal with serialization issues.
*
- * Can sleep.
+ * Optional: %EIO unless provided. Can sleep.
*
* @write: [TTY] ``ssize_t ()(struct tty_struct *tty, struct file *file,
* const unsigned char *buf, size_t nr)``
@@ -108,7 +110,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* characters first. If this function is not defined, the user will
* receive an %EIO error.
*
- * Can sleep.
+ * Optional: %EIO unless provided. Can sleep.
*
* @ioctl: [TTY] ``int ()(struct tty_struct *tty, unsigned int cmd,
* unsigned long arg)``
@@ -120,6 +122,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* discpline. So a low-level driver can "grab" an ioctl request before
* the line discpline has a chance to see it.
*
+ * Optional.
+ *
* @compat_ioctl: [TTY] ``int ()(struct tty_struct *tty, unsigned int cmd,
* unsigned long arg)``
*
@@ -130,11 +134,15 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* a pointer to wordsize-sensitive structure belongs here, but most of
* ldiscs will happily leave it %NULL.
*
+ * Optional.
+ *
* @set_termios: [TTY] ``void ()(struct tty_struct *tty, const struct ktermios *old)``
*
* This function notifies the line discpline that a change has been made
* to the termios structure.
*
+ * Optional.
+ *
* @poll: [TTY] ``int ()(struct tty_struct *tty, struct file *file,
* struct poll_table_struct *wait)``
*
@@ -142,6 +150,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* device. It is solely the responsibility of the line discipline to
* handle poll requests.
*
+ * Optional.
+ *
* @hangup: [TTY] ``void ()(struct tty_struct *tty)``
*
* Called on a hangup. Tells the discipline that it should cease I/O to
@@ -149,7 +159,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* but should wait until any pending driver I/O is completed. No further
* calls into the ldisc code will occur.
*
- * Can sleep.
+ * Optional. Can sleep.
*
* @receive_buf: [DRV] ``void ()(struct tty_struct *tty,
* const unsigned char *cp, const char *fp, int count)``
@@ -161,6 +171,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* character was received with a parity error, etc. @fp may be %NULL to
* indicate all data received is %TTY_NORMAL.
*
+ * Optional.
+ *
* @write_wakeup: [DRV] ``void ()(struct tty_struct *tty)``
*
* This function is called by the low-level tty driver to signal that line
@@ -170,11 +182,15 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* send, please arise a tasklet or workqueue to do the real data transfer.
* Do not send data in this hook, it may lead to a deadlock.
*
+ * Optional.
+ *
* @dcd_change: [DRV] ``void ()(struct tty_struct *tty, bool active)``
*
* Tells the discipline that the DCD pin has changed its status. Used
* exclusively by the %N_PPS (Pulse-Per-Second) line discipline.
*
+ * Optional.
+ *
* @receive_buf2: [DRV] ``int ()(struct tty_struct *tty,
* const unsigned char *cp, const char *fp, int count)``
*
@@ -186,6 +202,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* indicate all data received is %TTY_NORMAL. If assigned, prefer this
* function for automatic flow control.
*
+ * Optional.
+ *
* @lookahead_buf: [DRV] ``void ()(struct tty_struct *tty,
* const unsigned char *cp, const char *fp, int count)``
*
@@ -198,6 +216,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* same characters (e.g. by skipping the actions for high-priority
* characters already handled by ->lookahead_buf()).
*
+ * Optional.
+ *
* @owner: module containting this ldisc (for reference counting)
*
* This structure defines the interface between the tty line discipline
--
2.41.0


2023-08-10 09:54:26

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 26/36] tty: use min() for size computation in iterate_tty_read()

The computation is more obvious with min().

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_io.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 7cfa99fbbb62..4f21a21a1fd5 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -853,9 +853,8 @@ static ssize_t iterate_tty_read(struct tty_ldisc *ld, struct tty_struct *tty,
size_t copied, count = iov_iter_count(to);

do {
- ssize_t size;
+ ssize_t size = min(count, sizeof(kernel_buf));

- size = count > sizeof(kernel_buf) ? sizeof(kernel_buf) : count;
size = ld->ops->read(tty, file, kernel_buf, size, &cookie, offset);
if (!size)
break;
--
2.41.0


2023-08-10 09:54:53

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 07/36] tty: drop tty_debug_wait_until_sent()

It's a nop for everyone as TTY_DEBUG_WAIT_UNTIL_SENT is never set.
Provided, we have better debugging/printout mechanisms nowadays, remove
this mechanism.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_ioctl.c | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index e3e1318f53fd..f63e8b1b9e40 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -28,14 +28,6 @@
#include <asm/io.h>
#include <linux/uaccess.h>

-#undef TTY_DEBUG_WAIT_UNTIL_SENT
-
-#ifdef TTY_DEBUG_WAIT_UNTIL_SENT
-# define tty_debug_wait_until_sent(tty, f, args...) tty_debug(tty, f, ##args)
-#else
-# define tty_debug_wait_until_sent(tty, f, args...) do {} while (0)
-#endif
-
#undef DEBUG

/*
@@ -198,8 +190,6 @@ int tty_unthrottle_safe(struct tty_struct *tty)

void tty_wait_until_sent(struct tty_struct *tty, long timeout)
{
- tty_debug_wait_until_sent(tty, "wait until sent, timeout=%ld\n", timeout);
-
if (!timeout)
timeout = MAX_SCHEDULE_TIMEOUT;

--
2.41.0


2023-08-10 09:55:52

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 11/36] tty: switch receive_buf() counts to size_t

'size_t' is what receive_buf() expects and returns while handling count.
So switch to 'size_t'.

This renders both local 'count' and 'rcvd' in flush_to_ldisc() to be
size_t too.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_buffer.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 42464c37125a..7182dab60fac 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -502,12 +502,12 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)
}
}

-static int
-receive_buf(struct tty_port *port, struct tty_buffer *head, int count)
+static size_t
+receive_buf(struct tty_port *port, struct tty_buffer *head, size_t count)
{
u8 *p = char_buf_ptr(head, head->read);
const u8 *f = NULL;
- int n;
+ size_t n;

if (head->flags)
f = flag_buf_ptr(head, head->read);
@@ -539,7 +539,7 @@ static void flush_to_ldisc(struct work_struct *work)
while (1) {
struct tty_buffer *head = buf->head;
struct tty_buffer *next;
- int count, rcvd;
+ size_t count, rcvd;

/* Ldisc or user is trying to gain exclusive access */
if (atomic_read(&buf->priority))
--
2.41.0


2023-08-10 09:56:17

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 32/36] tty: hvc: convert counts to size_t

Unify the type of tty_operations::write() counters with the 'count'
parameter. I.e. use size_t for them.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: [email protected]
---
drivers/tty/hvc/hvc_console.c | 2 +-
drivers/tty/hvc/hvcs.c | 6 +++---
drivers/tty/hvc/hvsi.c | 10 +++++-----
3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index e93e8072ec86..959fae54ca39 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -500,7 +500,7 @@ static ssize_t hvc_write(struct tty_struct *tty, const u8 *buf, size_t count)
{
struct hvc_struct *hp = tty->driver_data;
unsigned long flags;
- int rsize, written = 0;
+ size_t rsize, written = 0;

/* This write was probably executed during a tty close. */
if (!hp)
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 1de91fa23b04..d29fdfe9d93d 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -1263,8 +1263,8 @@ static ssize_t hvcs_write(struct tty_struct *tty, const u8 *buf, size_t count)
unsigned int unit_address;
const unsigned char *charbuf;
unsigned long flags;
- int total_sent = 0;
- int tosend = 0;
+ size_t total_sent = 0;
+ size_t tosend = 0;
int result = 0;

/*
@@ -1299,7 +1299,7 @@ static ssize_t hvcs_write(struct tty_struct *tty, const u8 *buf, size_t count)
unit_address = hvcsd->vdev->unit_address;

while (count > 0) {
- tosend = min_t(unsigned, count,
+ tosend = min_t(size_t, count,
(HVCS_BUFF_LEN - hvcsd->chars_in_buffer));
/*
* No more space, this probably means that the last call to
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index c57bd85aa488..a94068bce76f 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -909,8 +909,8 @@ static ssize_t hvsi_write(struct tty_struct *tty, const u8 *source,
{
struct hvsi_struct *hp = tty->driver_data;
unsigned long flags;
- int total = 0;
- int origcount = count;
+ size_t total = 0;
+ size_t origcount = count;

spin_lock_irqsave(&hp->lock, flags);

@@ -928,7 +928,7 @@ static ssize_t hvsi_write(struct tty_struct *tty, const u8 *source,
* will see there is no room in outbuf and return.
*/
while ((count > 0) && (hvsi_write_room(tty) > 0)) {
- int chunksize = min_t(int, count, hvsi_write_room(tty));
+ size_t chunksize = min_t(size_t, count, hvsi_write_room(tty));

BUG_ON(hp->n_outbuf < 0);
memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
@@ -952,8 +952,8 @@ static ssize_t hvsi_write(struct tty_struct *tty, const u8 *source,
spin_unlock_irqrestore(&hp->lock, flags);

if (total != origcount)
- pr_debug("%s: wanted %i, only wrote %i\n", __func__, origcount,
- total);
+ pr_debug("%s: wanted %zu, only wrote %zu\n", __func__,
+ origcount, total);

return total;
}
--
2.41.0


2023-08-10 10:07:16

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 33/36] tty: vcc: convert counts to size_t

Unify the type of tty_operations::write() counters with the 'count'
parameter. I.e. use size_t for them.

This includes changing vcc_port::chars_in_buffer to size_t to keep min()
and avoid min_t().

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: "David S. Miller" <[email protected]>
---
arch/sparc/include/asm/vio.h | 2 +-
drivers/tty/vcc.c | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/sparc/include/asm/vio.h b/arch/sparc/include/asm/vio.h
index 8a0c3c11c9ce..587fb7841096 100644
--- a/arch/sparc/include/asm/vio.h
+++ b/arch/sparc/include/asm/vio.h
@@ -284,7 +284,7 @@ struct vio_dring_state {
struct ldc_trans_cookie cookies[VIO_MAX_RING_COOKIES];
};

-#define VIO_TAG_SIZE ((int)sizeof(struct vio_msg_tag))
+#define VIO_TAG_SIZE (sizeof(struct vio_msg_tag))
#define VIO_VCC_MTU_SIZE (LDC_PACKET_SIZE - VIO_TAG_SIZE)

struct vio_vcc {
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index 9cc569174c83..a39ed981bfd3 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -36,7 +36,7 @@ struct vcc_port {
* and guarantee that any characters that the driver accepts will
* be eventually sent, either immediately or later.
*/
- int chars_in_buffer;
+ size_t chars_in_buffer;
struct vio_vcc buffer;

struct timer_list rx_timer;
@@ -385,7 +385,7 @@ static void vcc_tx_timer(struct timer_list *t)
struct vcc_port *port = from_timer(port, t, tx_timer);
struct vio_vcc *pkt;
unsigned long flags;
- int tosend = 0;
+ size_t tosend = 0;
int rv;

spin_lock_irqsave(&port->lock, flags);
@@ -809,8 +809,8 @@ static ssize_t vcc_write(struct tty_struct *tty, const u8 *buf, size_t count)
struct vcc_port *port;
struct vio_vcc *pkt;
unsigned long flags;
- int total_sent = 0;
- int tosend = 0;
+ size_t total_sent = 0;
+ size_t tosend = 0;
int rv = -EINVAL;

port = vcc_get_ne(tty->index);
@@ -847,7 +847,7 @@ static ssize_t vcc_write(struct tty_struct *tty, const u8 *buf, size_t count)
* hypervisor actually took it because we have it buffered.
*/
rv = ldc_write(port->vio.lp, pkt, (VIO_TAG_SIZE + tosend));
- vccdbg("VCC: write: ldc_write(%d)=%d\n",
+ vccdbg("VCC: write: ldc_write(%zu)=%d\n",
(VIO_TAG_SIZE + tosend), rv);

total_sent += tosend;
@@ -864,7 +864,7 @@ static ssize_t vcc_write(struct tty_struct *tty, const u8 *buf, size_t count)

vcc_put(port, false);

- vccdbg("VCC: write: total=%d rv=%d", total_sent, rv);
+ vccdbg("VCC: write: total=%zu rv=%d", total_sent, rv);

return total_sent ? total_sent : rv;
}
--
2.41.0


2023-08-10 10:08:10

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 34/36] tty: gdm724x: convert counts to size_t

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().

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: [email protected]
---
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


2023-08-10 10:14:26

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 06/36] tty: tty_port: rename 'disc' to 'ld'

Line discipline variables are named 'ld' all over the tty code. Rename
these in tty_port, so that it is easier to grep for the code (namely for
"ld->ops").

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_port.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index a788a6bf487d..cda33dec73c3 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -26,19 +26,19 @@ static int tty_port_default_receive_buf(struct tty_port *port,
{
int ret;
struct tty_struct *tty;
- struct tty_ldisc *disc;
+ struct tty_ldisc *ld;

tty = READ_ONCE(port->itty);
if (!tty)
return 0;

- disc = tty_ldisc_ref(tty);
- if (!disc)
+ ld = tty_ldisc_ref(tty);
+ if (!ld)
return 0;

- ret = tty_ldisc_receive_buf(disc, p, (char *)f, count);
+ ret = tty_ldisc_receive_buf(ld, p, (char *)f, count);

- tty_ldisc_deref(disc);
+ tty_ldisc_deref(ld);

return ret;
}
@@ -47,20 +47,20 @@ static void tty_port_default_lookahead_buf(struct tty_port *port, const unsigned
const unsigned char *f, unsigned int count)
{
struct tty_struct *tty;
- struct tty_ldisc *disc;
+ struct tty_ldisc *ld;

tty = READ_ONCE(port->itty);
if (!tty)
return;

- disc = tty_ldisc_ref(tty);
- if (!disc)
+ ld = tty_ldisc_ref(tty);
+ if (!ld)
return;

- if (disc->ops->lookahead_buf)
- disc->ops->lookahead_buf(disc->tty, p, f, count);
+ if (ld->ops->lookahead_buf)
+ ld->ops->lookahead_buf(ld->tty, p, f, count);

- tty_ldisc_deref(disc);
+ tty_ldisc_deref(ld);
}

static void tty_port_default_wakeup(struct tty_port *port)
--
2.41.0


2023-08-10 10:21:56

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 03/36] tty: remove dummy tty_ldisc_ops::poll() implementations

tty_ldisc_ops::poll() is optional and needs not be provided. It is equal
to returning 0. So remove all those from the code.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
---
drivers/bluetooth/hci_ldisc.c | 7 -------
drivers/net/ppp/ppp_async.c | 8 --------
drivers/net/ppp/ppp_synctty.c | 8 --------
net/nfc/nci/uart.c | 7 -------
4 files changed, 30 deletions(-)

diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index a76eb98c0047..759472686831 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -819,12 +819,6 @@ static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file,
return 0;
}

-static __poll_t hci_uart_tty_poll(struct tty_struct *tty,
- struct file *filp, poll_table *wait)
-{
- return 0;
-}
-
static struct tty_ldisc_ops hci_uart_ldisc = {
.owner = THIS_MODULE,
.num = N_HCI,
@@ -835,7 +829,6 @@ static struct tty_ldisc_ops hci_uart_ldisc = {
.write = hci_uart_tty_write,
.ioctl = hci_uart_tty_ioctl,
.compat_ioctl = hci_uart_tty_ioctl,
- .poll = hci_uart_tty_poll,
.receive_buf = hci_uart_tty_receive,
.write_wakeup = hci_uart_tty_wakeup,
};
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index 15a179631903..f420bddb6a8c 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -328,13 +328,6 @@ ppp_asynctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
return err;
}

-/* No kernel lock - fine */
-static __poll_t
-ppp_asynctty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
-{
- return 0;
-}
-
/* May sleep, don't call from interrupt level or with interrupts disabled */
static void
ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
@@ -378,7 +371,6 @@ static struct tty_ldisc_ops ppp_ldisc = {
.read = ppp_asynctty_read,
.write = ppp_asynctty_write,
.ioctl = ppp_asynctty_ioctl,
- .poll = ppp_asynctty_poll,
.receive_buf = ppp_asynctty_receive,
.write_wakeup = ppp_asynctty_wakeup,
};
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index 18283b7b94bc..86dacef84c6c 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -321,13 +321,6 @@ ppp_synctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
return err;
}

-/* No kernel lock - fine */
-static __poll_t
-ppp_sync_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
-{
- return 0;
-}
-
/* May sleep, don't call from interrupt level or with interrupts disabled */
static void
ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
@@ -371,7 +364,6 @@ static struct tty_ldisc_ops ppp_sync_ldisc = {
.read = ppp_sync_read,
.write = ppp_sync_write,
.ioctl = ppp_synctty_ioctl,
- .poll = ppp_sync_poll,
.receive_buf = ppp_sync_receive,
.write_wakeup = ppp_sync_wakeup,
};
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index 082f94be0996..c8249d95306d 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -357,12 +357,6 @@ static ssize_t nci_uart_tty_write(struct tty_struct *tty, struct file *file,
return 0;
}

-static __poll_t nci_uart_tty_poll(struct tty_struct *tty,
- struct file *filp, poll_table *wait)
-{
- return 0;
-}
-
static int nci_uart_send(struct nci_uart *nu, struct sk_buff *skb)
{
/* Queue TX packet */
@@ -435,7 +429,6 @@ static struct tty_ldisc_ops nci_uart_ldisc = {
.close = nci_uart_tty_close,
.read = nci_uart_tty_read,
.write = nci_uart_tty_write,
- .poll = nci_uart_tty_poll,
.receive_buf = nci_uart_tty_receive,
.write_wakeup = nci_uart_tty_wakeup,
.ioctl = nci_uart_tty_ioctl,
--
2.41.0


2023-08-10 10:34:14

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 23/36] tty: use min() in iterate_tty_write()

It simplifies the code. The "price" is we have to unify 'chunk' to be
size_t the same as 'count' is. But that change is actually correct.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty_io.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 846460c02c58..0cf1277e260b 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -964,9 +964,8 @@ int tty_write_lock(struct tty_struct *tty, bool ndelay)
static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty,
struct file *file, struct iov_iter *from)
{
- size_t count = iov_iter_count(from);
+ size_t chunk, count = iov_iter_count(from);
ssize_t ret, written = 0;
- unsigned int chunk;

ret = tty_write_lock(tty, file->f_flags & O_NDELAY);
if (ret < 0)
@@ -1010,10 +1009,7 @@ static ssize_t iterate_tty_write(struct tty_ldisc *ld, struct tty_struct *tty,

/* Do the write .. */
for (;;) {
- size_t size = count;
-
- if (size > chunk)
- size = chunk;
+ size_t size = min(chunk, count);

ret = -EFAULT;
if (copy_from_iter(tty->write_buf, size, from) != size)
--
2.41.0


2023-08-10 10:38:36

by Dan Carpenter

[permalink] [raw]
Subject: Re: [PATCH 34/36] tty: gdm724x: convert counts to size_t

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().
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
> Cc: [email protected]
> ---
> 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;

We later check if remain <= 0. It still works because remain could
never be negative, but now it's even less necessary to check for
negatives, I guess.

regards,
dan carpenter


2023-08-10 10:38:55

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 14/36] tty: can327, move overflow test inside can327_ldisc_rx()'s loop

The 'count' is going to be unsigned and the 'count >= 0' test would be
always true then. Move the condition to the loop where this is easier to
check.

It looks as is easier to follow after all too.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Max Staudt <[email protected]>
Cc: Wolfgang Grandegger <[email protected]>
Cc: Marc Kleine-Budde <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: [email protected]
---
drivers/net/can/can327.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/can327.c b/drivers/net/can/can327.c
index 05e9c035e8f6..4533dc00f215 100644
--- a/drivers/net/can/can327.c
+++ b/drivers/net/can/can327.c
@@ -901,7 +901,13 @@ static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp,
*/
first_new_char_idx = elm->rxfill;

- while (count-- && elm->rxfill < CAN327_SIZE_RXBUF) {
+ while (count--) {
+ if (elm->rxfill >= CAN327_SIZE_RXBUF) {
+ netdev_err(elm->dev,
+ "Receive buffer overflowed. Bad chip or wiring? count = %i",
+ count);
+ goto uart_failure;
+ }
if (fp && *fp++) {
netdev_err(elm->dev,
"Error in received character stream. Check your wiring.");
@@ -930,13 +936,6 @@ static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp,
cp++;
}

- if (count >= 0) {
- netdev_err(elm->dev,
- "Receive buffer overflowed. Bad chip or wiring? count = %i",
- count);
- goto uart_failure;
- }
-
can327_parse_rxbuf(elm, first_new_char_idx);
spin_unlock_bh(&elm->lock);

--
2.41.0


2023-08-10 10:40:49

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 20/36] tty: tty_buffer: make all offsets unsigned

All these are supposed/expected to be unsigned as they are either counts
or offsets. So switch to unsigned for clarity.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
include/linux/tty_buffer.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/linux/tty_buffer.h b/include/linux/tty_buffer.h
index 391a875be20c..e45cba81d0e9 100644
--- a/include/linux/tty_buffer.h
+++ b/include/linux/tty_buffer.h
@@ -12,11 +12,11 @@ struct tty_buffer {
struct tty_buffer *next;
struct llist_node free;
};
- int used;
- int size;
- int commit;
- int lookahead; /* Lazy update on recv, can become less than "read" */
- int read;
+ unsigned int used;
+ unsigned int size;
+ unsigned int commit;
+ unsigned int lookahead; /* Lazy update on recv, can become less than "read" */
+ unsigned int read;
bool flags;
/* Data points here */
unsigned long data[];
--
2.41.0


2023-08-10 10:42:14

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 15/36] tty: make tty_ldisc_ops::*buf*() hooks operate on size_t

Count passed to tty_ldisc_ops::receive_buf*(), ::lookahead_buf(), and
returned from ::receive_buf2() is expected to be size_t. So set it to
size_t to unify with the rest of the code.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: William Hubbs <[email protected]>
Cc: Chris Brannon <[email protected]>
Cc: Kirk Reiser <[email protected]>
Cc: Samuel Thibault <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Max Staudt <[email protected]>
Cc: Wolfgang Grandegger <[email protected]>
Cc: Marc Kleine-Budde <[email protected]>
Cc: Dario Binacchi <[email protected]>
Cc: Andreas Koensgen <[email protected]>
Cc: Jeremy Kerr <[email protected]>
Cc: Matt Johnston <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
---
drivers/accessibility/speakup/spk_ttyio.c | 6 +++---
drivers/bluetooth/hci_ldisc.c | 2 +-
drivers/input/serio/serport.c | 3 ++-
drivers/misc/ti-st/st_core.c | 2 +-
drivers/net/caif/caif_serial.c | 2 +-
drivers/net/can/can327.c | 4 ++--
drivers/net/can/slcan/slcan-core.c | 2 +-
drivers/net/hamradio/6pack.c | 2 +-
drivers/net/hamradio/mkiss.c | 2 +-
drivers/net/mctp/mctp-serial.c | 2 +-
drivers/net/ppp/ppp_async.c | 2 +-
drivers/net/ppp/ppp_synctty.c | 2 +-
drivers/net/slip/slip.c | 2 +-
drivers/tty/n_gsm.c | 2 +-
drivers/tty/n_hdlc.c | 4 ++--
drivers/tty/n_tty.c | 14 ++++++++------
include/linux/tty_ldisc.h | 16 ++++++++--------
net/nfc/nci/uart.c | 2 +-
sound/soc/codecs/cx20442.c | 2 +-
19 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index 5d4bafe118ec..736f622068ce 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -71,9 +71,9 @@ static void spk_ttyio_ldisc_close(struct tty_struct *tty)
kfree(tty->disc_data);
}

-static int spk_ttyio_receive_buf2(struct tty_struct *tty,
- const unsigned char *cp,
- const char *fp, int count)
+static size_t spk_ttyio_receive_buf2(struct tty_struct *tty,
+ const unsigned char *cp, const char *fp,
+ size_t count)
{
struct spk_ldisc_data *ldisc_data = tty->disc_data;
struct spk_synth *synth = ldisc_data->synth;
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 759472686831..3473c4b8751a 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -599,7 +599,7 @@ static void hci_uart_tty_wakeup(struct tty_struct *tty)
* Return Value: None
*/
static void hci_uart_tty_receive(struct tty_struct *tty, const u8 *data,
- const char *flags, int count)
+ const char *flags, size_t count)
{
struct hci_uart *hu = tty->disc_data;

diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index a5d8953f5904..7fc6155131f8 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -115,7 +115,8 @@ static void serport_ldisc_close(struct tty_struct *tty)
*/

static void serport_ldisc_receive(struct tty_struct *tty,
- const unsigned char *cp, const char *fp, int count)
+ const unsigned char *cp, const char *fp,
+ size_t count)
{
struct serport *serport = tty->disc_data;
unsigned long flags;
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 3b2145722bd7..c89024ab3d77 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -792,7 +792,7 @@ static void st_tty_close(struct tty_struct *tty)
}

static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
- const char *tty_flags, int count)
+ const char *tty_flags, size_t count)
{
#ifdef VERBOSE
print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index 688075859ae4..feda04dbe837 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -159,7 +159,7 @@ static inline void debugfs_tx(struct ser_device *ser, const u8 *data, int size)
#endif

static void ldisc_receive(struct tty_struct *tty, const u8 *data,
- const char *flags, int count)
+ const char *flags, size_t count)
{
struct sk_buff *skb = NULL;
struct ser_device *ser;
diff --git a/drivers/net/can/can327.c b/drivers/net/can/can327.c
index 4533dc00f215..4bf970df7e84 100644
--- a/drivers/net/can/can327.c
+++ b/drivers/net/can/can327.c
@@ -886,7 +886,7 @@ static bool can327_is_valid_rx_char(u8 c)
* functions may be called in parallel.
*/
static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count)
+ const char *fp, size_t count)
{
struct can327 *elm = tty->disc_data;
size_t first_new_char_idx;
@@ -904,7 +904,7 @@ static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp,
while (count--) {
if (elm->rxfill >= CAN327_SIZE_RXBUF) {
netdev_err(elm->dev,
- "Receive buffer overflowed. Bad chip or wiring? count = %i",
+ "Receive buffer overflowed. Bad chip or wiring? count = %zu",
count);
goto uart_failure;
}
diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c
index 371af9d17b14..63371563d8e2 100644
--- a/drivers/net/can/slcan/slcan-core.c
+++ b/drivers/net/can/slcan/slcan-core.c
@@ -776,7 +776,7 @@ static const struct net_device_ops slcan_netdev_ops = {
*/
static void slcan_receive_buf(struct tty_struct *tty,
const unsigned char *cp, const char *fp,
- int count)
+ size_t count)
{
struct slcan *sl = tty->disc_data;

diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 9fb567524220..2089efb0d360 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -428,7 +428,7 @@ static void sixpack_write_wakeup(struct tty_struct *tty)
* and sent on to some IP layer for further processing.
*/
static void sixpack_receive_buf(struct tty_struct *tty,
- const unsigned char *cp, const char *fp, int count)
+ const unsigned char *cp, const char *fp, size_t count)
{
struct sixpack *sp;
int count1;
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index c251e04ae047..1efab6037c7e 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -875,7 +875,7 @@ static int mkiss_ioctl(struct tty_struct *tty, unsigned int cmd,
* and sent on to the AX.25 layer for further processing.
*/
static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count)
+ const char *fp, size_t count)
{
struct mkiss *ax = mkiss_get(tty);

diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c
index 9f9eaf896047..6761f4ff2e7c 100644
--- a/drivers/net/mctp/mctp-serial.c
+++ b/drivers/net/mctp/mctp-serial.c
@@ -392,7 +392,7 @@ static void mctp_serial_push(struct mctp_serial *dev, unsigned char c)

static void mctp_serial_tty_receive_buf(struct tty_struct *tty,
const unsigned char *c,
- const char *f, int len)
+ const char *f, size_t len)
{
struct mctp_serial *dev = tty->disc_data;
int i;
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index f420bddb6a8c..79b8fca47edb 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -331,7 +331,7 @@ ppp_asynctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
/* May sleep, don't call from interrupt level or with interrupts disabled */
static void
ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
- const char *cflags, int count)
+ const char *cflags, size_t count)
{
struct asyncppp *ap = ap_get(tty);
unsigned long flags;
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index 86dacef84c6c..767aca32b315 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -324,7 +324,7 @@ ppp_synctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
/* May sleep, don't call from interrupt level or with interrupts disabled */
static void
ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
- const char *cflags, int count)
+ const char *cflags, size_t count)
{
struct syncppp *ap = sp_get(tty);
unsigned long flags;
diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c
index 6865d32270e5..39450bf748a5 100644
--- a/drivers/net/slip/slip.c
+++ b/drivers/net/slip/slip.c
@@ -686,7 +686,7 @@ static void sl_setup(struct net_device *dev)
*/

static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count)
+ const char *fp, size_t count)
{
struct slip *sl = tty->disc_data;

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index c7a787f10a9c..2f85877b8ba1 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3490,7 +3490,7 @@ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
}

static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count)
+ const char *fp, size_t count)
{
struct gsm_mux *gsm = tty->disc_data;
char flags = TTY_NORMAL;
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 46b09bfb6f3a..ce3c779f5c03 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -370,12 +370,12 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty)
* interpreted as one HDLC frame.
*/
static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data,
- const char *flags, int count)
+ const char *flags, size_t count)
{
register struct n_hdlc *n_hdlc = tty->disc_data;
register struct n_hdlc_buf *buf;

- pr_debug("%s() called count=%d\n", __func__, count);
+ pr_debug("%s() called count=%zu\n", __func__, count);

if (count > maxframe) {
pr_debug("rx count>maxframesize, data discarded\n");
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 0043cc84b91a..ee9b20dcbce6 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1480,7 +1480,7 @@ n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag)

/* Caller must ensure count > 0 */
static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const unsigned char *cp,
- const unsigned char *fp, unsigned int count)
+ const unsigned char *fp, size_t count)
{
struct n_tty_data *ldata = tty->disc_data;
unsigned char flag = TTY_NORMAL;
@@ -1662,12 +1662,13 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
* claims non-exclusive %termios_rwsem
* publishes commit_head or canon_head
*/
-static int
+static size_t
n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp,
const char *fp, int count, int flow)
{
struct n_tty_data *ldata = tty->disc_data;
- int room, n, rcvd = 0, overflow;
+ size_t rcvd = 0;
+ int room, n, overflow;

down_read(&tty->termios_rwsem);

@@ -1744,13 +1745,14 @@ n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp,
}

static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count)
+ const char *fp, size_t count)
{
n_tty_receive_buf_common(tty, cp, fp, count, 0);
}

-static int n_tty_receive_buf2(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count)
+static size_t n_tty_receive_buf2(struct tty_struct *tty,
+ const unsigned char *cp, const char *fp,
+ size_t count)
{
return n_tty_receive_buf_common(tty, cp, fp, count, 1);
}
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index 62e089434995..f88529e6a783 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -162,7 +162,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* Optional. Can sleep.
*
* @receive_buf: [DRV] ``void ()(struct tty_struct *tty,
- * const unsigned char *cp, const char *fp, int count)``
+ * const unsigned char *cp, const char *fp, size_t count)``
*
* This function is called by the low-level tty driver to send characters
* received by the hardware to the line discpline for processing. @cp is
@@ -191,8 +191,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
*
* Optional.
*
- * @receive_buf2: [DRV] ``int ()(struct tty_struct *tty,
- * const unsigned char *cp, const char *fp, int count)``
+ * @receive_buf2: [DRV] ``ssize_t ()(struct tty_struct *tty,
+ * const unsigned char *cp, const char *fp, size_t count)``
*
* This function is called by the low-level tty driver to send characters
* received by the hardware to the line discpline for processing. @cp is a
@@ -205,7 +205,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* Optional.
*
* @lookahead_buf: [DRV] ``void ()(struct tty_struct *tty,
- * const unsigned char *cp, const char *fp, int count)``
+ * const unsigned char *cp, const char *fp, size_t count)``
*
* This function is called by the low-level tty driver for characters
* not eaten by ->receive_buf() or ->receive_buf2(). It is useful for
@@ -256,13 +256,13 @@ struct tty_ldisc_ops {
* The following routines are called from below.
*/
void (*receive_buf)(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count);
+ const char *fp, size_t count);
void (*write_wakeup)(struct tty_struct *tty);
void (*dcd_change)(struct tty_struct *tty, bool active);
- int (*receive_buf2)(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count);
+ size_t (*receive_buf2)(struct tty_struct *tty, const unsigned char *cp,
+ const char *fp, size_t count);
void (*lookahead_buf)(struct tty_struct *tty, const unsigned char *cp,
- const unsigned char *fp, unsigned int count);
+ const unsigned char *fp, size_t count);

struct module *owner;
};
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index c8249d95306d..c957ca6d2f87 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -296,7 +296,7 @@ static int nci_uart_default_recv_buf(struct nci_uart *nu, const u8 *data,
* Return Value: None
*/
static void nci_uart_tty_receive(struct tty_struct *tty, const u8 *data,
- const char *flags, int count)
+ const char *flags, size_t count)
{
struct nci_uart *nu = tty->disc_data;

diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c
index 43c0cac0ec9e..42cc863cbd53 100644
--- a/sound/soc/codecs/cx20442.c
+++ b/sound/soc/codecs/cx20442.c
@@ -259,7 +259,7 @@ static void v253_hangup(struct tty_struct *tty)

/* Line discipline .receive_buf() */
static void v253_receive(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, int count)
+ const char *fp, size_t count)
{
struct snd_soc_component *component = tty->disc_data;
struct cx20442_priv *cx20442;
--
2.41.0


2023-08-10 10:43:15

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 05/36] tty: change tty_write_lock()'s ndelay parameter to bool

It's a yes-no parameter, so convert it to bool to be obvious.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
---
drivers/tty/tty.h | 2 +-
drivers/tty/tty_io.c | 6 +++---
drivers/tty/tty_ioctl.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h
index 89769a1f1f97..2751ac3946e7 100644
--- a/drivers/tty/tty.h
+++ b/drivers/tty/tty.h
@@ -63,7 +63,7 @@ int tty_check_change(struct tty_struct *tty);
void __stop_tty(struct tty_struct *tty);
void __start_tty(struct tty_struct *tty);
void tty_write_unlock(struct tty_struct *tty);
-int tty_write_lock(struct tty_struct *tty, int ndelay);
+int tty_write_lock(struct tty_struct *tty, bool ndelay);
void tty_vhangup_session(struct tty_struct *tty);
void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty);
int tty_signal_session_leader(struct tty_struct *tty, int exit_session);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index eb4e2e0e300d..54036a20a102 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -946,7 +946,7 @@ void tty_write_unlock(struct tty_struct *tty)
wake_up_interruptible_poll(&tty->write_wait, EPOLLOUT);
}

-int tty_write_lock(struct tty_struct *tty, int ndelay)
+int tty_write_lock(struct tty_struct *tty, bool ndelay)
{
if (!mutex_trylock(&tty->atomic_write_lock)) {
if (ndelay)
@@ -1160,7 +1160,7 @@ int tty_send_xchar(struct tty_struct *tty, char ch)
return 0;
}

- if (tty_write_lock(tty, 0) < 0)
+ if (tty_write_lock(tty, false) < 0)
return -ERESTARTSYS;

down_read(&tty->termios_rwsem);
@@ -2486,7 +2486,7 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
retval = tty->ops->break_ctl(tty, duration);
else {
/* Do the work ourselves */
- if (tty_write_lock(tty, 0) < 0)
+ if (tty_write_lock(tty, false) < 0)
return -EINTR;
retval = tty->ops->break_ctl(tty, -1);
if (retval)
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 2e88b414cf95..e3e1318f53fd 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -507,7 +507,7 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
if (retval < 0)
return retval;

- if (tty_write_lock(tty, 0) < 0)
+ if (tty_write_lock(tty, false) < 0)
goto retry_write_wait;

/* Racing writer? */
--
2.41.0


2023-08-10 10:51:45

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 16/36] tty: use u8 for chars

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) <[email protected]>
Cc: William Hubbs <[email protected]>
Cc: Chris Brannon <[email protected]>
Cc: Kirk Reiser <[email protected]>
Cc: Samuel Thibault <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Max Staudt <[email protected]>
Cc: Wolfgang Grandegger <[email protected]>
Cc: Marc Kleine-Budde <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Dario Binacchi <[email protected]>
Cc: Andreas Koensgen <[email protected]>
Cc: Jeremy Kerr <[email protected]>
Cc: Matt Johnston <[email protected]>
Cc: Liam Girdwood <[email protected]>
Cc: Mark Brown <[email protected]>
Cc: Jaroslav Kysela <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Peter Ujfalusi <[email protected]>
---
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/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index 736f622068ce..dd683a079c08 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -71,9 +71,8 @@ static void spk_ttyio_ldisc_close(struct tty_struct *tty)
kfree(tty->disc_data);
}

-static size_t spk_ttyio_receive_buf2(struct tty_struct *tty,
- const unsigned char *cp, const char *fp,
- size_t count)
+static size_t spk_ttyio_receive_buf2(struct tty_struct *tty, const u8 *cp,
+ const char *fp, size_t count)
{
struct spk_ldisc_data *ldisc_data = tty->disc_data;
struct spk_synth *synth = ldisc_data->synth;
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 7fc6155131f8..8bf79d39964d 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -114,9 +114,8 @@ static void serport_ldisc_close(struct tty_struct *tty)
* 'interrupt' routine.
*/

-static void serport_ldisc_receive(struct tty_struct *tty,
- const unsigned char *cp, const char *fp,
- size_t count)
+static void serport_ldisc_receive(struct tty_struct *tty, const u8 *cp,
+ const char *fp, size_t count)
{
struct serport *serport = tty->disc_data;
unsigned long flags;
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index c89024ab3d77..0ce4e46ff161 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -791,7 +791,7 @@ static void st_tty_close(struct tty_struct *tty)
pr_debug("%s: done ", __func__);
}

-static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
+static void st_tty_receive(struct tty_struct *tty, const u8 *data,
const char *tty_flags, size_t count)
{
#ifdef VERBOSE
diff --git a/drivers/net/can/can327.c b/drivers/net/can/can327.c
index 4bf970df7e84..a054f5fd0d43 100644
--- a/drivers/net/can/can327.c
+++ b/drivers/net/can/can327.c
@@ -885,7 +885,7 @@ static bool can327_is_valid_rx_char(u8 c)
* This will not be re-entered while running, but other ldisc
* functions may be called in parallel.
*/
-static void can327_ldisc_rx(struct tty_struct *tty, const unsigned char *cp,
+static void can327_ldisc_rx(struct tty_struct *tty, const u8 *cp,
const char *fp, size_t count)
{
struct can327 *elm = tty->disc_data;
diff --git a/drivers/net/can/slcan/slcan-core.c b/drivers/net/can/slcan/slcan-core.c
index 63371563d8e2..fe5671dbeb77 100644
--- a/drivers/net/can/slcan/slcan-core.c
+++ b/drivers/net/can/slcan/slcan-core.c
@@ -774,9 +774,8 @@ static const struct net_device_ops slcan_netdev_ops = {
* be re-entered while running but other ldisc functions may be called
* in parallel
*/
-static void slcan_receive_buf(struct tty_struct *tty,
- const unsigned char *cp, const char *fp,
- size_t count)
+static void slcan_receive_buf(struct tty_struct *tty, const u8 *cp,
+ const char *fp, size_t count)
{
struct slcan *sl = tty->disc_data;

diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 2089efb0d360..9a1f2a3f3b4f 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -427,8 +427,8 @@ static void sixpack_write_wakeup(struct tty_struct *tty)
* a block of 6pack data has been received, which can now be decapsulated
* and sent on to some IP layer for further processing.
*/
-static void sixpack_receive_buf(struct tty_struct *tty,
- const unsigned char *cp, const char *fp, size_t count)
+static void sixpack_receive_buf(struct tty_struct *tty, const u8 *cp,
+ const char *fp, size_t count)
{
struct sixpack *sp;
int count1;
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index 1efab6037c7e..26dbcf49bfa6 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -874,7 +874,7 @@ static int mkiss_ioctl(struct tty_struct *tty, unsigned int cmd,
* a block of data has been received, which can now be decapsulated
* and sent on to the AX.25 layer for further processing.
*/
-static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
+static void mkiss_receive_buf(struct tty_struct *tty, const u8 *cp,
const char *fp, size_t count)
{
struct mkiss *ax = mkiss_get(tty);
diff --git a/drivers/net/mctp/mctp-serial.c b/drivers/net/mctp/mctp-serial.c
index 6761f4ff2e7c..5f809a18d308 100644
--- a/drivers/net/mctp/mctp-serial.c
+++ b/drivers/net/mctp/mctp-serial.c
@@ -390,8 +390,7 @@ static void mctp_serial_push(struct mctp_serial *dev, unsigned char c)
}
}

-static void mctp_serial_tty_receive_buf(struct tty_struct *tty,
- const unsigned char *c,
+static void mctp_serial_tty_receive_buf(struct tty_struct *tty, const u8 *c,
const char *f, size_t len)
{
struct mctp_serial *dev = tty->disc_data;
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index 79b8fca47edb..a661ccdea6ab 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -330,8 +330,8 @@ ppp_asynctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)

/* May sleep, don't call from interrupt level or with interrupts disabled */
static void
-ppp_asynctty_receive(struct tty_struct *tty, const unsigned char *buf,
- const char *cflags, size_t count)
+ppp_asynctty_receive(struct tty_struct *tty, const u8 *buf, const char *cflags,
+ size_t count)
{
struct asyncppp *ap = ap_get(tty);
unsigned long flags;
@@ -819,8 +819,8 @@ process_input_packet(struct asyncppp *ap)
other ldisc functions but will not be re-entered */

static void
-ppp_async_input(struct asyncppp *ap, const unsigned char *buf,
- const char *flags, int count)
+ppp_async_input(struct asyncppp *ap, const u8 *buf, const char *flags,
+ int count)
{
struct sk_buff *skb;
int c, i, j, n, s, f;
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index 767aca32b315..2a5cf6be9591 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -93,8 +93,8 @@ static int ppp_sync_ioctl(struct ppp_channel *chan, unsigned int cmd,
static void ppp_sync_process(struct tasklet_struct *t);
static int ppp_sync_push(struct syncppp *ap);
static void ppp_sync_flush_output(struct syncppp *ap);
-static void ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
- const char *flags, int count);
+static void ppp_sync_input(struct syncppp *ap, const u8 *buf, const char *flags,
+ int count);

static const struct ppp_channel_ops sync_ops = {
.start_xmit = ppp_sync_send,
@@ -323,8 +323,8 @@ ppp_synctty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg)

/* May sleep, don't call from interrupt level or with interrupts disabled */
static void
-ppp_sync_receive(struct tty_struct *tty, const unsigned char *buf,
- const char *cflags, size_t count)
+ppp_sync_receive(struct tty_struct *tty, const u8 *buf, const char *cflags,
+ size_t count)
{
struct syncppp *ap = sp_get(tty);
unsigned long flags;
@@ -655,8 +655,7 @@ ppp_sync_flush_output(struct syncppp *ap)
* frame is considered to be in error and is tossed.
*/
static void
-ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
- const char *flags, int count)
+ppp_sync_input(struct syncppp *ap, const u8 *buf, const char *flags, int count)
{
struct sk_buff *skb;
unsigned char *p;
diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c
index 39450bf748a5..7bfa90724e7b 100644
--- a/drivers/net/slip/slip.c
+++ b/drivers/net/slip/slip.c
@@ -685,7 +685,7 @@ static void sl_setup(struct net_device *dev)
* in parallel
*/

-static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
+static void slip_receive_buf(struct tty_struct *tty, const u8 *cp,
const char *fp, size_t count)
{
struct slip *sl = tty->disc_data;
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 2f85877b8ba1..86d89bbbaa16 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3489,7 +3489,7 @@ static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
gsm->tty = NULL;
}

-static void gsmld_receive_buf(struct tty_struct *tty, const unsigned char *cp,
+static void gsmld_receive_buf(struct tty_struct *tty, const u8 *cp,
const char *fp, size_t count)
{
struct gsm_mux *gsm = tty->disc_data;
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index ce3c779f5c03..c86be060baed 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -369,7 +369,7 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty)
* Called by tty low level driver when receive data is available. Data is
* interpreted as one HDLC frame.
*/
-static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data,
+static void n_hdlc_tty_receive(struct tty_struct *tty, const u8 *data,
const char *flags, size_t count)
{
register struct n_hdlc *n_hdlc = tty->disc_data;
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index ee9b20dcbce6..d770007e5215 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1479,7 +1479,7 @@ n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag)
}

/* Caller must ensure count > 0 */
-static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const unsigned char *cp,
+static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const u8 *cp,
const unsigned char *fp, size_t count)
{
struct n_tty_data *ldata = tty->disc_data;
@@ -1500,8 +1500,8 @@ static void n_tty_lookahead_flow_ctrl(struct tty_struct *tty, const unsigned cha
}

static void
-n_tty_receive_buf_real_raw(const struct tty_struct *tty,
- const unsigned char *cp, int count)
+n_tty_receive_buf_real_raw(const struct tty_struct *tty, const u8 *cp,
+ int count)
{
struct n_tty_data *ldata = tty->disc_data;
size_t n, head;
@@ -1520,7 +1520,7 @@ n_tty_receive_buf_real_raw(const struct tty_struct *tty,
}

static void
-n_tty_receive_buf_raw(struct tty_struct *tty, const unsigned char *cp,
+n_tty_receive_buf_raw(struct tty_struct *tty, const u8 *cp,
const char *fp, int count)
{
struct n_tty_data *ldata = tty->disc_data;
@@ -1537,7 +1537,7 @@ n_tty_receive_buf_raw(struct tty_struct *tty, const unsigned char *cp,
}

static void
-n_tty_receive_buf_closing(struct tty_struct *tty, const unsigned char *cp,
+n_tty_receive_buf_closing(struct tty_struct *tty, const u8 *cp,
const char *fp, int count, bool lookahead_done)
{
char flag = TTY_NORMAL;
@@ -1550,14 +1550,15 @@ n_tty_receive_buf_closing(struct tty_struct *tty, const unsigned char *cp,
}
}

-static void n_tty_receive_buf_standard(struct tty_struct *tty,
- const unsigned char *cp, const char *fp, int count, bool lookahead_done)
+static void n_tty_receive_buf_standard(struct tty_struct *tty, const u8 *cp,
+ const char *fp, int count,
+ bool lookahead_done)
{
struct n_tty_data *ldata = tty->disc_data;
char flag = TTY_NORMAL;

while (count--) {
- unsigned char c = *cp++;
+ u8 c = *cp++;

if (fp)
flag = *fp++;
@@ -1588,7 +1589,7 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
}
}

-static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
+static void __receive_buf(struct tty_struct *tty, const u8 *cp,
const char *fp, int count)
{
struct n_tty_data *ldata = tty->disc_data;
@@ -1663,7 +1664,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
* publishes commit_head or canon_head
*/
static size_t
-n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp,
+n_tty_receive_buf_common(struct tty_struct *tty, const u8 *cp,
const char *fp, int count, int flow)
{
struct n_tty_data *ldata = tty->disc_data;
@@ -1744,15 +1745,14 @@ n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp,
return rcvd;
}

-static void n_tty_receive_buf(struct tty_struct *tty, const unsigned char *cp,
+static void n_tty_receive_buf(struct tty_struct *tty, const u8 *cp,
const char *fp, size_t count)
{
n_tty_receive_buf_common(tty, cp, fp, count, 0);
}

-static size_t n_tty_receive_buf2(struct tty_struct *tty,
- const unsigned char *cp, const char *fp,
- size_t count)
+static size_t n_tty_receive_buf2(struct tty_struct *tty, const u8 *cp,
+ const char *fp, size_t count)
{
return n_tty_receive_buf_common(tty, cp, fp, count, 1);
}
diff --git a/drivers/tty/tty.h b/drivers/tty/tty.h
index 2751ac3946e7..e31cd9f281de 100644
--- a/drivers/tty/tty.h
+++ b/drivers/tty/tty.h
@@ -115,6 +115,6 @@ static inline void tty_audit_tiocsti(const struct tty_struct *tty, char ch)
ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);

int tty_insert_flip_string_and_push_buffer(struct tty_port *port,
- const unsigned char *chars, size_t cnt);
+ const u8 *chars, size_t cnt);

#endif
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 56f5732ce47f..9db42e6ed45b 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -316,8 +316,8 @@ EXPORT_SYMBOL_GPL(tty_buffer_request_room);
*
* Returns: the number added.
*/
-int tty_insert_flip_string_fixed_flag(struct tty_port *port,
- const unsigned char *chars, char flag, size_t size)
+int tty_insert_flip_string_fixed_flag(struct tty_port *port, const u8 *chars,
+ char flag, size_t size)
{
int copied = 0;
bool flags = flag != TTY_NORMAL;
@@ -355,8 +355,8 @@ EXPORT_SYMBOL(tty_insert_flip_string_fixed_flag);
*
* Returns: the number added.
*/
-int tty_insert_flip_string_flags(struct tty_port *port,
- const unsigned char *chars, const char *flags, size_t size)
+int tty_insert_flip_string_flags(struct tty_port *port, const u8 *chars,
+ const char *flags, size_t size)
{
int copied = 0;

@@ -390,7 +390,7 @@ EXPORT_SYMBOL(tty_insert_flip_string_flags);
* Queue a single byte @ch to the tty buffering, with an optional flag. This is
* the slow path of tty_insert_flip_char().
*/
-int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag)
+int __tty_insert_flip_char(struct tty_port *port, u8 ch, char flag)
{
struct tty_buffer *tb;
bool flags = flag != TTY_NORMAL;
@@ -421,8 +421,7 @@ EXPORT_SYMBOL(__tty_insert_flip_char);
* Returns: the length available and buffer pointer (@chars) to the space which
* is now allocated and accounted for as ready for normal characters.
*/
-int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars,
- size_t size)
+int tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size)
{
int space = __tty_buffer_request_room(port, size, false);

@@ -450,8 +449,8 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
*
* Returns: the number of bytes processed.
*/
-size_t tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
- const char *f, size_t count)
+size_t tty_ldisc_receive_buf(struct tty_ldisc *ld, const u8 *p, const char *f,
+ size_t count)
{
if (ld->ops->receive_buf2)
count = ld->ops->receive_buf2(ld->tty, p, f, count);
@@ -489,7 +488,7 @@ static void lookahead_bufs(struct tty_port *port, struct tty_buffer *head)
}

if (port->client_ops->lookahead_buf) {
- unsigned char *p, *f = NULL;
+ u8 *p, *f = NULL;

p = char_buf_ptr(head, head->lookahead);
if (head->flags)
@@ -620,7 +619,7 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
* Returns: the number added.
*/
int tty_insert_flip_string_and_push_buffer(struct tty_port *port,
- const unsigned char *chars, size_t size)
+ const u8 *chars, size_t size)
{
struct tty_bufhead *buf = &port->buf;
unsigned long flags;
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;
}

static inline char *flag_buf_ptr(struct tty_buffer *b, int ofs)
diff --git a/include/linux/tty_flip.h b/include/linux/tty_flip.h
index 09c4dbcd0025..a0fcffeaaa25 100644
--- a/include/linux/tty_flip.h
+++ b/include/linux/tty_flip.h
@@ -10,17 +10,15 @@ struct tty_ldisc;
int tty_buffer_set_limit(struct tty_port *port, int limit);
unsigned int tty_buffer_space_avail(struct tty_port *port);
int tty_buffer_request_room(struct tty_port *port, size_t size);
-int tty_insert_flip_string_flags(struct tty_port *port,
- const unsigned char *chars, const char *flags, size_t size);
-int tty_insert_flip_string_fixed_flag(struct tty_port *port,
- const unsigned char *chars, char flag, size_t size);
-int tty_prepare_flip_string(struct tty_port *port, unsigned char **chars,
- size_t size);
+int tty_insert_flip_string_flags(struct tty_port *port, const u8 *chars,
+ const char *flags, size_t size);
+int tty_insert_flip_string_fixed_flag(struct tty_port *port, const u8 *chars,
+ char flag, size_t size);
+int tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size);
void tty_flip_buffer_push(struct tty_port *port);
-int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag);
+int __tty_insert_flip_char(struct tty_port *port, u8 ch, char flag);

-static inline int tty_insert_flip_char(struct tty_port *port,
- unsigned char ch, char flag)
+static inline int tty_insert_flip_char(struct tty_port *port, u8 ch, char flag)
{
struct tty_buffer *tb = port->buf.tail;
int change;
@@ -36,13 +34,13 @@ static inline int tty_insert_flip_char(struct tty_port *port,
}

static inline int tty_insert_flip_string(struct tty_port *port,
- const unsigned char *chars, size_t size)
+ const u8 *chars, size_t size)
{
return tty_insert_flip_string_fixed_flag(port, chars, TTY_NORMAL, size);
}

-size_t tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
- const char *f, size_t count);
+size_t tty_ldisc_receive_buf(struct tty_ldisc *ld, const u8 *p, const char *f,
+ size_t count);

void tty_buffer_lock_exclusive(struct tty_port *port);
void tty_buffer_unlock_exclusive(struct tty_port *port);
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index f88529e6a783..5551c4400e59 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -161,8 +161,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
*
* Optional. Can sleep.
*
- * @receive_buf: [DRV] ``void ()(struct tty_struct *tty,
- * const unsigned char *cp, const char *fp, size_t count)``
+ * @receive_buf: [DRV] ``void ()(struct tty_struct *tty, const u8 *cp,
+ * const char *fp, size_t count)``
*
* This function is called by the low-level tty driver to send characters
* received by the hardware to the line discpline for processing. @cp is
@@ -191,8 +191,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
*
* Optional.
*
- * @receive_buf2: [DRV] ``ssize_t ()(struct tty_struct *tty,
- * const unsigned char *cp, const char *fp, size_t count)``
+ * @receive_buf2: [DRV] ``ssize_t ()(struct tty_struct *tty, const u8 *cp,
+ * const char *fp, size_t count)``
*
* This function is called by the low-level tty driver to send characters
* received by the hardware to the line discpline for processing. @cp is a
@@ -204,8 +204,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
*
* Optional.
*
- * @lookahead_buf: [DRV] ``void ()(struct tty_struct *tty,
- * const unsigned char *cp, const char *fp, size_t count)``
+ * @lookahead_buf: [DRV] ``void ()(struct tty_struct *tty, const u8 *cp,
+ * const char *fp, size_t count)``
*
* This function is called by the low-level tty driver for characters
* not eaten by ->receive_buf() or ->receive_buf2(). It is useful for
@@ -255,13 +255,13 @@ struct tty_ldisc_ops {
/*
* The following routines are called from below.
*/
- void (*receive_buf)(struct tty_struct *tty, const unsigned char *cp,
+ void (*receive_buf)(struct tty_struct *tty, const u8 *cp,
const char *fp, size_t count);
void (*write_wakeup)(struct tty_struct *tty);
void (*dcd_change)(struct tty_struct *tty, bool active);
- size_t (*receive_buf2)(struct tty_struct *tty, const unsigned char *cp,
+ size_t (*receive_buf2)(struct tty_struct *tty, const u8 *cp,
const char *fp, size_t count);
- void (*lookahead_buf)(struct tty_struct *tty, const unsigned char *cp,
+ void (*lookahead_buf)(struct tty_struct *tty, const u8 *cp,
const unsigned char *fp, size_t count);

struct module *owner;
diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c
index 42cc863cbd53..6d4938e3cbad 100644
--- a/sound/soc/codecs/cx20442.c
+++ b/sound/soc/codecs/cx20442.c
@@ -258,8 +258,8 @@ static void v253_hangup(struct tty_struct *tty)
}

/* Line discipline .receive_buf() */
-static void v253_receive(struct tty_struct *tty, const unsigned char *cp,
- const char *fp, size_t count)
+static void v253_receive(struct tty_struct *tty, const u8 *cp, const char *fp,
+ size_t count)
{
struct snd_soc_component *component = tty->disc_data;
struct cx20442_priv *cx20442;
diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c
index 1028b5efcfff..371943350fdf 100644
--- a/sound/soc/ti/ams-delta.c
+++ b/sound/soc/ti/ams-delta.c
@@ -336,7 +336,7 @@ static void cx81801_hangup(struct tty_struct *tty)
}

/* Line discipline .receive_buf() */
-static void cx81801_receive(struct tty_struct *tty, const unsigned char *cp,
+static void cx81801_receive(struct tty_struct *tty, const u8 *cp,
const char *fp, int count)
{
struct snd_soc_component *component = tty->disc_data;
--
2.41.0


2023-08-10 10:51:54

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 34/36] tty: gdm724x: convert counts to size_t

On 10. 08. 23, 11:42, Dan Carpenter 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().
>>
>> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
>> Cc: [email protected]
>> ---
>> 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;
>
> We later check if remain <= 0. It still works because remain could
> never be negative, but now it's even less necessary to check for
> negatives, I guess.

You're right. The whole loop should be now:

while (remain) {
...
}

Even without the preceding 'if'.

thanks,
--
js
suse labs


2023-08-10 10:56:18

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 31/36] tty: ldops: unify to u8

Some hooks in struct tty_ldisc_ops still reference buffers by 'unsigned
char'. Unify to 'u8' as the rest of the tty layer does.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Cc: Marcel Holtmann <[email protected]>
Cc: Johan Hedberg <[email protected]>
Cc: Luiz Augusto von Dentz <[email protected]>
Cc: Dmitry Torokhov <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
---
drivers/bluetooth/hci_ldisc.c | 6 +++---
drivers/input/serio/serport.c | 4 ++--
drivers/net/ppp/ppp_async.c | 9 ++++-----
drivers/net/ppp/ppp_synctty.c | 7 +++----
drivers/tty/n_gsm.c | 7 +++----
drivers/tty/n_hdlc.c | 6 +++---
drivers/tty/n_null.c | 7 +++----
drivers/tty/n_tty.c | 11 +++++------
include/linux/tty_ldisc.h | 13 ++++++-------
net/nfc/nci/uart.c | 6 +++---
10 files changed, 35 insertions(+), 41 deletions(-)

diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 3e11fc06a932..a26367e9fb19 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -807,14 +807,14 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
* We don't provide read/write/poll interface for user space.
*/
static ssize_t hci_uart_tty_read(struct tty_struct *tty, struct file *file,
- unsigned char *buf, size_t nr,
- void **cookie, unsigned long offset)
+ u8 *buf, size_t nr, void **cookie,
+ unsigned long offset)
{
return 0;
}

static ssize_t hci_uart_tty_write(struct tty_struct *tty, struct file *file,
- const unsigned char *data, size_t count)
+ const u8 *data, size_t count)
{
return 0;
}
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 5ce8d9f10f3e..1db3f30011c4 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -158,8 +158,8 @@ static void serport_ldisc_receive(struct tty_struct *tty, const u8 *cp,
*/

static ssize_t serport_ldisc_read(struct tty_struct * tty, struct file * file,
- unsigned char *kbuf, size_t nr,
- void **cookie, unsigned long offset)
+ u8 *kbuf, size_t nr, void **cookie,
+ unsigned long offset)
{
struct serport *serport = tty->disc_data;
struct serio *serio;
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index cfd5cb609d99..fbaaa8c102a1 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -257,9 +257,8 @@ static void ppp_asynctty_hangup(struct tty_struct *tty)
* Pppd reads and writes packets via /dev/ppp instead.
*/
static ssize_t
-ppp_asynctty_read(struct tty_struct *tty, struct file *file,
- unsigned char *buf, size_t count,
- void **cookie, unsigned long offset)
+ppp_asynctty_read(struct tty_struct *tty, struct file *file, u8 *buf,
+ size_t count, void **cookie, unsigned long offset)
{
return -EAGAIN;
}
@@ -269,8 +268,8 @@ ppp_asynctty_read(struct tty_struct *tty, struct file *file,
* from the ppp generic stuff.
*/
static ssize_t
-ppp_asynctty_write(struct tty_struct *tty, struct file *file,
- const unsigned char *buf, size_t count)
+ppp_asynctty_write(struct tty_struct *tty, struct file *file, const u8 *buf,
+ size_t count)
{
return -EAGAIN;
}
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index 164c9053f73b..ebcdffdf4f0e 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -255,8 +255,7 @@ static void ppp_sync_hangup(struct tty_struct *tty)
* Pppd reads and writes packets via /dev/ppp instead.
*/
static ssize_t
-ppp_sync_read(struct tty_struct *tty, struct file *file,
- unsigned char *buf, size_t count,
+ppp_sync_read(struct tty_struct *tty, struct file *file, u8 *buf, size_t count,
void **cookie, unsigned long offset)
{
return -EAGAIN;
@@ -267,8 +266,8 @@ ppp_sync_read(struct tty_struct *tty, struct file *file,
* from the ppp generic stuff.
*/
static ssize_t
-ppp_sync_write(struct tty_struct *tty, struct file *file,
- const unsigned char *buf, size_t count)
+ppp_sync_write(struct tty_struct *tty, struct file *file, const u8 *buf,
+ size_t count)
{
return -EAGAIN;
}
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 3e5cc30941a7..42759500b79e 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3638,9 +3638,8 @@ static void gsmld_write_wakeup(struct tty_struct *tty)
* This code must be sure never to sleep through a hangup.
*/

-static ssize_t gsmld_read(struct tty_struct *tty, struct file *file,
- unsigned char *buf, size_t nr,
- void **cookie, unsigned long offset)
+static ssize_t gsmld_read(struct tty_struct *tty, struct file *file, u8 *buf,
+ size_t nr, void **cookie, unsigned long offset)
{
return -EOPNOTSUPP;
}
@@ -3660,7 +3659,7 @@ static ssize_t gsmld_read(struct tty_struct *tty, struct file *file,
*/

static ssize_t gsmld_write(struct tty_struct *tty, struct file *file,
- const unsigned char *buf, size_t nr)
+ const u8 *buf, size_t nr)
{
struct gsm_mux *gsm = tty->disc_data;
unsigned long flags;
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 9be0932d07e0..a670419efe79 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -425,8 +425,8 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const u8 *data,
* Returns the number of bytes returned or error code.
*/
static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
- __u8 *kbuf, size_t nr,
- void **cookie, unsigned long offset)
+ u8 *kbuf, size_t nr, void **cookie,
+ unsigned long offset)
{
struct n_hdlc *n_hdlc = tty->disc_data;
int ret = 0;
@@ -518,7 +518,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file,
* Returns the number of bytes written (or error code).
*/
static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
- const unsigned char *data, size_t count)
+ const u8 *data, size_t count)
{
struct n_hdlc *n_hdlc = tty->disc_data;
int error = 0;
diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c
index 4a0d8bb2fb4c..5a429d923eb3 100644
--- a/drivers/tty/n_null.c
+++ b/drivers/tty/n_null.c
@@ -10,15 +10,14 @@
* Copyright (C) Intel 2017
*/

-static ssize_t n_null_read(struct tty_struct *tty, struct file *file,
- unsigned char *buf, size_t nr,
- void **cookie, unsigned long offset)
+static ssize_t n_null_read(struct tty_struct *tty, struct file *file, u8 *buf,
+ size_t nr, void **cookie, unsigned long offset)
{
return -EOPNOTSUPP;
}

static ssize_t n_null_write(struct tty_struct *tty, struct file *file,
- const unsigned char *buf, size_t nr)
+ const u8 *buf, size_t nr)
{
return -EOPNOTSUPP;
}
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 1053b2adb04c..f44f38bb412e 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2128,12 +2128,11 @@ static int job_control(struct tty_struct *tty, struct file *file)
* claims non-exclusive termios_rwsem;
* publishes read_tail
*/
-static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
- unsigned char *kbuf, size_t nr,
- void **cookie, unsigned long offset)
+static ssize_t n_tty_read(struct tty_struct *tty, struct file *file, u8 *kbuf,
+ size_t nr, void **cookie, unsigned long offset)
{
struct n_tty_data *ldata = tty->disc_data;
- unsigned char *kb = kbuf;
+ u8 *kb = kbuf;
DEFINE_WAIT_FUNC(wait, woken_wake_function);
int c;
int minimum, time;
@@ -2332,9 +2331,9 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
*/

static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
- const unsigned char *buf, size_t nr)
+ const u8 *buf, size_t nr)
{
- const unsigned char *b = buf;
+ const u8 *b = buf;
DEFINE_WAIT_FUNC(wait, woken_wake_function);
int c;
ssize_t retval = 0;
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index a661d7df5497..af01e89074b2 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -90,8 +90,8 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
*
* Optional.
*
- * @read: [TTY] ``ssize_t ()(struct tty_struct *tty, struct file *file,
- * unsigned char *buf, size_t nr)``
+ * @read: [TTY] ``ssize_t ()(struct tty_struct *tty, struct file *file, u8 *buf,
+ * size_t nr)``
*
* This function is called when the user requests to read from the @tty.
* The line discipline will return whatever characters it has buffered up
@@ -102,7 +102,7 @@ int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
* Optional: %EIO unless provided. Can sleep.
*
* @write: [TTY] ``ssize_t ()(struct tty_struct *tty, struct file *file,
- * const unsigned char *buf, size_t nr)``
+ * const u8 *buf, size_t nr)``
*
* This function is called when the user requests to write to the @tty.
* The line discipline will deliver the characters to the low-level tty
@@ -238,11 +238,10 @@ struct tty_ldisc_ops {
int (*open)(struct tty_struct *tty);
void (*close)(struct tty_struct *tty);
void (*flush_buffer)(struct tty_struct *tty);
- ssize_t (*read)(struct tty_struct *tty, struct file *file,
- unsigned char *buf, size_t nr,
- void **cookie, unsigned long offset);
+ ssize_t (*read)(struct tty_struct *tty, struct file *file, u8 *buf,
+ size_t nr, void **cookie, unsigned long offset);
ssize_t (*write)(struct tty_struct *tty, struct file *file,
- const unsigned char *buf, size_t nr);
+ const u8 *buf, size_t nr);
int (*ioctl)(struct tty_struct *tty, unsigned int cmd,
unsigned long arg);
int (*compat_ioctl)(struct tty_struct *tty, unsigned int cmd,
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index 93775c540287..ed1508a9e093 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -345,14 +345,14 @@ static int nci_uart_tty_ioctl(struct tty_struct *tty, unsigned int cmd,

/* We don't provide read/write/poll interface for user space. */
static ssize_t nci_uart_tty_read(struct tty_struct *tty, struct file *file,
- unsigned char *buf, size_t nr,
- void **cookie, unsigned long offset)
+ u8 *buf, size_t nr, void **cookie,
+ unsigned long offset)
{
return 0;
}

static ssize_t nci_uart_tty_write(struct tty_struct *tty, struct file *file,
- const unsigned char *data, size_t count)
+ const u8 *data, size_t count)
{
return 0;
}
--
2.41.0


2023-08-10 11:22:53

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 34-and-three-quarters/36] tty: gdm724x: simplify gdm_tty_write()

len and remain can never be negative in gdm_tty_write(). So remove such
a check and move the check of remaining bytes to the loop condition.
This way, the preceding 'if' is now superfluous too. Fix all that and
make the code cleaner.

Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Cc: [email protected]
---
drivers/staging/gdm724x/gdm_tty.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
index cbaaa8fa7474..67d9bf41e836 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -158,10 +158,7 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
if (!gdm_tty_ready(gdm))
return -ENODEV;

- if (!len)
- return 0;
-
- while (1) {
+ while (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),
@@ -171,8 +168,6 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
gdm);
sent_len += sending_len;
remain -= sending_len;
- if (remain <= 0)
- break;
}

return len;
--
2.41.0


2023-08-10 12:25:09

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 16/36] tty: use u8 for chars

On Thu, Aug 10, 2023 at 11:14:50AM +0200, 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.

Acked-by: Mark Brown <[email protected]>


Attachments:
(No filename) (258.00 B)
signature.asc (499.00 B)
Download all attachments

2023-08-10 12:57:27

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH 15/36] tty: make tty_ldisc_ops::*buf*() hooks operate on size_t

On Thu, Aug 10, 2023 at 11:14:49AM +0200, Jiri Slaby (SUSE) wrote:
> Count passed to tty_ldisc_ops::receive_buf*(), ::lookahead_buf(), and
> returned from ::receive_buf2() is expected to be size_t. So set it to
> size_t to unify with the rest of the code.

Acked-by: Mark Brown <[email protected]>


Attachments:
(No filename) (305.00 B)
signature.asc (499.00 B)
Download all attachments

2023-08-10 13:27:35

by Max Filippov

[permalink] [raw]
Subject: Re: [PATCH 01/36] tty: xtensa/iss: drop unneeded tty_operations hooks

On Thu, Aug 10, 2023 at 2:15 AM Jiri Slaby (SUSE) <[email protected]> wrote:
>
> All ::flush_chars(), ::hangup(), and ::wait_until_sent() from struct
> tty_operations are optional. There is no need to provide them with
> empty bodies.
>
> tty_operations::put_char() needs not be provided if it is the same as
> tty_operations::write(tty, &ch, 1).
>
> So drop all of them.
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
> Cc: Chris Zankel <[email protected]>
> Cc: Max Filippov <[email protected]>
> ---
> arch/xtensa/platforms/iss/console.c | 24 ------------------------
> 1 file changed, 24 deletions(-)

Acked-by: Max Filippov <[email protected]>

--
Thanks.
-- Max

2023-08-11 09:37:50

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 34-and-three-quarters/36] tty: gdm724x: simplify gdm_tty_write()

On Thu, 10 Aug 2023, Jiri Slaby (SUSE) wrote:

> len and remain can never be negative in gdm_tty_write(). So remove such
> a check and move the check of remaining bytes to the loop condition.
> This way, the preceding 'if' is now superfluous too. Fix all that and
> make the code cleaner.
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>

I guess Suggested-by would be more appropriate since there's no problem
being fixed here.

> Cc: [email protected]

Reviewed-by: Ilpo J?rvinen <[email protected]>

--
i.



> ---
> drivers/staging/gdm724x/gdm_tty.c | 7 +------
> 1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
> index cbaaa8fa7474..67d9bf41e836 100644
> --- a/drivers/staging/gdm724x/gdm_tty.c
> +++ b/drivers/staging/gdm724x/gdm_tty.c
> @@ -158,10 +158,7 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
> if (!gdm_tty_ready(gdm))
> return -ENODEV;
>
> - if (!len)
> - return 0;
> -
> - while (1) {
> + while (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),
> @@ -171,8 +168,6 @@ static ssize_t gdm_tty_write(struct tty_struct *tty, const u8 *buf, size_t len)
> gdm);
> sent_len += sending_len;
> remain -= sending_len;
> - if (remain <= 0)
> - break;
> }
>
> return len;
>

2023-08-11 11:04:06

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 16/36] tty: use u8 for chars

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) <[email protected]>
> Cc: William Hubbs <[email protected]>
> Cc: Chris Brannon <[email protected]>
> Cc: Kirk Reiser <[email protected]>
> Cc: Samuel Thibault <[email protected]>
> Cc: Dmitry Torokhov <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Max Staudt <[email protected]>
> Cc: Wolfgang Grandegger <[email protected]>
> Cc: Marc Kleine-Budde <[email protected]>
> Cc: "David S. Miller" <[email protected]>
> Cc: Eric Dumazet <[email protected]>
> Cc: Jakub Kicinski <[email protected]>
> Cc: Paolo Abeni <[email protected]>
> Cc: Dario Binacchi <[email protected]>
> Cc: Andreas Koensgen <[email protected]>
> Cc: Jeremy Kerr <[email protected]>
> Cc: Matt Johnston <[email protected]>
> Cc: Liam Girdwood <[email protected]>
> Cc: Mark Brown <[email protected]>
> Cc: Jaroslav Kysela <[email protected]>
> Cc: Takashi Iwai <[email protected]>
> Cc: Peter Ujfalusi <[email protected]>
> ---
> 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?

--
i.


2023-08-11 11:06:02

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 00/36] tty: type unifications -- part I.

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.

At least for patches #1-#14,

Reviewed-by: Ilpo J?rvinen <[email protected]>

> 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(-)
>
>

--
i.

2023-08-11 12:16:41

by Alexander Gordeev

[permalink] [raw]
Subject: Re: [PATCH 27/36] tty: propagate u8 data to tty_operations::write()

On Thu, Aug 10, 2023 at 11:15:01AM +0200, Jiri Slaby (SUSE) wrote:

Hi Jiri,

> Data are now typed as u8. Propagate this change to
> tty_operations::write().
...
> drivers/s390/char/con3215.c | 3 +--
> drivers/s390/char/con3270.c | 3 +--
> drivers/s390/char/sclp_tty.c | 2 +-
> drivers/s390/char/sclp_vt220.c | 2 +-
...
> diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
> index a1fef666c9b0..16b6f430dfd3 100644
> --- a/drivers/s390/char/con3215.c
> +++ b/drivers/s390/char/con3215.c
> @@ -1021,8 +1021,7 @@ static unsigned int tty3215_write_room(struct tty_struct *tty)
> /*
> * String write routine for 3215 ttys
> */
> -static int tty3215_write(struct tty_struct *tty,
> - const unsigned char *buf, int count)
> +static int tty3215_write(struct tty_struct *tty, const u8 *buf, int count)
> {
> handle_write(tty->driver_data, buf, count);
> return count;
> diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
> index d9983550062d..123524bff734 100644
> --- a/drivers/s390/char/con3270.c
> +++ b/drivers/s390/char/con3270.c
> @@ -1803,8 +1803,7 @@ static void tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
> /*
> * String write routine for 3270 ttys
> */
> -static int tty3270_write(struct tty_struct *tty,
> - const unsigned char *buf, int count)
> +static int tty3270_write(struct tty_struct *tty, const u8 *buf, int count)
> {
> struct tty3270 *tp;
>
> diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
> index 971fbb52740b..cc0f6a97124e 100644
> --- a/drivers/s390/char/sclp_tty.c
> +++ b/drivers/s390/char/sclp_tty.c
> @@ -230,7 +230,7 @@ static int sclp_tty_write_string(const unsigned char *str, int count, int may_fa
> * routine will return the number of characters actually accepted for writing.
> */
> static int
> -sclp_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
> +sclp_tty_write(struct tty_struct *tty, const u8 *buf, int count)
> {
> if (sclp_tty_chars_count > 0) {
> sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
> diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
> index a32f34a1c6d2..44974d801c1e 100644
> --- a/drivers/s390/char/sclp_vt220.c
> +++ b/drivers/s390/char/sclp_vt220.c
> @@ -463,7 +463,7 @@ __sclp_vt220_write(const unsigned char *buf, int count, int do_schedule,
> * number of characters actually accepted for writing.
> */
> static int
> -sclp_vt220_write(struct tty_struct *tty, const unsigned char *buf, int count)
> +sclp_vt220_write(struct tty_struct *tty, const u8 *buf, int count)
> {
> return __sclp_vt220_write(buf, count, 1, 0, 1);
> }
...

In this and following patch it is only ::write() (and other) callbacks
switched to u8, while the called internal functions stay with old types.

Do you plan to follow with part II etc, or it is archs/drivers that
are expected to sort it out eventually?

(I speak for s390, but the other affected archs are in the same boat I guess).

Thanks!

2023-08-11 21:42:56

by Max Staudt

[permalink] [raw]

2023-08-11 21:45:08

by Max Staudt

[permalink] [raw]

2023-08-14 07:14:13

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 16/36] tty: use u8 for chars

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,
--
js
suse labs


2023-08-14 07:27:38

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 00/36] tty: type unifications -- part I.

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,
--
js
suse labs


2023-08-14 15:13:02

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 27/36] tty: propagate u8 data to tty_operations::write()

On Thu, Aug 10, 2023 at 11:16 AM Jiri Slaby (SUSE) <[email protected]> wrote:
> Data are now typed as u8. Propagate this change to
> tty_operations::write().
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>

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

Reviewed-by: Geert Uytterhoeven <[email protected]> # m68k
Acked-by: Geert Uytterhoeven <[email protected]> # m68k

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2023-08-14 15:43:00

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 28/36] tty: propagate u8 data to tty_operations::put_char()

On Thu, Aug 10, 2023 at 11:16 AM Jiri Slaby (SUSE) <[email protected]> wrote:
> Data are now typed as u8. Propagate this change to
> tty_operations::put_char().
>
> Signed-off-by: Jiri Slaby (SUSE) <[email protected]>

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

Reviewed-by: Geert Uytterhoeven <[email protected]> # m68k
Acked-by: Geert Uytterhoeven <[email protected]> # m68k

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2023-08-14 15:47:32

by Ilpo Järvinen

[permalink] [raw]
Subject: Re: [PATCH 00/36] tty: type unifications -- part I.

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.


--
i.

2023-08-15 20:57:32

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH 34/36] tty: gdm724x: convert counts to size_t

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) <[email protected]>
> Cc: [email protected]
> ---
> 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
>

2023-08-16 12:22:00

by David Laight

[permalink] [raw]
Subject: RE: [PATCH 34/36] tty: gdm724x: convert counts to size_t

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/[email protected]/
>
> thanks,
> --
> js
> suse labs

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

2023-08-17 22:10:14

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 34/36] tty: gdm724x: convert counts to size_t

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,
--
js
suse labs


2023-08-18 08:00:20

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 34/36] tty: gdm724x: convert counts to size_t

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/[email protected]/

thanks,
--
js
suse labs


2023-08-18 12:29:01

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 27/36] tty: propagate u8 data to tty_operations::write()

Hi,

On 11. 08. 23, 13:52, Alexander Gordeev wrote:
> On Thu, Aug 10, 2023 at 11:15:01AM +0200, Jiri Slaby (SUSE) wrote:
>
> Hi Jiri,
>
>> Data are now typed as u8. Propagate this change to
>> tty_operations::write().
> ...
>> drivers/s390/char/con3215.c | 3 +--
>> drivers/s390/char/con3270.c | 3 +--
>> drivers/s390/char/sclp_tty.c | 2 +-
>> drivers/s390/char/sclp_vt220.c | 2 +-
> ...
>> diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
>> index a1fef666c9b0..16b6f430dfd3 100644
>> --- a/drivers/s390/char/con3215.c
>> +++ b/drivers/s390/char/con3215.c
>> @@ -1021,8 +1021,7 @@ static unsigned int tty3215_write_room(struct tty_struct *tty)
>> /*
>> * String write routine for 3215 ttys
>> */
>> -static int tty3215_write(struct tty_struct *tty,
>> - const unsigned char *buf, int count)
>> +static int tty3215_write(struct tty_struct *tty, const u8 *buf, int count)
>> {
>> handle_write(tty->driver_data, buf, count);
>> return count;
>> diff --git a/drivers/s390/char/con3270.c b/drivers/s390/char/con3270.c
>> index d9983550062d..123524bff734 100644
>> --- a/drivers/s390/char/con3270.c
>> +++ b/drivers/s390/char/con3270.c
>> @@ -1803,8 +1803,7 @@ static void tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
>> /*
>> * String write routine for 3270 ttys
>> */
>> -static int tty3270_write(struct tty_struct *tty,
>> - const unsigned char *buf, int count)
>> +static int tty3270_write(struct tty_struct *tty, const u8 *buf, int count)
>> {
>> struct tty3270 *tp;
>>
>> diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
>> index 971fbb52740b..cc0f6a97124e 100644
>> --- a/drivers/s390/char/sclp_tty.c
>> +++ b/drivers/s390/char/sclp_tty.c
>> @@ -230,7 +230,7 @@ static int sclp_tty_write_string(const unsigned char *str, int count, int may_fa
>> * routine will return the number of characters actually accepted for writing.
>> */
>> static int
>> -sclp_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
>> +sclp_tty_write(struct tty_struct *tty, const u8 *buf, int count)
>> {
>> if (sclp_tty_chars_count > 0) {
>> sclp_tty_write_string(sclp_tty_chars, sclp_tty_chars_count, 0);
>> diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
>> index a32f34a1c6d2..44974d801c1e 100644
>> --- a/drivers/s390/char/sclp_vt220.c
>> +++ b/drivers/s390/char/sclp_vt220.c
>> @@ -463,7 +463,7 @@ __sclp_vt220_write(const unsigned char *buf, int count, int do_schedule,
>> * number of characters actually accepted for writing.
>> */
>> static int
>> -sclp_vt220_write(struct tty_struct *tty, const unsigned char *buf, int count)
>> +sclp_vt220_write(struct tty_struct *tty, const u8 *buf, int count)
>> {
>> return __sclp_vt220_write(buf, count, 1, 0, 1);
>> }
> ...
>
> In this and following patch it is only ::write() (and other) callbacks
> switched to u8, while the called internal functions stay with old types.
>
> Do you plan to follow with part II etc, or it is archs/drivers that
> are expected to sort it out eventually?

Yes, I would say something like part V. would do the job -- at least
that's my plan. Slowly propagating from the tty core to leafs (drivers).

> (I speak for s390, but the other affected archs are in the same boat I guess).


thanks,
--
js
suse labs