linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/35] tty cleanup for 5.14
@ 2021-05-05  9:18 Jiri Slaby
  2021-05-05  9:18 ` [PATCH 01/35] tty: remove broken r3964 line discipline Jiri Slaby
                   ` (36 more replies)
  0 siblings, 37 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Hi,

this is again a series of various TTY cleanups. The stats say: 116 files
changed, 661 insertions, 2602 deletions. The major part of the removal
is a drop of BROKEN r3964 ldisc. The rest is mostly removal of dead
code, or adaption to the current tty core state.

Jiri Slaby (35):
  tty: remove broken r3964 line discipline
  n_tty: remove n_tty_receive_char wrapper
  n_tty: remove n_tty_receive_char_fast
  n_tty: drop n_tty_receive_buf_fast
  n_tty: drop parmrk_dbl from n_tty_receive_char
  n_tty: move lnext handling
  n_tty: make n_tty_receive_char_special return void
  n_tty: do only one cp dereference in n_tty_receive_buf_standard
  n_tty: invert TTY_NORMAL condition in n_tty_receive_buf_standard
  n_tty: remove superfluous return from n_tty_receive_signal_char
  tty: make fp of tty_ldisc_ops::receive_buf{,2} const
  tty: cumulate and document tty_struct::flow* members
  tty: cumulate and document tty_struct::ctrl* members
  tty: set tty_ldisc_ops::num statically
  n_gsm: use goto-failpaths in gsm_init
  tty: make tty_ldisc_ops a param in tty_unregister_ldisc
  tty: drop tty_ldisc_ops::refcount
  tty: no checking of tty_unregister_ldisc
  tty: return void from tty_unregister_ldisc
  ti-st: use goto-failpath in st_core_init
  ti-st: use tty_write_room
  tty: make tty_operations::write_room return uint
  USB: serial: make usb_serial_driver::write_room return uint
  tty: make tty_buffer_space_avail return uint
  tty: remove tty_operations::chars_in_buffer for non-buffering
  tty: make tty_operations::chars_in_buffer return uint
  serial: make usb_serial_driver::chars_in_buffer return uint
  nozomi: simplify ntty_chars_in_buffer
  USB: serial: digi_acceleport, simplify digi_chars_in_buffer
  tty: remove empty tty_operations::flush_buffer
  tty: remove empty tty_operations::set_termios
  isdn: capi, remove optional tty ops
  isdn: capi, drop useless pr_debugs
  tty: make tty_get_byte_size available
  tty: make use of tty_get_byte_size

 Documentation/networking/caif/caif.rst      |    4 +-
 arch/alpha/kernel/srmcons.c                 |    9 +-
 arch/m68k/emu/nfcon.c                       |    2 +-
 arch/parisc/kernel/pdc_cons.c               |    8 +-
 arch/powerpc/configs/ppc6xx_defconfig       |    1 -
 arch/um/drivers/line.c                      |   15 +-
 arch/um/drivers/line.h                      |    5 +-
 arch/um/drivers/ssl.c                       |    1 -
 arch/um/drivers/stdio_console.c             |    1 -
 arch/xtensa/platforms/iss/console.c         |    9 +-
 drivers/accessibility/speakup/spk_ttyio.c   |    9 +-
 drivers/bluetooth/hci_ldisc.c               |   12 +-
 drivers/char/Kconfig                        |   13 -
 drivers/char/pcmcia/synclink_cs.c           |   24 +-
 drivers/char/ttyprintk.c                    |    2 +-
 drivers/input/serio/serport.c               |    8 +-
 drivers/ipack/devices/ipoctal.c             |    4 +-
 drivers/isdn/capi/capi.c                    |   40 +-
 drivers/misc/bcm-vk/bcm_vk_tty.c            |    2 +-
 drivers/misc/ti-st/st_core.c                |   30 +-
 drivers/mmc/core/sdio_uart.c                |    6 +-
 drivers/net/caif/caif_serial.c              |   13 +-
 drivers/net/can/slcan.c                     |   10 +-
 drivers/net/hamradio/6pack.c                |   14 +-
 drivers/net/hamradio/mkiss.c                |   13 +-
 drivers/net/ppp/ppp_async.c                 |   12 +-
 drivers/net/ppp/ppp_synctty.c               |   12 +-
 drivers/net/slip/slip.c                     |    9 +-
 drivers/net/usb/hso.c                       |    8 +-
 drivers/pps/clients/pps-ldisc.c             |   11 +-
 drivers/s390/char/con3215.c                 |    4 +-
 drivers/s390/char/sclp_rw.c                 |    4 +-
 drivers/s390/char/sclp_rw.h                 |    2 +-
 drivers/s390/char/sclp_tty.c                |    9 +-
 drivers/s390/char/sclp_vt220.c              |    9 +-
 drivers/s390/char/tty3270.c                 |   22 +-
 drivers/staging/fwserial/fwserial.c         |   14 +-
 drivers/staging/gdm724x/gdm_tty.c           |    2 +-
 drivers/staging/greybus/uart.c              |   22 +-
 drivers/tty/Makefile                        |    1 -
 drivers/tty/amiserial.c                     |   12 +-
 drivers/tty/ehv_bytechan.c                  |    4 +-
 drivers/tty/goldfish.c                      |    4 +-
 drivers/tty/hvc/hvc_console.c               |    4 +-
 drivers/tty/hvc/hvcs.c                      |    4 +-
 drivers/tty/hvc/hvsi.c                      |    6 +-
 drivers/tty/ipwireless/tty.c                |    4 +-
 drivers/tty/mips_ejtag_fdc.c                |    8 +-
 drivers/tty/moxa.c                          |   22 +-
 drivers/tty/mxser.c                         |   16 +-
 drivers/tty/n_gsm.c                         |   28 +-
 drivers/tty/n_hdlc.c                        |   14 +-
 drivers/tty/n_null.c                        |    7 +-
 drivers/tty/n_r3964.c                       | 1283 -------------------
 drivers/tty/n_tty.c                         |  201 +--
 drivers/tty/nozomi.c                        |   17 +-
 drivers/tty/pty.c                           |   85 +-
 drivers/tty/serial/8250/8250_aspeed_vuart.c |    4 +-
 drivers/tty/serial/arc_uart.c               |    2 +-
 drivers/tty/serial/cpm_uart/cpm_uart_core.c |   19 +-
 drivers/tty/serial/dz.c                     |    2 +-
 drivers/tty/serial/kgdb_nmi.c               |    2 +-
 drivers/tty/serial/mxs-auart.c              |   18 +-
 drivers/tty/serial/qcom_geni_serial.c       |   16 +-
 drivers/tty/serial/serial_core.c            |   38 +-
 drivers/tty/serial/sh-sci.c                 |   20 +-
 drivers/tty/serial/stm32-usart.c            |   32 +-
 drivers/tty/synclink_gt.c                   |   27 +-
 drivers/tty/tty_buffer.c                    |    6 +-
 drivers/tty/tty_io.c                        |   68 +-
 drivers/tty/tty_ioctl.c                     |   61 +-
 drivers/tty/tty_jobctrl.c                   |   84 +-
 drivers/tty/tty_ldisc.c                     |   26 +-
 drivers/tty/tty_port.c                      |    2 +-
 drivers/tty/ttynull.c                       |    2 +-
 drivers/tty/vcc.c                           |    8 +-
 drivers/tty/vt/keyboard.c                   |    2 +-
 drivers/tty/vt/vt.c                         |   18 +-
 drivers/usb/class/cdc-acm.c                 |   21 +-
 drivers/usb/gadget/function/u_serial.c      |   12 +-
 drivers/usb/host/xhci-dbgtty.c              |    8 +-
 drivers/usb/serial/belkin_sa.c              |   21 +-
 drivers/usb/serial/cyberjack.c              |    4 +-
 drivers/usb/serial/cypress_m8.c             |   35 +-
 drivers/usb/serial/digi_acceleport.c        |   19 +-
 drivers/usb/serial/garmin_gps.c             |    2 +-
 drivers/usb/serial/generic.c                |   12 +-
 drivers/usb/serial/io_edgeport.c            |   12 +-
 drivers/usb/serial/io_ti.c                  |   12 +-
 drivers/usb/serial/ir-usb.c                 |    6 +-
 drivers/usb/serial/keyspan.c                |    4 +-
 drivers/usb/serial/kobil_sct.c              |    4 +-
 drivers/usb/serial/mos7720.c                |   12 +-
 drivers/usb/serial/mos7840.c                |   13 +-
 drivers/usb/serial/opticon.c                |    6 +-
 drivers/usb/serial/oti6858.c                |   12 +-
 drivers/usb/serial/pl2303.c                 |   15 +-
 drivers/usb/serial/quatech2.c               |    4 +-
 drivers/usb/serial/sierra.c                 |    8 +-
 drivers/usb/serial/ti_usb_3410_5052.c       |   16 +-
 drivers/usb/serial/usb-serial.c             |    4 +-
 drivers/usb/serial/usb-wwan.h               |    4 +-
 drivers/usb/serial/usb_wwan.c               |   12 +-
 drivers/usb/serial/whiteheat.c              |    9 +-
 include/linux/n_r3964.h                     |  175 ---
 include/linux/serial_core.h                 |    2 +-
 include/linux/tty.h                         |   76 +-
 include/linux/tty_driver.h                  |   10 +-
 include/linux/tty_flip.h                    |    2 +-
 include/linux/tty_ldisc.h                   |    6 +-
 include/linux/usb/serial.h                  |    8 +-
 include/uapi/linux/n_r3964.h                |   99 --
 net/bluetooth/rfcomm/tty.c                  |    4 +-
 net/nfc/nci/uart.c                          |    7 +-
 sound/soc/codecs/cx20442.c                  |    4 +-
 sound/soc/ti/ams-delta.c                    |   11 +-
 116 files changed, 661 insertions(+), 2602 deletions(-)
 delete mode 100644 drivers/tty/n_r3964.c
 delete mode 100644 include/linux/n_r3964.h
 delete mode 100644 include/uapi/linux/n_r3964.h

-- 
2.31.1


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

* [PATCH 01/35] tty: remove broken r3964 line discipline
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
@ 2021-05-05  9:18 ` Jiri Slaby
  2021-05-05  9:26   ` Greg KH
  2021-05-05  9:18 ` [PATCH 02/35] n_tty: remove n_tty_receive_char wrapper Jiri Slaby
                   ` (35 subsequent siblings)
  36 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Noone stepped up in the past two years since it was marked as BROKEN by
commit c7084edc3f6d (tty: mark Siemens R3964 line discipline as BROKEN).
Remove the line discipline for good.

Three remarks:
* we remove also the uapi header (as noone is able to use that interface
  anyway)
* we do *not* remove the N_R3964 constant definition from tty.h, so it
  remains reserved.
* in_interrupt() check is now removed from vt's con_put_char. Noone else
  calls tty_operations::put_char from interrupt context.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 arch/powerpc/configs/ppc6xx_defconfig |    1 -
 drivers/char/Kconfig                  |   13 -
 drivers/tty/Makefile                  |    1 -
 drivers/tty/n_r3964.c                 | 1283 -------------------------
 drivers/tty/vt/vt.c                   |    2 -
 include/linux/n_r3964.h               |  175 ----
 include/uapi/linux/n_r3964.h          |   99 --
 7 files changed, 1574 deletions(-)
 delete mode 100644 drivers/tty/n_r3964.c
 delete mode 100644 include/linux/n_r3964.h
 delete mode 100644 include/uapi/linux/n_r3964.h

diff --git a/arch/powerpc/configs/ppc6xx_defconfig b/arch/powerpc/configs/ppc6xx_defconfig
index 1fd9d1260f9e..ee09f7bb6ea9 100644
--- a/arch/powerpc/configs/ppc6xx_defconfig
+++ b/arch/powerpc/configs/ppc6xx_defconfig
@@ -621,7 +621,6 @@ CONFIG_HW_RANDOM=y
 CONFIG_HW_RANDOM_VIRTIO=m
 CONFIG_NVRAM=y
 CONFIG_DTLK=m
-CONFIG_R3964=m
 CONFIG_CARDMAN_4000=m
 CONFIG_CARDMAN_4040=m
 CONFIG_IPWIRELESS=m
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index b151e0fcdeb5..52d0dd49a683 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -218,19 +218,6 @@ config XILINX_HWICAP
 
 	  If unsure, say N.
 
-config R3964
-	tristate "Siemens R3964 line discipline"
-	depends on TTY && BROKEN
-	help
-	  This driver allows synchronous communication with devices using the
-	  Siemens R3964 packet protocol. Unless you are dealing with special
-	  hardware like PLCs, you are unlikely to need this.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called n_r3964.
-
-	  If unsure, say N.
-
 config APPLICOM
 	tristate "Applicom intelligent fieldbus card support"
 	depends on PCI
diff --git a/drivers/tty/Makefile b/drivers/tty/Makefile
index c7054f5117c3..a2bd75fbaaa4 100644
--- a/drivers/tty/Makefile
+++ b/drivers/tty/Makefile
@@ -9,7 +9,6 @@ obj-$(CONFIG_AUDIT)		+= tty_audit.o
 obj-$(CONFIG_MAGIC_SYSRQ)	+= sysrq.o
 obj-$(CONFIG_N_HDLC)		+= n_hdlc.o
 obj-$(CONFIG_N_GSM)		+= n_gsm.o
-obj-$(CONFIG_R3964)		+= n_r3964.o
 
 obj-y				+= vt/
 obj-$(CONFIG_HVC_DRIVER)	+= hvc/
diff --git a/drivers/tty/n_r3964.c b/drivers/tty/n_r3964.c
deleted file mode 100644
index 2eb76ea1d88d..000000000000
--- a/drivers/tty/n_r3964.c
+++ /dev/null
@@ -1,1283 +0,0 @@
-// SPDX-License-Identifier: GPL-1.0+
-/* r3964 linediscipline for linux
- *
- * -----------------------------------------------------------
- * Copyright by 
- * Philips Automation Projects
- * Kassel (Germany)
- * -----------------------------------------------------------
- * Author:
- * L. Haag
- *
- * $Log: n_r3964.c,v $
- * Revision 1.10  2001/03/18 13:02:24  dwmw2
- * Fix timer usage, use spinlocks properly.
- *
- * Revision 1.9  2001/03/18 12:52:14  dwmw2
- * Merge changes in 2.4.2
- *
- * Revision 1.8  2000/03/23 14:14:54  dwmw2
- * Fix race in sleeping in r3964_read()
- *
- * Revision 1.7  1999/28/08 11:41:50  dwmw2
- * Port to 2.3 kernel
- *
- * Revision 1.6  1998/09/30 00:40:40  dwmw2
- * Fixed compilation on 2.0.x kernels
- * Updated to newly registered tty-ldisc number 9
- *
- * Revision 1.5  1998/09/04 21:57:36  dwmw2
- * Signal handling bug fixes, port to 2.1.x.
- *
- * Revision 1.4  1998/04/02 20:26:59  lhaag
- * select, blocking, ...
- *
- * Revision 1.3  1998/02/12 18:58:43  root
- * fixed some memory leaks
- * calculation of checksum characters
- *
- * Revision 1.2  1998/02/07 13:03:34  root
- * ioctl read_telegram
- *
- * Revision 1.1  1998/02/06 19:21:03  root
- * Initial revision
- *
- *
- */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/types.h>
-#include <linux/fcntl.h>
-#include <linux/interrupt.h>
-#include <linux/ptrace.h>
-#include <linux/ioport.h>
-#include <linux/in.h>
-#include <linux/slab.h>
-#include <linux/tty.h>
-#include <linux/errno.h>
-#include <linux/string.h>	/* used in new tty drivers */
-#include <linux/signal.h>	/* used in new tty drivers */
-#include <linux/ioctl.h>
-#include <linux/n_r3964.h>
-#include <linux/poll.h>
-#include <linux/init.h>
-#include <linux/uaccess.h>
-
-/*#define DEBUG_QUEUE*/
-
-/* Log successful handshake and protocol operations  */
-/*#define DEBUG_PROTO_S*/
-
-/* Log handshake and protocol errors: */
-/*#define DEBUG_PROTO_E*/
-
-/* Log Linediscipline operations (open, close, read, write...): */
-/*#define DEBUG_LDISC*/
-
-/* Log module and memory operations (init, cleanup; kmalloc, kfree): */
-/*#define DEBUG_MODUL*/
-
-/* Macro helpers for debug output: */
-#define TRACE(format, args...) printk("r3964: " format "\n" , ## args)
-
-#ifdef DEBUG_MODUL
-#define TRACE_M(format, args...) printk("r3964: " format "\n" , ## args)
-#else
-#define TRACE_M(fmt, arg...) do {} while (0)
-#endif
-#ifdef DEBUG_PROTO_S
-#define TRACE_PS(format, args...) printk("r3964: " format "\n" , ## args)
-#else
-#define TRACE_PS(fmt, arg...) do {} while (0)
-#endif
-#ifdef DEBUG_PROTO_E
-#define TRACE_PE(format, args...) printk("r3964: " format "\n" , ## args)
-#else
-#define TRACE_PE(fmt, arg...) do {} while (0)
-#endif
-#ifdef DEBUG_LDISC
-#define TRACE_L(format, args...) printk("r3964: " format "\n" , ## args)
-#else
-#define TRACE_L(fmt, arg...) do {} while (0)
-#endif
-#ifdef DEBUG_QUEUE
-#define TRACE_Q(format, args...) printk("r3964: " format "\n" , ## args)
-#else
-#define TRACE_Q(fmt, arg...) do {} while (0)
-#endif
-static void add_tx_queue(struct r3964_info *, struct r3964_block_header *);
-static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code);
-static void put_char(struct r3964_info *pInfo, unsigned char ch);
-static void trigger_transmit(struct r3964_info *pInfo);
-static void retry_transmit(struct r3964_info *pInfo);
-static void transmit_block(struct r3964_info *pInfo);
-static void receive_char(struct r3964_info *pInfo, const unsigned char c);
-static void receive_error(struct r3964_info *pInfo, const char flag);
-static void on_timeout(struct timer_list *t);
-static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg);
-static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
-		unsigned char __user * buf);
-static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
-		int error_code, struct r3964_block_header *pBlock);
-static struct r3964_message *remove_msg(struct r3964_info *pInfo,
-		struct r3964_client_info *pClient);
-static void remove_client_block(struct r3964_info *pInfo,
-		struct r3964_client_info *pClient);
-
-static int r3964_open(struct tty_struct *tty);
-static void r3964_close(struct tty_struct *tty);
-static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
-		void *cookie, unsigned char *buf, size_t nr);
-static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
-		const unsigned char *buf, size_t nr);
-static int r3964_ioctl(struct tty_struct *tty, struct file *file,
-		unsigned int cmd, unsigned long arg);
-#ifdef CONFIG_COMPAT
-static int r3964_compat_ioctl(struct tty_struct *tty, struct file *file,
-		unsigned int cmd, unsigned long arg);
-#endif
-static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old);
-static __poll_t r3964_poll(struct tty_struct *tty, struct file *file,
-		struct poll_table_struct *wait);
-static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
-		char *fp, int count);
-
-static struct tty_ldisc_ops tty_ldisc_N_R3964 = {
-	.owner = THIS_MODULE,
-	.name = "R3964",
-	.open = r3964_open,
-	.close = r3964_close,
-	.read = r3964_read,
-	.write = r3964_write,
-	.ioctl = r3964_ioctl,
-#ifdef CONFIG_COMPAT
-	.compat_ioctl = r3964_compat_ioctl,
-#endif
-	.set_termios = r3964_set_termios,
-	.poll = r3964_poll,
-	.receive_buf = r3964_receive_buf,
-};
-
-static void dump_block(const unsigned char *block, unsigned int length)
-{
-	unsigned int i, j;
-	char linebuf[16 * 3 + 1];
-
-	for (i = 0; i < length; i += 16) {
-		for (j = 0; (j < 16) && (j + i < length); j++) {
-			sprintf(linebuf + 3 * j, "%02x ", block[i + j]);
-		}
-		linebuf[3 * j] = '\0';
-		TRACE_PS("%s", linebuf);
-	}
-}
-
-/*************************************************************
- * Driver initialisation
- *************************************************************/
-
-/*************************************************************
- * Module support routines
- *************************************************************/
-
-static void __exit r3964_exit(void)
-{
-	int status;
-
-	TRACE_M("cleanup_module()");
-
-	status = tty_unregister_ldisc(N_R3964);
-
-	if (status != 0) {
-		printk(KERN_ERR "r3964: error unregistering linediscipline: "
-				"%d\n", status);
-	} else {
-		TRACE_L("linediscipline successfully unregistered");
-	}
-}
-
-static int __init r3964_init(void)
-{
-	int status;
-
-	printk("r3964: Philips r3964 Driver $Revision: 1.10 $\n");
-
-	/*
-	 * Register the tty line discipline
-	 */
-
-	status = tty_register_ldisc(N_R3964, &tty_ldisc_N_R3964);
-	if (status == 0) {
-		TRACE_L("line discipline %d registered", N_R3964);
-		TRACE_L("flags=%x num=%x", tty_ldisc_N_R3964.flags,
-			tty_ldisc_N_R3964.num);
-		TRACE_L("open=%p", tty_ldisc_N_R3964.open);
-		TRACE_L("tty_ldisc_N_R3964 = %p", &tty_ldisc_N_R3964);
-	} else {
-		printk(KERN_ERR "r3964: error registering line discipline: "
-				"%d\n", status);
-	}
-	return status;
-}
-
-module_init(r3964_init);
-module_exit(r3964_exit);
-
-/*************************************************************
- * Protocol implementation routines
- *************************************************************/
-
-static void add_tx_queue(struct r3964_info *pInfo,
-			 struct r3964_block_header *pHeader)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&pInfo->lock, flags);
-
-	pHeader->next = NULL;
-
-	if (pInfo->tx_last == NULL) {
-		pInfo->tx_first = pInfo->tx_last = pHeader;
-	} else {
-		pInfo->tx_last->next = pHeader;
-		pInfo->tx_last = pHeader;
-	}
-
-	spin_unlock_irqrestore(&pInfo->lock, flags);
-
-	TRACE_Q("add_tx_queue %p, length %d, tx_first = %p",
-		pHeader, pHeader->length, pInfo->tx_first);
-}
-
-static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code)
-{
-	struct r3964_block_header *pHeader;
-	unsigned long flags;
-#ifdef DEBUG_QUEUE
-	struct r3964_block_header *pDump;
-#endif
-
-	pHeader = pInfo->tx_first;
-
-	if (pHeader == NULL)
-		return;
-
-#ifdef DEBUG_QUEUE
-	printk("r3964: remove_from_tx_queue: %p, length %u - ",
-		pHeader, pHeader->length);
-	for (pDump = pHeader; pDump; pDump = pDump->next)
-		printk("%p ", pDump);
-	printk("\n");
-#endif
-
-	if (pHeader->owner) {
-		if (error_code) {
-			add_msg(pHeader->owner, R3964_MSG_ACK, 0,
-				error_code, NULL);
-		} else {
-			add_msg(pHeader->owner, R3964_MSG_ACK, pHeader->length,
-				error_code, NULL);
-		}
-		wake_up_interruptible(&pInfo->tty->read_wait);
-	}
-
-	spin_lock_irqsave(&pInfo->lock, flags);
-
-	pInfo->tx_first = pHeader->next;
-	if (pInfo->tx_first == NULL) {
-		pInfo->tx_last = NULL;
-	}
-
-	spin_unlock_irqrestore(&pInfo->lock, flags);
-
-	kfree(pHeader);
-	TRACE_M("remove_from_tx_queue - kfree %p", pHeader);
-
-	TRACE_Q("remove_from_tx_queue: tx_first = %p, tx_last = %p",
-		pInfo->tx_first, pInfo->tx_last);
-}
-
-static void add_rx_queue(struct r3964_info *pInfo,
-			 struct r3964_block_header *pHeader)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&pInfo->lock, flags);
-
-	pHeader->next = NULL;
-
-	if (pInfo->rx_last == NULL) {
-		pInfo->rx_first = pInfo->rx_last = pHeader;
-	} else {
-		pInfo->rx_last->next = pHeader;
-		pInfo->rx_last = pHeader;
-	}
-	pInfo->blocks_in_rx_queue++;
-
-	spin_unlock_irqrestore(&pInfo->lock, flags);
-
-	TRACE_Q("add_rx_queue: %p, length = %d, rx_first = %p, count = %d",
-		pHeader, pHeader->length,
-		pInfo->rx_first, pInfo->blocks_in_rx_queue);
-}
-
-static void remove_from_rx_queue(struct r3964_info *pInfo,
-				 struct r3964_block_header *pHeader)
-{
-	unsigned long flags;
-	struct r3964_block_header *pFind;
-
-	if (pHeader == NULL)
-		return;
-
-	TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
-		pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
-	TRACE_Q("remove_from_rx_queue: %p, length %u",
-		pHeader, pHeader->length);
-
-	spin_lock_irqsave(&pInfo->lock, flags);
-
-	if (pInfo->rx_first == pHeader) {
-		/* Remove the first block in the linked list: */
-		pInfo->rx_first = pHeader->next;
-
-		if (pInfo->rx_first == NULL) {
-			pInfo->rx_last = NULL;
-		}
-		pInfo->blocks_in_rx_queue--;
-	} else {
-		/* Find block to remove: */
-		for (pFind = pInfo->rx_first; pFind; pFind = pFind->next) {
-			if (pFind->next == pHeader) {
-				/* Got it. */
-				pFind->next = pHeader->next;
-				pInfo->blocks_in_rx_queue--;
-				if (pFind->next == NULL) {
-					/* Oh, removed the last one! */
-					pInfo->rx_last = pFind;
-				}
-				break;
-			}
-		}
-	}
-
-	spin_unlock_irqrestore(&pInfo->lock, flags);
-
-	kfree(pHeader);
-	TRACE_M("remove_from_rx_queue - kfree %p", pHeader);
-
-	TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
-		pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
-}
-
-static void put_char(struct r3964_info *pInfo, unsigned char ch)
-{
-	struct tty_struct *tty = pInfo->tty;
-	/* FIXME: put_char should not be called from an IRQ */
-	tty_put_char(tty, ch);
-	pInfo->bcc ^= ch;
-}
-
-static void flush(struct r3964_info *pInfo)
-{
-	struct tty_struct *tty = pInfo->tty;
-
-	if (tty == NULL || tty->ops->flush_chars == NULL)
-		return;
-	tty->ops->flush_chars(tty);
-}
-
-static void trigger_transmit(struct r3964_info *pInfo)
-{
-	unsigned long flags;
-
-	spin_lock_irqsave(&pInfo->lock, flags);
-
-	if ((pInfo->state == R3964_IDLE) && (pInfo->tx_first != NULL)) {
-		pInfo->state = R3964_TX_REQUEST;
-		pInfo->nRetry = 0;
-		pInfo->flags &= ~R3964_ERROR;
-		mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
-
-		spin_unlock_irqrestore(&pInfo->lock, flags);
-
-		TRACE_PS("trigger_transmit - sent STX");
-
-		put_char(pInfo, STX);
-		flush(pInfo);
-
-		pInfo->bcc = 0;
-	} else {
-		spin_unlock_irqrestore(&pInfo->lock, flags);
-	}
-}
-
-static void retry_transmit(struct r3964_info *pInfo)
-{
-	if (pInfo->nRetry < R3964_MAX_RETRIES) {
-		TRACE_PE("transmission failed. Retry #%d", pInfo->nRetry);
-		pInfo->bcc = 0;
-		put_char(pInfo, STX);
-		flush(pInfo);
-		pInfo->state = R3964_TX_REQUEST;
-		pInfo->nRetry++;
-		mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
-	} else {
-		TRACE_PE("transmission failed after %d retries",
-			 R3964_MAX_RETRIES);
-
-		remove_from_tx_queue(pInfo, R3964_TX_FAIL);
-
-		put_char(pInfo, NAK);
-		flush(pInfo);
-		pInfo->state = R3964_IDLE;
-
-		trigger_transmit(pInfo);
-	}
-}
-
-static void transmit_block(struct r3964_info *pInfo)
-{
-	struct tty_struct *tty = pInfo->tty;
-	struct r3964_block_header *pBlock = pInfo->tx_first;
-	int room = 0;
-
-	if (tty == NULL || pBlock == NULL) {
-		return;
-	}
-
-	room = tty_write_room(tty);
-
-	TRACE_PS("transmit_block %p, room %d, length %d",
-		 pBlock, room, pBlock->length);
-
-	while (pInfo->tx_position < pBlock->length) {
-		if (room < 2)
-			break;
-
-		if (pBlock->data[pInfo->tx_position] == DLE) {
-			/* send additional DLE char: */
-			put_char(pInfo, DLE);
-		}
-		put_char(pInfo, pBlock->data[pInfo->tx_position++]);
-
-		room--;
-	}
-
-	if ((pInfo->tx_position == pBlock->length) && (room >= 3)) {
-		put_char(pInfo, DLE);
-		put_char(pInfo, ETX);
-		if (pInfo->flags & R3964_BCC) {
-			put_char(pInfo, pInfo->bcc);
-		}
-		pInfo->state = R3964_WAIT_FOR_TX_ACK;
-		mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
-	}
-	flush(pInfo);
-}
-
-static void on_receive_block(struct r3964_info *pInfo)
-{
-	unsigned int length;
-	struct r3964_client_info *pClient;
-	struct r3964_block_header *pBlock;
-
-	length = pInfo->rx_position;
-
-	/* compare byte checksum characters: */
-	if (pInfo->flags & R3964_BCC) {
-		if (pInfo->bcc != pInfo->last_rx) {
-			TRACE_PE("checksum error - got %x but expected %x",
-				 pInfo->last_rx, pInfo->bcc);
-			pInfo->flags |= R3964_CHECKSUM;
-		}
-	}
-
-	/* check for errors (parity, overrun,...): */
-	if (pInfo->flags & R3964_ERROR) {
-		TRACE_PE("on_receive_block - transmission failed error %x",
-			 pInfo->flags & R3964_ERROR);
-
-		put_char(pInfo, NAK);
-		flush(pInfo);
-		if (pInfo->nRetry < R3964_MAX_RETRIES) {
-			pInfo->state = R3964_WAIT_FOR_RX_REPEAT;
-			pInfo->nRetry++;
-			mod_timer(&pInfo->tmr, jiffies + R3964_TO_RX_PANIC);
-		} else {
-			TRACE_PE("on_receive_block - failed after max retries");
-			pInfo->state = R3964_IDLE;
-		}
-		return;
-	}
-
-	/* received block; submit DLE: */
-	put_char(pInfo, DLE);
-	flush(pInfo);
-	del_timer_sync(&pInfo->tmr);
-	TRACE_PS(" rx success: got %d chars", length);
-
-	/* prepare struct r3964_block_header: */
-	pBlock = kmalloc(length + sizeof(struct r3964_block_header),
-			GFP_KERNEL);
-	TRACE_M("on_receive_block - kmalloc %p", pBlock);
-
-	if (pBlock == NULL)
-		return;
-
-	pBlock->length = length;
-	pBlock->data = ((unsigned char *)pBlock) +
-			sizeof(struct r3964_block_header);
-	pBlock->locks = 0;
-	pBlock->next = NULL;
-	pBlock->owner = NULL;
-
-	memcpy(pBlock->data, pInfo->rx_buf, length);
-
-	/* queue block into rx_queue: */
-	add_rx_queue(pInfo, pBlock);
-
-	/* notify attached client processes: */
-	for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
-		if (pClient->sig_flags & R3964_SIG_DATA) {
-			add_msg(pClient, R3964_MSG_DATA, length, R3964_OK,
-				pBlock);
-		}
-	}
-	wake_up_interruptible(&pInfo->tty->read_wait);
-
-	pInfo->state = R3964_IDLE;
-
-	trigger_transmit(pInfo);
-}
-
-static void receive_char(struct r3964_info *pInfo, const unsigned char c)
-{
-	switch (pInfo->state) {
-	case R3964_TX_REQUEST:
-		if (c == DLE) {
-			TRACE_PS("TX_REQUEST - got DLE");
-
-			pInfo->state = R3964_TRANSMITTING;
-			pInfo->tx_position = 0;
-
-			transmit_block(pInfo);
-		} else if (c == STX) {
-			if (pInfo->nRetry == 0) {
-				TRACE_PE("TX_REQUEST - init conflict");
-				if (pInfo->priority == R3964_SLAVE) {
-					goto start_receiving;
-				}
-			} else {
-				TRACE_PE("TX_REQUEST - secondary init "
-					"conflict!? Switching to SLAVE mode "
-					"for next rx.");
-				goto start_receiving;
-			}
-		} else {
-			TRACE_PE("TX_REQUEST - char != DLE: %x", c);
-			retry_transmit(pInfo);
-		}
-		break;
-	case R3964_TRANSMITTING:
-		if (c == NAK) {
-			TRACE_PE("TRANSMITTING - got NAK");
-			retry_transmit(pInfo);
-		} else {
-			TRACE_PE("TRANSMITTING - got invalid char");
-
-			pInfo->state = R3964_WAIT_ZVZ_BEFORE_TX_RETRY;
-			mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
-		}
-		break;
-	case R3964_WAIT_FOR_TX_ACK:
-		if (c == DLE) {
-			TRACE_PS("WAIT_FOR_TX_ACK - got DLE");
-			remove_from_tx_queue(pInfo, R3964_OK);
-
-			pInfo->state = R3964_IDLE;
-			trigger_transmit(pInfo);
-		} else {
-			retry_transmit(pInfo);
-		}
-		break;
-	case R3964_WAIT_FOR_RX_REPEAT:
-	case R3964_IDLE:
-		if (c == STX) {
-			/* Prevent rx_queue from overflow: */
-			if (pInfo->blocks_in_rx_queue >=
-			    R3964_MAX_BLOCKS_IN_RX_QUEUE) {
-				TRACE_PE("IDLE - got STX but no space in "
-						"rx_queue!");
-				pInfo->state = R3964_WAIT_FOR_RX_BUF;
-				mod_timer(&pInfo->tmr,
-					  jiffies + R3964_TO_NO_BUF);
-				break;
-			}
-start_receiving:
-			/* Ok, start receiving: */
-			TRACE_PS("IDLE - got STX");
-			pInfo->rx_position = 0;
-			pInfo->last_rx = 0;
-			pInfo->flags &= ~R3964_ERROR;
-			pInfo->state = R3964_RECEIVING;
-			mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
-			pInfo->nRetry = 0;
-			put_char(pInfo, DLE);
-			flush(pInfo);
-			pInfo->bcc = 0;
-		}
-		break;
-	case R3964_RECEIVING:
-		if (pInfo->rx_position < RX_BUF_SIZE) {
-			pInfo->bcc ^= c;
-
-			if (c == DLE) {
-				if (pInfo->last_rx == DLE) {
-					pInfo->last_rx = 0;
-					goto char_to_buf;
-				}
-				pInfo->last_rx = DLE;
-				break;
-			} else if ((c == ETX) && (pInfo->last_rx == DLE)) {
-				if (pInfo->flags & R3964_BCC) {
-					pInfo->state = R3964_WAIT_FOR_BCC;
-					mod_timer(&pInfo->tmr,
-						  jiffies + R3964_TO_ZVZ);
-				} else {
-					on_receive_block(pInfo);
-				}
-			} else {
-				pInfo->last_rx = c;
-char_to_buf:
-				pInfo->rx_buf[pInfo->rx_position++] = c;
-				mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
-			}
-		}
-		/* else: overflow-msg? BUF_SIZE>MTU; should not happen? */
-		break;
-	case R3964_WAIT_FOR_BCC:
-		pInfo->last_rx = c;
-		on_receive_block(pInfo);
-		break;
-	}
-}
-
-static void receive_error(struct r3964_info *pInfo, const char flag)
-{
-	switch (flag) {
-	case TTY_NORMAL:
-		break;
-	case TTY_BREAK:
-		TRACE_PE("received break");
-		pInfo->flags |= R3964_BREAK;
-		break;
-	case TTY_PARITY:
-		TRACE_PE("parity error");
-		pInfo->flags |= R3964_PARITY;
-		break;
-	case TTY_FRAME:
-		TRACE_PE("frame error");
-		pInfo->flags |= R3964_FRAME;
-		break;
-	case TTY_OVERRUN:
-		TRACE_PE("frame overrun");
-		pInfo->flags |= R3964_OVERRUN;
-		break;
-	default:
-		TRACE_PE("receive_error - unknown flag %d", flag);
-		pInfo->flags |= R3964_UNKNOWN;
-		break;
-	}
-}
-
-static void on_timeout(struct timer_list *t)
-{
-	struct r3964_info *pInfo = from_timer(pInfo, t, tmr);
-
-	switch (pInfo->state) {
-	case R3964_TX_REQUEST:
-		TRACE_PE("TX_REQUEST - timeout");
-		retry_transmit(pInfo);
-		break;
-	case R3964_WAIT_ZVZ_BEFORE_TX_RETRY:
-		put_char(pInfo, NAK);
-		flush(pInfo);
-		retry_transmit(pInfo);
-		break;
-	case R3964_WAIT_FOR_TX_ACK:
-		TRACE_PE("WAIT_FOR_TX_ACK - timeout");
-		retry_transmit(pInfo);
-		break;
-	case R3964_WAIT_FOR_RX_BUF:
-		TRACE_PE("WAIT_FOR_RX_BUF - timeout");
-		put_char(pInfo, NAK);
-		flush(pInfo);
-		pInfo->state = R3964_IDLE;
-		break;
-	case R3964_RECEIVING:
-		TRACE_PE("RECEIVING - timeout after %d chars",
-			 pInfo->rx_position);
-		put_char(pInfo, NAK);
-		flush(pInfo);
-		pInfo->state = R3964_IDLE;
-		break;
-	case R3964_WAIT_FOR_RX_REPEAT:
-		TRACE_PE("WAIT_FOR_RX_REPEAT - timeout");
-		pInfo->state = R3964_IDLE;
-		break;
-	case R3964_WAIT_FOR_BCC:
-		TRACE_PE("WAIT_FOR_BCC - timeout");
-		put_char(pInfo, NAK);
-		flush(pInfo);
-		pInfo->state = R3964_IDLE;
-		break;
-	}
-}
-
-static struct r3964_client_info *findClient(struct r3964_info *pInfo,
-		struct pid *pid)
-{
-	struct r3964_client_info *pClient;
-
-	for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
-		if (pClient->pid == pid) {
-			return pClient;
-		}
-	}
-	return NULL;
-}
-
-static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg)
-{
-	struct r3964_client_info *pClient;
-	struct r3964_client_info **ppClient;
-	struct r3964_message *pMsg;
-
-	if ((arg & R3964_SIG_ALL) == 0) {
-		/* Remove client from client list */
-		for (ppClient = &pInfo->firstClient; *ppClient;
-		     ppClient = &(*ppClient)->next) {
-			pClient = *ppClient;
-
-			if (pClient->pid == pid) {
-				TRACE_PS("removing client %d from client list",
-					 pid_nr(pid));
-				*ppClient = pClient->next;
-				while (pClient->msg_count) {
-					pMsg = remove_msg(pInfo, pClient);
-					if (pMsg) {
-						kfree(pMsg);
-						TRACE_M("enable_signals - msg "
-							"kfree %p", pMsg);
-					}
-				}
-				put_pid(pClient->pid);
-				kfree(pClient);
-				TRACE_M("enable_signals - kfree %p", pClient);
-				return 0;
-			}
-		}
-		return -EINVAL;
-	} else {
-		pClient = findClient(pInfo, pid);
-		if (pClient) {
-			/* update signal options */
-			pClient->sig_flags = arg;
-		} else {
-			/* add client to client list */
-			pClient = kmalloc(sizeof(struct r3964_client_info),
-					GFP_KERNEL);
-			TRACE_M("enable_signals - kmalloc %p", pClient);
-			if (pClient == NULL)
-				return -ENOMEM;
-
-			TRACE_PS("add client %d to client list", pid_nr(pid));
-			spin_lock_init(&pClient->lock);
-			pClient->sig_flags = arg;
-			pClient->pid = get_pid(pid);
-			pClient->next = pInfo->firstClient;
-			pClient->first_msg = NULL;
-			pClient->last_msg = NULL;
-			pClient->next_block_to_read = NULL;
-			pClient->msg_count = 0;
-			pInfo->firstClient = pClient;
-		}
-	}
-
-	return 0;
-}
-
-static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
-			 unsigned char __user * buf)
-{
-	struct r3964_client_info *pClient;
-	struct r3964_block_header *block;
-
-	if (!buf) {
-		return -EINVAL;
-	}
-
-	pClient = findClient(pInfo, pid);
-	if (pClient == NULL) {
-		return -EINVAL;
-	}
-
-	block = pClient->next_block_to_read;
-	if (!block) {
-		return 0;
-	} else {
-		if (copy_to_user(buf, block->data, block->length))
-			return -EFAULT;
-
-		remove_client_block(pInfo, pClient);
-		return block->length;
-	}
-
-	return -EINVAL;
-}
-
-static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
-		int error_code, struct r3964_block_header *pBlock)
-{
-	struct r3964_message *pMsg;
-	unsigned long flags;
-
-	if (pClient->msg_count < R3964_MAX_MSG_COUNT - 1) {
-queue_the_message:
-
-		pMsg = kmalloc(sizeof(struct r3964_message),
-				error_code ? GFP_ATOMIC : GFP_KERNEL);
-		TRACE_M("add_msg - kmalloc %p", pMsg);
-		if (pMsg == NULL) {
-			return;
-		}
-
-		spin_lock_irqsave(&pClient->lock, flags);
-
-		pMsg->msg_id = msg_id;
-		pMsg->arg = arg;
-		pMsg->error_code = error_code;
-		pMsg->block = pBlock;
-		pMsg->next = NULL;
-
-		if (pClient->last_msg == NULL) {
-			pClient->first_msg = pClient->last_msg = pMsg;
-		} else {
-			pClient->last_msg->next = pMsg;
-			pClient->last_msg = pMsg;
-		}
-
-		pClient->msg_count++;
-
-		if (pBlock != NULL) {
-			pBlock->locks++;
-		}
-		spin_unlock_irqrestore(&pClient->lock, flags);
-	} else {
-		if ((pClient->last_msg->msg_id == R3964_MSG_ACK)
-		    && (pClient->last_msg->error_code == R3964_OVERFLOW)) {
-			pClient->last_msg->arg++;
-			TRACE_PE("add_msg - inc prev OVERFLOW-msg");
-		} else {
-			msg_id = R3964_MSG_ACK;
-			arg = 0;
-			error_code = R3964_OVERFLOW;
-			pBlock = NULL;
-			TRACE_PE("add_msg - queue OVERFLOW-msg");
-			goto queue_the_message;
-		}
-	}
-	/* Send SIGIO signal to client process: */
-	if (pClient->sig_flags & R3964_USE_SIGIO) {
-		kill_pid(pClient->pid, SIGIO, 1);
-	}
-}
-
-static struct r3964_message *remove_msg(struct r3964_info *pInfo,
-					struct r3964_client_info *pClient)
-{
-	struct r3964_message *pMsg = NULL;
-	unsigned long flags;
-
-	if (pClient->first_msg) {
-		spin_lock_irqsave(&pClient->lock, flags);
-
-		pMsg = pClient->first_msg;
-		pClient->first_msg = pMsg->next;
-		if (pClient->first_msg == NULL) {
-			pClient->last_msg = NULL;
-		}
-
-		pClient->msg_count--;
-		if (pMsg->block) {
-			remove_client_block(pInfo, pClient);
-			pClient->next_block_to_read = pMsg->block;
-		}
-		spin_unlock_irqrestore(&pClient->lock, flags);
-	}
-	return pMsg;
-}
-
-static void remove_client_block(struct r3964_info *pInfo,
-				struct r3964_client_info *pClient)
-{
-	struct r3964_block_header *block;
-
-	TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid));
-
-	block = pClient->next_block_to_read;
-	if (block) {
-		block->locks--;
-		if (block->locks == 0) {
-			remove_from_rx_queue(pInfo, block);
-		}
-	}
-	pClient->next_block_to_read = NULL;
-}
-
-/*************************************************************
- * Line discipline routines
- *************************************************************/
-
-static int r3964_open(struct tty_struct *tty)
-{
-	struct r3964_info *pInfo;
-
-	TRACE_L("open");
-	TRACE_L("tty=%p, PID=%d, disc_data=%p",
-		tty, current->pid, tty->disc_data);
-
-	pInfo = kmalloc(sizeof(struct r3964_info), GFP_KERNEL);
-	TRACE_M("r3964_open - info kmalloc %p", pInfo);
-
-	if (!pInfo) {
-		printk(KERN_ERR "r3964: failed to alloc info structure\n");
-		return -ENOMEM;
-	}
-
-	pInfo->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
-	TRACE_M("r3964_open - rx_buf kmalloc %p", pInfo->rx_buf);
-
-	if (!pInfo->rx_buf) {
-		printk(KERN_ERR "r3964: failed to alloc receive buffer\n");
-		kfree(pInfo);
-		TRACE_M("r3964_open - info kfree %p", pInfo);
-		return -ENOMEM;
-	}
-
-	pInfo->tx_buf = kmalloc(TX_BUF_SIZE, GFP_KERNEL);
-	TRACE_M("r3964_open - tx_buf kmalloc %p", pInfo->tx_buf);
-
-	if (!pInfo->tx_buf) {
-		printk(KERN_ERR "r3964: failed to alloc transmit buffer\n");
-		kfree(pInfo->rx_buf);
-		TRACE_M("r3964_open - rx_buf kfree %p", pInfo->rx_buf);
-		kfree(pInfo);
-		TRACE_M("r3964_open - info kfree %p", pInfo);
-		return -ENOMEM;
-	}
-
-	spin_lock_init(&pInfo->lock);
-	mutex_init(&pInfo->read_lock);
-	pInfo->tty = tty;
-	pInfo->priority = R3964_MASTER;
-	pInfo->rx_first = pInfo->rx_last = NULL;
-	pInfo->tx_first = pInfo->tx_last = NULL;
-	pInfo->rx_position = 0;
-	pInfo->tx_position = 0;
-	pInfo->last_rx = 0;
-	pInfo->blocks_in_rx_queue = 0;
-	pInfo->firstClient = NULL;
-	pInfo->state = R3964_IDLE;
-	pInfo->flags = R3964_DEBUG;
-	pInfo->nRetry = 0;
-
-	tty->disc_data = pInfo;
-	tty->receive_room = 65536;
-
-	timer_setup(&pInfo->tmr, on_timeout, 0);
-
-	return 0;
-}
-
-static void r3964_close(struct tty_struct *tty)
-{
-	struct r3964_info *pInfo = tty->disc_data;
-	struct r3964_client_info *pClient, *pNext;
-	struct r3964_message *pMsg;
-	struct r3964_block_header *pHeader, *pNextHeader;
-	unsigned long flags;
-
-	TRACE_L("close");
-
-	/*
-	 * Make sure that our task queue isn't activated.  If it
-	 * is, take it out of the linked list.
-	 */
-	del_timer_sync(&pInfo->tmr);
-
-	/* Remove client-structs and message queues: */
-	pClient = pInfo->firstClient;
-	while (pClient) {
-		pNext = pClient->next;
-		while (pClient->msg_count) {
-			pMsg = remove_msg(pInfo, pClient);
-			if (pMsg) {
-				kfree(pMsg);
-				TRACE_M("r3964_close - msg kfree %p", pMsg);
-			}
-		}
-		put_pid(pClient->pid);
-		kfree(pClient);
-		TRACE_M("r3964_close - client kfree %p", pClient);
-		pClient = pNext;
-	}
-	/* Remove jobs from tx_queue: */
-	spin_lock_irqsave(&pInfo->lock, flags);
-	pHeader = pInfo->tx_first;
-	pInfo->tx_first = pInfo->tx_last = NULL;
-	spin_unlock_irqrestore(&pInfo->lock, flags);
-
-	while (pHeader) {
-		pNextHeader = pHeader->next;
-		kfree(pHeader);
-		pHeader = pNextHeader;
-	}
-
-	/* Free buffers: */
-	kfree(pInfo->rx_buf);
-	TRACE_M("r3964_close - rx_buf kfree %p", pInfo->rx_buf);
-	kfree(pInfo->tx_buf);
-	TRACE_M("r3964_close - tx_buf kfree %p", pInfo->tx_buf);
-	kfree(pInfo);
-	TRACE_M("r3964_close - info kfree %p", pInfo);
-}
-
-static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
-			  unsigned char *kbuf, size_t nr,
-			  void **cookie, unsigned long offset)
-{
-	struct r3964_info *pInfo = tty->disc_data;
-	struct r3964_client_info *pClient;
-	struct r3964_message *pMsg;
-	struct r3964_client_message theMsg;
-	int ret;
-
-	TRACE_L("read()");
-
-	/*
-	 *	Internal serialization of reads.
-	 */
-	if (file->f_flags & O_NONBLOCK) {
-		if (!mutex_trylock(&pInfo->read_lock))
-			return -EAGAIN;
-	} else {
-		if (mutex_lock_interruptible(&pInfo->read_lock))
-			return -ERESTARTSYS;
-	}
-
-	pClient = findClient(pInfo, task_pid(current));
-	if (pClient) {
-		pMsg = remove_msg(pInfo, pClient);
-		if (pMsg == NULL) {
-			/* no messages available. */
-			if (tty_io_nonblock(tty, file)) {
-				ret = -EAGAIN;
-				goto unlock;
-			}
-			/* block until there is a message: */
-			wait_event_interruptible(tty->read_wait,
-					(pMsg = remove_msg(pInfo, pClient)));
-		}
-
-		/* If we still haven't got a message, we must have been signalled */
-
-		if (!pMsg) {
-			ret = -EINTR;
-			goto unlock;
-		}
-
-		/* deliver msg to client process: */
-		theMsg.msg_id = pMsg->msg_id;
-		theMsg.arg = pMsg->arg;
-		theMsg.error_code = pMsg->error_code;
-		ret = sizeof(struct r3964_client_message);
-
-		kfree(pMsg);
-		TRACE_M("r3964_read - msg kfree %p", pMsg);
-
-		memcpy(kbuf, &theMsg, ret);
-
-		TRACE_PS("read - return %d", ret);
-		goto unlock;
-	}
-	ret = -EPERM;
-unlock:
-	mutex_unlock(&pInfo->read_lock);
-	return ret;
-}
-
-static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
-			   const unsigned char *data, size_t count)
-{
-	struct r3964_info *pInfo = tty->disc_data;
-	struct r3964_block_header *pHeader;
-	struct r3964_client_info *pClient;
-	unsigned char *new_data;
-
-	TRACE_L("write request, %d characters", count);
-/* 
- * Verify the pointers 
- */
-
-	if (!pInfo)
-		return -EIO;
-
-/*
- * Ensure that the caller does not wish to send too much.
- */
-	if (count > R3964_MTU) {
-		if (pInfo->flags & R3964_DEBUG) {
-			TRACE_L(KERN_WARNING "r3964_write: truncating user "
-				"packet from %u to mtu %d", count, R3964_MTU);
-		}
-		count = R3964_MTU;
-	}
-/*
- * Allocate a buffer for the data and copy it from the buffer with header prepended
- */
-	new_data = kmalloc(count + sizeof(struct r3964_block_header),
-			GFP_KERNEL);
-	TRACE_M("r3964_write - kmalloc %p", new_data);
-	if (new_data == NULL) {
-		if (pInfo->flags & R3964_DEBUG) {
-			printk(KERN_ERR "r3964_write: no memory\n");
-		}
-		return -ENOSPC;
-	}
-
-	pHeader = (struct r3964_block_header *)new_data;
-	pHeader->data = new_data + sizeof(struct r3964_block_header);
-	pHeader->length = count;
-	pHeader->locks = 0;
-	pHeader->owner = NULL;
-
-	pClient = findClient(pInfo, task_pid(current));
-	if (pClient) {
-		pHeader->owner = pClient;
-	}
-
-	memcpy(pHeader->data, data, count);	/* We already verified this */
-
-	if (pInfo->flags & R3964_DEBUG) {
-		dump_block(pHeader->data, count);
-	}
-
-/*
- * Add buffer to transmit-queue:
- */
-	add_tx_queue(pInfo, pHeader);
-	trigger_transmit(pInfo);
-
-	return 0;
-}
-
-static int r3964_ioctl(struct tty_struct *tty, struct file *file,
-		unsigned int cmd, unsigned long arg)
-{
-	struct r3964_info *pInfo = tty->disc_data;
-	if (pInfo == NULL)
-		return -EINVAL;
-	switch (cmd) {
-	case R3964_ENABLE_SIGNALS:
-		return enable_signals(pInfo, task_pid(current), arg);
-	case R3964_SETPRIORITY:
-		if (arg < R3964_MASTER || arg > R3964_SLAVE)
-			return -EINVAL;
-		pInfo->priority = arg & 0xff;
-		return 0;
-	case R3964_USE_BCC:
-		if (arg)
-			pInfo->flags |= R3964_BCC;
-		else
-			pInfo->flags &= ~R3964_BCC;
-		return 0;
-	case R3964_READ_TELEGRAM:
-		return read_telegram(pInfo, task_pid(current),
-				(unsigned char __user *)arg);
-	default:
-		return -ENOIOCTLCMD;
-	}
-}
-
-#ifdef CONFIG_COMPAT
-static int r3964_compat_ioctl(struct tty_struct *tty, struct file *file,
-		unsigned int cmd, unsigned long arg)
-{
-	switch (cmd) {
-	case R3964_ENABLE_SIGNALS:
-	case R3964_SETPRIORITY:
-	case R3964_USE_BCC:
-		return r3964_ioctl(tty, file, cmd, arg);
-	default:
-		return -ENOIOCTLCMD;
-	}
-}
-#endif
-
-static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old)
-{
-	TRACE_L("set_termios");
-}
-
-/* Called without the kernel lock held - fine */
-static __poll_t r3964_poll(struct tty_struct *tty, struct file *file,
-			struct poll_table_struct *wait)
-{
-	struct r3964_info *pInfo = tty->disc_data;
-	struct r3964_client_info *pClient;
-	struct r3964_message *pMsg = NULL;
-	unsigned long flags;
-	__poll_t result = EPOLLOUT;
-
-	TRACE_L("POLL");
-
-	pClient = findClient(pInfo, task_pid(current));
-	if (pClient) {
-		poll_wait(file, &tty->read_wait, wait);
-		spin_lock_irqsave(&pInfo->lock, flags);
-		pMsg = pClient->first_msg;
-		spin_unlock_irqrestore(&pInfo->lock, flags);
-		if (pMsg)
-			result |= EPOLLIN | EPOLLRDNORM;
-	} else {
-		result = -EINVAL;
-	}
-	return result;
-}
-
-static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
-			char *fp, int count)
-{
-	struct r3964_info *pInfo = tty->disc_data;
-	const unsigned char *p;
-	char *f, flags = TTY_NORMAL;
-	int i;
-
-	for (i = count, p = cp, f = fp; i; i--, p++) {
-		if (f)
-			flags = *f++;
-		if (flags == TTY_NORMAL) {
-			receive_char(pInfo, *p);
-		} else {
-			receive_error(pInfo, flags);
-		}
-
-	}
-}
-
-MODULE_LICENSE("GPL");
-MODULE_ALIAS_LDISC(N_R3964);
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 01645e87b3d5..e5040bdadcd6 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3260,8 +3260,6 @@ static int con_write(struct tty_struct *tty, const unsigned char *buf, int count
 
 static int con_put_char(struct tty_struct *tty, unsigned char ch)
 {
-	if (in_interrupt())
-		return 0;	/* n_r3964 calls put_char() from interrupt context */
 	return do_con_write(tty, &ch, 1);
 }
 
diff --git a/include/linux/n_r3964.h b/include/linux/n_r3964.h
deleted file mode 100644
index 90a803aa42e8..000000000000
--- a/include/linux/n_r3964.h
+++ /dev/null
@@ -1,175 +0,0 @@
-/* r3964 linediscipline for linux
- *
- * -----------------------------------------------------------
- * Copyright by
- * Philips Automation Projects
- * Kassel (Germany)
- * -----------------------------------------------------------
- * This software may be used and distributed according to the terms of
- * the GNU General Public License, incorporated herein by reference.
- *
- * Author:
- * L. Haag
- *
- * $Log: r3964.h,v $
- * Revision 1.4  2005/12/21 19:54:24  Kurt Huwig <kurt huwig de>
- * Fixed HZ usage on 2.6 kernels
- * Removed unnecessary include
- *
- * Revision 1.3  2001/03/18 13:02:24  dwmw2
- * Fix timer usage, use spinlocks properly.
- *
- * Revision 1.2  2001/03/18 12:53:15  dwmw2
- * Merge changes in 2.4.2
- *
- * Revision 1.1.1.1  1998/10/13 16:43:14  dwmw2
- * This'll screw the version control
- *
- * Revision 1.6  1998/09/30 00:40:38  dwmw2
- * Updated to use kernel's N_R3964 if available
- *
- * Revision 1.4  1998/04/02 20:29:44  lhaag
- * select, blocking, ...
- *
- * Revision 1.3  1998/02/12 18:58:43  root
- * fixed some memory leaks
- * calculation of checksum characters
- *
- * Revision 1.2  1998/02/07 13:03:17  root
- * ioctl read_telegram
- *
- * Revision 1.1  1998/02/06 19:19:43  root
- * Initial revision
- *
- *
- */
-#ifndef __LINUX_N_R3964_H__
-#define __LINUX_N_R3964_H__
-
-
-#include <linux/param.h>
-#include <uapi/linux/n_r3964.h>
-
-/*
- * Common ascii handshake characters:
- */
-
-#define STX 0x02
-#define ETX 0x03
-#define DLE 0x10
-#define NAK 0x15
-
-/*
- * Timeouts (from milliseconds to jiffies)
- */
-
-#define R3964_TO_QVZ ((550)*HZ/1000)
-#define R3964_TO_ZVZ ((220)*HZ/1000)
-#define R3964_TO_NO_BUF ((400)*HZ/1000)
-#define R3964_NO_TX_ROOM ((100)*HZ/1000)
-#define R3964_TO_RX_PANIC ((4000)*HZ/1000)
-#define R3964_MAX_RETRIES 5
-
-
-enum { R3964_IDLE, 
-	   R3964_TX_REQUEST, R3964_TRANSMITTING, 
-	   R3964_WAIT_ZVZ_BEFORE_TX_RETRY, R3964_WAIT_FOR_TX_ACK,
-	   R3964_WAIT_FOR_RX_BUF,
-	   R3964_RECEIVING, R3964_WAIT_FOR_BCC, R3964_WAIT_FOR_RX_REPEAT
-	   };
-
-/*
- * All open file-handles are 'clients' and are stored in a linked list:
- */
-
-struct r3964_message;
-
-struct r3964_client_info {
-	spinlock_t     lock;
-	struct pid    *pid;
-	unsigned int   sig_flags;
-
-	struct r3964_client_info *next;
-
-	struct r3964_message *first_msg;
-	struct r3964_message *last_msg;
-	struct r3964_block_header *next_block_to_read;
-	int            msg_count;
-};
-
-
-
-struct r3964_block_header;
-
-/* internal version of client_message: */
-struct r3964_message {
-	  int     msg_id;
-	  int     arg;
-	  int     error_code;
-	  struct r3964_block_header *block;
-	  struct r3964_message *next;
-};
-
-/*
- * Header of received block in rx_buf/tx_buf:
- */
-
-struct r3964_block_header 
-{
-	unsigned int length;             /* length in chars without header */
-	unsigned char *data;             /* usually data is located 
-                                        immediately behind this struct */
-	unsigned int locks;              /* only used in rx_buffer */
-	  
-    struct r3964_block_header *next;
-	struct r3964_client_info *owner;  /* =NULL in rx_buffer */
-};
-
-/*
- * If rx_buf hasn't enough space to store R3964_MTU chars,
- * we will reject all incoming STX-requests by sending NAK.
- */
-
-#define RX_BUF_SIZE    4000
-#define TX_BUF_SIZE    4000
-#define R3964_MAX_BLOCKS_IN_RX_QUEUE 100
-
-#define R3964_PARITY 0x0001
-#define R3964_FRAME  0x0002
-#define R3964_OVERRUN 0x0004
-#define R3964_UNKNOWN 0x0008
-#define R3964_BREAK   0x0010
-#define R3964_CHECKSUM 0x0020
-#define R3964_ERROR  0x003f
-#define R3964_BCC   0x4000
-#define R3964_DEBUG 0x8000
-
-
-struct r3964_info {
-	spinlock_t     lock;
-	struct tty_struct *tty;
-	unsigned char priority;
-	unsigned char *rx_buf;            /* ring buffer */
-	unsigned char *tx_buf;
-
-	struct r3964_block_header *rx_first;
-	struct r3964_block_header *rx_last;
-	struct r3964_block_header *tx_first;
-	struct r3964_block_header *tx_last;
-	unsigned int tx_position;
-        unsigned int rx_position;
-	unsigned char last_rx;
-	unsigned char bcc;
-        unsigned int  blocks_in_rx_queue;
-
-	struct mutex read_lock;		/* serialize r3964_read */
-
-	struct r3964_client_info *firstClient;
-	unsigned int state;
-	unsigned int flags;
-
-	struct timer_list tmr;
-	int nRetry;
-};
-
-#endif
diff --git a/include/uapi/linux/n_r3964.h b/include/uapi/linux/n_r3964.h
deleted file mode 100644
index 6bbd18520f30..000000000000
--- a/include/uapi/linux/n_r3964.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/* SPDX-License-Identifier: GPL-1.0+ WITH Linux-syscall-note */
-/* r3964 linediscipline for linux
- *
- * -----------------------------------------------------------
- * Copyright by
- * Philips Automation Projects
- * Kassel (Germany)
- * -----------------------------------------------------------
- * This software may be used and distributed according to the terms of
- * the GNU General Public License, incorporated herein by reference.
- *
- * Author:
- * L. Haag
- *
- * $Log: r3964.h,v $
- * Revision 1.4  2005/12/21 19:54:24  Kurt Huwig <kurt huwig de>
- * Fixed HZ usage on 2.6 kernels
- * Removed unnecessary include
- *
- * Revision 1.3  2001/03/18 13:02:24  dwmw2
- * Fix timer usage, use spinlocks properly.
- *
- * Revision 1.2  2001/03/18 12:53:15  dwmw2
- * Merge changes in 2.4.2
- *
- * Revision 1.1.1.1  1998/10/13 16:43:14  dwmw2
- * This'll screw the version control
- *
- * Revision 1.6  1998/09/30 00:40:38  dwmw2
- * Updated to use kernel's N_R3964 if available
- *
- * Revision 1.4  1998/04/02 20:29:44  lhaag
- * select, blocking, ...
- *
- * Revision 1.3  1998/02/12 18:58:43  root
- * fixed some memory leaks
- * calculation of checksum characters
- *
- * Revision 1.2  1998/02/07 13:03:17  root
- * ioctl read_telegram
- *
- * Revision 1.1  1998/02/06 19:19:43  root
- * Initial revision
- *
- *
- */
-
-#ifndef _UAPI__LINUX_N_R3964_H__
-#define _UAPI__LINUX_N_R3964_H__
-
-/* line disciplines for r3964 protocol */
-
-
-/*
- * Ioctl-commands
- */
-
-#define R3964_ENABLE_SIGNALS      0x5301
-#define R3964_SETPRIORITY         0x5302
-#define R3964_USE_BCC             0x5303
-#define R3964_READ_TELEGRAM       0x5304
-
-/* Options for R3964_SETPRIORITY */
-#define R3964_MASTER   0
-#define R3964_SLAVE    1
-
-/* Options for R3964_ENABLE_SIGNALS */
-#define R3964_SIG_ACK   0x0001
-#define R3964_SIG_DATA  0x0002
-#define R3964_SIG_ALL   0x000f
-#define R3964_SIG_NONE  0x0000
-#define R3964_USE_SIGIO 0x1000
-
-/*
- * r3964 operation states:
- */
-
-/* types for msg_id: */
-enum {R3964_MSG_ACK=1, R3964_MSG_DATA };
-
-#define R3964_MAX_MSG_COUNT 32
-
-/* error codes for client messages */
-#define R3964_OK 0        /* no error. */
-#define R3964_TX_FAIL -1  /* transmission error, block NOT sent */
-#define R3964_OVERFLOW -2 /* msg queue overflow */
-
-/* the client gets this struct when calling read(fd,...): */
-struct r3964_client_message {
-	  int     msg_id;
-	  int     arg;
-	  int     error_code;
-};
-
-#define R3964_MTU      256
-
-
-
-#endif /* _UAPI__LINUX_N_R3964_H__ */
-- 
2.31.1


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

* [PATCH 02/35] n_tty: remove n_tty_receive_char wrapper
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
  2021-05-05  9:18 ` [PATCH 01/35] tty: remove broken r3964 line discipline Jiri Slaby
@ 2021-05-05  9:18 ` Jiri Slaby
  2021-05-05  9:18 ` [PATCH 03/35] n_tty: remove n_tty_receive_char_fast Jiri Slaby
                   ` (34 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

The wrapper was meant as an optimization in commits eb3e4668bd9e (n_tty:
Un-inline slow-path n_tty_receive_char()) and e60d27c4d8b3 (n_tty:
Factor LNEXT processing from per-char i/o path). But the current
compiler (gcc 10) inlines it anyway (as expected). Actually, I'm not
sure it ever didn't. It would need to be marked with the noinline
attribute.

So remove this useless wrapper.

And if we ever introduce something similar, we need confirming numbers
first.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 9686c5d10571..0a8c9440f5d2 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1401,7 +1401,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 }
 
 static inline void
-n_tty_receive_char_inline(struct tty_struct *tty, unsigned char c)
+n_tty_receive_char(struct tty_struct *tty, unsigned char c)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 
@@ -1423,11 +1423,6 @@ n_tty_receive_char_inline(struct tty_struct *tty, unsigned char c)
 	put_tty_queue(c, ldata);
 }
 
-static void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
-{
-	n_tty_receive_char_inline(tty, c);
-}
-
 static inline void
 n_tty_receive_char_fast(struct tty_struct *tty, unsigned char c)
 {
@@ -1577,7 +1572,7 @@ n_tty_receive_buf_standard(struct tty_struct *tty, const unsigned char *cp,
 				continue;
 			}
 			if (!test_bit(c, ldata->char_map))
-				n_tty_receive_char_inline(tty, c);
+				n_tty_receive_char(tty, c);
 			else if (n_tty_receive_char_special(tty, c) && count) {
 				if (fp)
 					flag = *fp++;
-- 
2.31.1


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

* [PATCH 03/35] n_tty: remove n_tty_receive_char_fast
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
  2021-05-05  9:18 ` [PATCH 01/35] tty: remove broken r3964 line discipline Jiri Slaby
  2021-05-05  9:18 ` [PATCH 02/35] n_tty: remove n_tty_receive_char wrapper Jiri Slaby
@ 2021-05-05  9:18 ` Jiri Slaby
  2021-05-05  9:18 ` [PATCH 04/35] n_tty: drop n_tty_receive_buf_fast Jiri Slaby
                   ` (33 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

n_tty_receive_char_fast is a copy of n_tty_receive_char with one
exception: PARMRK is not doubled in the former. Unify these two and
double PARMRK depending on a newly added parameter (bool parmrk_dbl).

I don't think the theoretical speedup is worth the code duplication.
Which is directly connected with maintenance burden.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 32 ++++++--------------------------
 1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 0a8c9440f5d2..0adc79bae839 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1400,8 +1400,8 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 	return 0;
 }
 
-static inline void
-n_tty_receive_char(struct tty_struct *tty, unsigned char c)
+static void n_tty_receive_char(struct tty_struct *tty, unsigned char c,
+		bool parmrk_dbl)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 
@@ -1418,31 +1418,11 @@ n_tty_receive_char(struct tty_struct *tty, unsigned char c)
 		commit_echoes(tty);
 	}
 	/* PARMRK doubling check */
-	if (c == (unsigned char) '\377' && I_PARMRK(tty))
+	if (parmrk_dbl && c == (unsigned char) '\377' && I_PARMRK(tty))
 		put_tty_queue(c, ldata);
 	put_tty_queue(c, ldata);
 }
 
-static inline void
-n_tty_receive_char_fast(struct tty_struct *tty, unsigned char c)
-{
-	struct n_tty_data *ldata = tty->disc_data;
-
-	if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) {
-		start_tty(tty);
-		process_echoes(tty);
-	}
-	if (L_ECHO(tty)) {
-		finish_erasing(ldata);
-		/* Record the column of first canon char. */
-		if (ldata->canon_head == ldata->read_head)
-			echo_set_canon_col(ldata);
-		echo_char(c, tty);
-		commit_echoes(tty);
-	}
-	put_tty_queue(c, ldata);
-}
-
 static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c)
 {
 	if (I_ISTRIP(tty))
@@ -1494,7 +1474,7 @@ n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag)
 			c &= 0x7f;
 		if (I_IUCLC(tty) && L_IEXTEN(tty))
 			c = tolower(c);
-		n_tty_receive_char(tty, c);
+		n_tty_receive_char(tty, c, true);
 	} else
 		n_tty_receive_char_flagged(tty, c, flag);
 }
@@ -1572,7 +1552,7 @@ n_tty_receive_buf_standard(struct tty_struct *tty, const unsigned char *cp,
 				continue;
 			}
 			if (!test_bit(c, ldata->char_map))
-				n_tty_receive_char(tty, c);
+				n_tty_receive_char(tty, c, true);
 			else if (n_tty_receive_char_special(tty, c) && count) {
 				if (fp)
 					flag = *fp++;
@@ -1598,7 +1578,7 @@ n_tty_receive_buf_fast(struct tty_struct *tty, const unsigned char *cp,
 			unsigned char c = *cp++;
 
 			if (!test_bit(c, ldata->char_map))
-				n_tty_receive_char_fast(tty, c);
+				n_tty_receive_char(tty, c, false);
 			else if (n_tty_receive_char_special(tty, c) && count) {
 				if (fp)
 					flag = *fp++;
-- 
2.31.1


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

* [PATCH 04/35] n_tty: drop n_tty_receive_buf_fast
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (2 preceding siblings ...)
  2021-05-05  9:18 ` [PATCH 03/35] n_tty: remove n_tty_receive_char_fast Jiri Slaby
@ 2021-05-05  9:18 ` Jiri Slaby
  2021-05-05  9:18 ` [PATCH 05/35] n_tty: drop parmrk_dbl from n_tty_receive_char Jiri Slaby
                   ` (32 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

After the previous patches, n_tty_receive_buf_standard and
n_tty_receive_buf_fast differ only in handling of tty line and input
controls. Unlike n_tty_receive_buf_fast, n_tty_receive_buf_standard
handles them all (I_ISTRIP, I_IUCLC, L_IEXTEN, L_EXTPROC, and I_PARMRK).

So remove n_tty_receive_buf_fast and let n_tty_receive_buf_standard do
the handling. Actually most of the tests are only moved from
__receive_buf to n_tty_receive_buf_standard.

Again, the code duplication is not worth the theoretical speedup.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 36 +++---------------------------------
 1 file changed, 3 insertions(+), 33 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 0adc79bae839..5d83fb5412fd 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1530,9 +1530,8 @@ 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,
-			  char *fp, int count)
+static void n_tty_receive_buf_standard(struct tty_struct *tty,
+		const unsigned char *cp, char *fp, int count)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 	char flag = TTY_NORMAL;
@@ -1564,32 +1563,6 @@ n_tty_receive_buf_standard(struct tty_struct *tty, const unsigned char *cp,
 	}
 }
 
-static void
-n_tty_receive_buf_fast(struct tty_struct *tty, const unsigned char *cp,
-		       char *fp, int count)
-{
-	struct n_tty_data *ldata = tty->disc_data;
-	char flag = TTY_NORMAL;
-
-	while (count--) {
-		if (fp)
-			flag = *fp++;
-		if (likely(flag == TTY_NORMAL)) {
-			unsigned char c = *cp++;
-
-			if (!test_bit(c, ldata->char_map))
-				n_tty_receive_char(tty, c, false);
-			else if (n_tty_receive_char_special(tty, c) && count) {
-				if (fp)
-					flag = *fp++;
-				n_tty_receive_char_lnext(tty, *cp++, flag);
-				count--;
-			}
-		} else
-			n_tty_receive_char_flagged(tty, *cp++, flag);
-	}
-}
-
 static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
 			  char *fp, int count)
 {
@@ -1612,10 +1585,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
 			count--;
 		}
 
-		if (!preops && !I_PARMRK(tty))
-			n_tty_receive_buf_fast(tty, cp, fp, count);
-		else
-			n_tty_receive_buf_standard(tty, cp, fp, count);
+		n_tty_receive_buf_standard(tty, cp, fp, count);
 
 		flush_echoes(tty);
 		if (tty->ops->flush_chars)
-- 
2.31.1


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

* [PATCH 05/35] n_tty: drop parmrk_dbl from n_tty_receive_char
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (3 preceding siblings ...)
  2021-05-05  9:18 ` [PATCH 04/35] n_tty: drop n_tty_receive_buf_fast Jiri Slaby
@ 2021-05-05  9:18 ` Jiri Slaby
  2021-05-05  9:18 ` [PATCH 06/35] n_tty: move lnext handling Jiri Slaby
                   ` (31 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

After the previous cleanup patches, parmrk_dbl parameter is always true
-- I_PARMRK is checked only in n_tty_receive_char now. So remove
parmrk_dbl completely.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 5d83fb5412fd..f0db3f41df83 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1400,8 +1400,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 	return 0;
 }
 
-static void n_tty_receive_char(struct tty_struct *tty, unsigned char c,
-		bool parmrk_dbl)
+static void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 
@@ -1418,7 +1417,7 @@ static void n_tty_receive_char(struct tty_struct *tty, unsigned char c,
 		commit_echoes(tty);
 	}
 	/* PARMRK doubling check */
-	if (parmrk_dbl && c == (unsigned char) '\377' && I_PARMRK(tty))
+	if (c == (unsigned char) '\377' && I_PARMRK(tty))
 		put_tty_queue(c, ldata);
 	put_tty_queue(c, ldata);
 }
@@ -1474,7 +1473,7 @@ n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag)
 			c &= 0x7f;
 		if (I_IUCLC(tty) && L_IEXTEN(tty))
 			c = tolower(c);
-		n_tty_receive_char(tty, c, true);
+		n_tty_receive_char(tty, c);
 	} else
 		n_tty_receive_char_flagged(tty, c, flag);
 }
@@ -1551,7 +1550,7 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
 				continue;
 			}
 			if (!test_bit(c, ldata->char_map))
-				n_tty_receive_char(tty, c, true);
+				n_tty_receive_char(tty, c);
 			else if (n_tty_receive_char_special(tty, c) && count) {
 				if (fp)
 					flag = *fp++;
-- 
2.31.1


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

* [PATCH 06/35] n_tty: move lnext handling
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (4 preceding siblings ...)
  2021-05-05  9:18 ` [PATCH 05/35] n_tty: drop parmrk_dbl from n_tty_receive_char Jiri Slaby
@ 2021-05-05  9:18 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 07/35] n_tty: make n_tty_receive_char_special return void Jiri Slaby
                   ` (30 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:18 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Move lnext handling from __receive_buf to n_tty_receive_buf_standard. It
simplifies the handling as it needs not fetching 'flag' and decrement
'count' in __receive_buf. Instead, all this is left up to the loop in
n_tty_receive_buf_standard which already does that.

This way, no need to repeat the action when n_tty_receive_char_special
returns true -- ldata->lnext is set there in that case, so the 'if
(ldata->lnext)' check is sufficient. The next patch will switch
n_tty_receive_char_special to return 'void'.

The result is much simplified code flow.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index f0db3f41df83..d40844b7a4fb 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1538,6 +1538,12 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
 	while (count--) {
 		if (fp)
 			flag = *fp++;
+
+		if (ldata->lnext) {
+			n_tty_receive_char_lnext(tty, *cp++, flag);
+			continue;
+		}
+
 		if (likely(flag == TTY_NORMAL)) {
 			unsigned char c = *cp++;
 
@@ -1551,12 +1557,8 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
 			}
 			if (!test_bit(c, ldata->char_map))
 				n_tty_receive_char(tty, c);
-			else if (n_tty_receive_char_special(tty, c) && count) {
-				if (fp)
-					flag = *fp++;
-				n_tty_receive_char_lnext(tty, *cp++, flag);
-				count--;
-			}
+			else
+				n_tty_receive_char_special(tty, c);
 		} else
 			n_tty_receive_char_flagged(tty, *cp++, flag);
 	}
@@ -1575,15 +1577,6 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
 	else if (tty->closing && !L_EXTPROC(tty))
 		n_tty_receive_buf_closing(tty, cp, fp, count);
 	else {
-		if (ldata->lnext) {
-			char flag = TTY_NORMAL;
-
-			if (fp)
-				flag = *fp++;
-			n_tty_receive_char_lnext(tty, *cp++, flag);
-			count--;
-		}
-
 		n_tty_receive_buf_standard(tty, cp, fp, count);
 
 		flush_echoes(tty);
-- 
2.31.1


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

* [PATCH 07/35] n_tty: make n_tty_receive_char_special return void
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (5 preceding siblings ...)
  2021-05-05  9:18 ` [PATCH 06/35] n_tty: move lnext handling Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 08/35] n_tty: do only one cp dereference in n_tty_receive_buf_standard Jiri Slaby
                   ` (29 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

After the previous patch, noone cares about the return value of
n_tty_receive_char_special. ldata->lnext is checked instead.

So switch return type of n_tty_receive_char_special to void.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index d40844b7a4fb..b8f981499465 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1260,12 +1260,8 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c)
  *	n_tty_receive_buf()/producer path:
  *		caller holds non-exclusive termios_rwsem
  *		publishes canon_head if canonical mode is active
- *
- *	Returns 1 if LNEXT was received, else returns 0
  */
-
-static int
-n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
+static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 
@@ -1273,24 +1269,24 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 		if (c == START_CHAR(tty)) {
 			start_tty(tty);
 			process_echoes(tty);
-			return 0;
+			return;
 		}
 		if (c == STOP_CHAR(tty)) {
 			stop_tty(tty);
-			return 0;
+			return;
 		}
 	}
 
 	if (L_ISIG(tty)) {
 		if (c == INTR_CHAR(tty)) {
 			n_tty_receive_signal_char(tty, SIGINT, c);
-			return 0;
+			return;
 		} else if (c == QUIT_CHAR(tty)) {
 			n_tty_receive_signal_char(tty, SIGQUIT, c);
-			return 0;
+			return;
 		} else if (c == SUSP_CHAR(tty)) {
 			n_tty_receive_signal_char(tty, SIGTSTP, c);
-			return 0;
+			return;
 		}
 	}
 
@@ -1301,7 +1297,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 
 	if (c == '\r') {
 		if (I_IGNCR(tty))
-			return 0;
+			return;
 		if (I_ICRNL(tty))
 			c = '\n';
 	} else if (c == '\n' && I_INLCR(tty))
@@ -1312,7 +1308,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 		    (c == WERASE_CHAR(tty) && L_IEXTEN(tty))) {
 			eraser(c, tty);
 			commit_echoes(tty);
-			return 0;
+			return;
 		}
 		if (c == LNEXT_CHAR(tty) && L_IEXTEN(tty)) {
 			ldata->lnext = 1;
@@ -1324,7 +1320,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 					commit_echoes(tty);
 				}
 			}
-			return 1;
+			return;
 		}
 		if (c == REPRINT_CHAR(tty) && L_ECHO(tty) && L_IEXTEN(tty)) {
 			size_t tail = ldata->canon_head;
@@ -1337,7 +1333,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 				tail++;
 			}
 			commit_echoes(tty);
-			return 0;
+			return;
 		}
 		if (c == '\n') {
 			if (L_ECHO(tty) || L_ECHONL(tty)) {
@@ -1375,7 +1371,7 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 			smp_store_release(&ldata->canon_head, ldata->read_head);
 			kill_fasync(&tty->fasync, SIGIO, POLL_IN);
 			wake_up_interruptible_poll(&tty->read_wait, EPOLLIN);
-			return 0;
+			return;
 		}
 	}
 
@@ -1397,7 +1393,6 @@ n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 		put_tty_queue(c, ldata);
 
 	put_tty_queue(c, ldata);
-	return 0;
 }
 
 static void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
-- 
2.31.1


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

* [PATCH 08/35] n_tty: do only one cp dereference in n_tty_receive_buf_standard
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (6 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 07/35] n_tty: make n_tty_receive_char_special return void Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 09/35] n_tty: invert TTY_NORMAL condition " Jiri Slaby
                   ` (28 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

It might be confusing for readers: there are three distinct dereferences
and increments of 'cp' in n_tty_receive_buf_standard. Do it on a single
place, along with/before the 'fp' dereference.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index b8f981499465..e7c9dce14f88 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1531,17 +1531,17 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
 	char flag = TTY_NORMAL;
 
 	while (count--) {
+		unsigned char c = *cp++;
+
 		if (fp)
 			flag = *fp++;
 
 		if (ldata->lnext) {
-			n_tty_receive_char_lnext(tty, *cp++, flag);
+			n_tty_receive_char_lnext(tty, c, flag);
 			continue;
 		}
 
 		if (likely(flag == TTY_NORMAL)) {
-			unsigned char c = *cp++;
-
 			if (I_ISTRIP(tty))
 				c &= 0x7f;
 			if (I_IUCLC(tty) && L_IEXTEN(tty))
@@ -1555,7 +1555,7 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
 			else
 				n_tty_receive_char_special(tty, c);
 		} else
-			n_tty_receive_char_flagged(tty, *cp++, flag);
+			n_tty_receive_char_flagged(tty, c, flag);
 	}
 }
 
-- 
2.31.1


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

* [PATCH 09/35] n_tty: invert TTY_NORMAL condition in n_tty_receive_buf_standard
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (7 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 08/35] n_tty: do only one cp dereference in n_tty_receive_buf_standard Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 10/35] n_tty: remove superfluous return from n_tty_receive_signal_char Jiri Slaby
                   ` (27 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Handle !TTY_NORMAL as a short path and 'continue' the loop. Do the rest as
a normal code flow. This decreases the indentation level by one and
makes the code flow more understandable.

IOW, we avoid
  if (cond) {
    LONG CODE;
  } else
    single_line();
by
  if (!cond) {
    single_line();
    continue;
  }
  LONG CODE;

While at it, invert also the 'if (!test_bit) A else B' into 'if
(test_bit) B else A'.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index e7c9dce14f88..01883e5c8bbd 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1541,21 +1541,24 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
 			continue;
 		}
 
-		if (likely(flag == TTY_NORMAL)) {
-			if (I_ISTRIP(tty))
-				c &= 0x7f;
-			if (I_IUCLC(tty) && L_IEXTEN(tty))
-				c = tolower(c);
-			if (L_EXTPROC(tty)) {
-				put_tty_queue(c, ldata);
-				continue;
-			}
-			if (!test_bit(c, ldata->char_map))
-				n_tty_receive_char(tty, c);
-			else
-				n_tty_receive_char_special(tty, c);
-		} else
+		if (unlikely(flag != TTY_NORMAL)) {
 			n_tty_receive_char_flagged(tty, c, flag);
+			continue;
+		}
+
+		if (I_ISTRIP(tty))
+			c &= 0x7f;
+		if (I_IUCLC(tty) && L_IEXTEN(tty))
+			c = tolower(c);
+		if (L_EXTPROC(tty)) {
+			put_tty_queue(c, ldata);
+			continue;
+		}
+
+		if (test_bit(c, ldata->char_map))
+			n_tty_receive_char_special(tty, c);
+		else
+			n_tty_receive_char(tty, c);
 	}
 }
 
-- 
2.31.1


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

* [PATCH 10/35] n_tty: remove superfluous return from n_tty_receive_signal_char
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (8 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 09/35] n_tty: invert TTY_NORMAL condition " Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 11/35] tty: make fp of tty_ldisc_ops::receive_buf{,2} const Jiri Slaby
                   ` (26 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

A return at the end of a void-returning function is superfluous. Get rid
of it.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 01883e5c8bbd..0d93be26c678 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1245,7 +1245,6 @@ n_tty_receive_signal_char(struct tty_struct *tty, int signal, unsigned char c)
 		commit_echoes(tty);
 	} else
 		process_echoes(tty);
-	return;
 }
 
 /**
-- 
2.31.1


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

* [PATCH 11/35] tty: make fp of tty_ldisc_ops::receive_buf{,2} const
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (9 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 10/35] n_tty: remove superfluous return from n_tty_receive_signal_char Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 12/35] tty: cumulate and document tty_struct::flow* members Jiri Slaby
                   ` (25 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, William Hubbs,
	Chris Brannon, Kirk Reiser, Samuel Thibault, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Dmitry Torokhov,
	Arnd Bergmann, David S. Miller, Jakub Kicinski,
	Wolfgang Grandegger, Marc Kleine-Budde, Andreas Koensgen,
	Paul Mackerras, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Peter Ujfalusi

Char pointer (cp) passed to tty_ldisc_ops::receive_buf{,2} is const.
There is no reason for flag pointer (fp) not to be too. So switch it in
the definition and all uses.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: William Hubbs <w.d.hubbs@gmail.com>
Cc: Chris Brannon <chris@the-brannons.com>
Cc: Kirk Reiser <kirk@reisers.ca>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Andreas Koensgen <ajk@comnets.uni-bremen.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
---
 drivers/accessibility/speakup/spk_ttyio.c |  3 ++-
 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/slcan.c                   |  3 ++-
 drivers/net/hamradio/6pack.c              |  2 +-
 drivers/net/hamradio/mkiss.c              |  2 +-
 drivers/net/ppp/ppp_async.c               |  6 +++---
 drivers/net/ppp/ppp_synctty.c             |  6 +++---
 drivers/net/slip/slip.c                   |  2 +-
 drivers/tty/n_gsm.c                       |  2 +-
 drivers/tty/n_hdlc.c                      |  2 +-
 drivers/tty/n_null.c                      |  2 +-
 drivers/tty/n_tty.c                       | 16 ++++++++--------
 drivers/tty/tty_buffer.c                  |  4 ++--
 include/linux/tty.h                       |  2 +-
 include/linux/tty_ldisc.h                 |  4 ++--
 net/nfc/nci/uart.c                        |  2 +-
 sound/soc/codecs/cx20442.c                |  4 ++--
 sound/soc/ti/ams-delta.c                  |  4 ++--
 21 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index 2e39fcf492d8..b7fd094700d9 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -72,7 +72,8 @@ static void spk_ttyio_ldisc_close(struct tty_struct *tty)
 }
 
 static int spk_ttyio_receive_buf2(struct tty_struct *tty,
-				  const unsigned char *cp, char *fp, int count)
+				  const unsigned char *cp,
+				  const char *fp, int 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 71a4ca505e09..e785851a92c1 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -593,7 +593,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,
-				 char *flags, int count)
+				 const char *flags, int count)
 {
 	struct hci_uart *hu = tty->disc_data;
 
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 33e9d9bfd036..ff3715315592 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -114,7 +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, char *fp, int count)
+static void serport_ldisc_receive(struct tty_struct *tty,
+		const unsigned char *cp, const char *fp, int count)
 {
 	struct serport *serport = (struct 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 071844b58073..239a75502cd6 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -798,7 +798,7 @@ static void st_tty_close(struct tty_struct *tty)
 }
 
 static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
-			   char *tty_flags, int count)
+			   const char *tty_flags, int 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 da6fffb4d5a8..fb3ca4e11fe5 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,
-			char *flags, int count)
+			const char *flags, int count)
 {
 	struct sk_buff *skb = NULL;
 	struct ser_device *ser;
diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
index 31ba6664503d..7dc3e79cb5c4 100644
--- a/drivers/net/can/slcan.c
+++ b/drivers/net/can/slcan.c
@@ -467,7 +467,8 @@ static void slc_setup(struct net_device *dev)
  */
 
 static void slcan_receive_buf(struct tty_struct *tty,
-			      const unsigned char *cp, char *fp, int count)
+			      const unsigned char *cp, const char *fp,
+			      int count)
 {
 	struct slcan *sl = (struct slcan *) tty->disc_data;
 
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 80f41945709f..c0a80f04dd8e 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, char *fp, int count)
+	const unsigned char *cp, const char *fp, int count)
 {
 	struct sixpack *sp;
 	int count1;
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index 65154224d5b8..fc05ded48178 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -871,7 +871,7 @@ static int mkiss_ioctl(struct tty_struct *tty, struct file *file,
  * and sent on to the AX.25 layer for further processing.
  */
 static void mkiss_receive_buf(struct tty_struct *tty, const unsigned char *cp,
-	char *fp, int count)
+	const char *fp, int count)
 {
 	struct mkiss *ax = mkiss_get(tty);
 
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index 8b41aa3fb64e..9f08bd19551f 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -98,7 +98,7 @@ static int ppp_async_send(struct ppp_channel *chan, struct sk_buff *skb);
 static int ppp_async_push(struct asyncppp *ap);
 static void ppp_async_flush_output(struct asyncppp *ap);
 static void ppp_async_input(struct asyncppp *ap, const unsigned char *buf,
-			    char *flags, int count);
+			    const char *flags, int count);
 static int ppp_async_ioctl(struct ppp_channel *chan, unsigned int cmd,
 			   unsigned long arg);
 static void ppp_async_process(struct tasklet_struct *t);
@@ -340,7 +340,7 @@ ppp_asynctty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
 /* 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,
-		  char *cflags, int count)
+		  const char *cflags, int count)
 {
 	struct asyncppp *ap = ap_get(tty);
 	unsigned long flags;
@@ -829,7 +829,7 @@ process_input_packet(struct asyncppp *ap)
 
 static void
 ppp_async_input(struct asyncppp *ap, const unsigned char *buf,
-		char *flags, int count)
+		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 576b6a93bf23..c82c4e6df4cb 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -94,7 +94,7 @@ 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,
-			   char *flags, int count);
+			   const char *flags, int count);
 
 static const struct ppp_channel_ops sync_ops = {
 	.start_xmit = ppp_sync_send,
@@ -333,7 +333,7 @@ ppp_sync_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
 /* 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,
-		  char *cflags, int count)
+		  const char *cflags, int count)
 {
 	struct syncppp *ap = sp_get(tty);
 	unsigned long flags;
@@ -665,7 +665,7 @@ ppp_sync_flush_output(struct syncppp *ap)
  */
 static void
 ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
-		char *flags, int count)
+		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 1ab124eba8eb..4dda49e61745 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)
  */
 
 static void slip_receive_buf(struct tty_struct *tty, const unsigned char *cp,
-							char *fp, int count)
+		const char *fp, int count)
 {
 	struct slip *sl = tty->disc_data;
 
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 5fea02cfb0cc..477403ecc445 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2424,7 +2424,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,
-			      char *fp, int count)
+			      const char *fp, int 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 b0f33e8ac819..62b1d1a6e0f1 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -358,7 +358,7 @@ 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,
-			       char *flags, int count)
+			       const char *flags, int count)
 {
 	register struct n_hdlc *n_hdlc = tty->disc_data;
 	register struct n_hdlc_buf *buf;
diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c
index b8f67b5f1ef8..2ff373d2f98d 100644
--- a/drivers/tty/n_null.c
+++ b/drivers/tty/n_null.c
@@ -33,7 +33,7 @@ static ssize_t n_null_write(struct tty_struct *tty, struct file *file,
 }
 
 static void n_null_receivebuf(struct tty_struct *tty,
-				 const unsigned char *cp, char *fp,
+				 const unsigned char *cp, const char *fp,
 				 int cnt)
 {
 }
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 0d93be26c678..c32318da5190 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1474,7 +1474,7 @@ n_tty_receive_char_lnext(struct tty_struct *tty, unsigned char c, char flag)
 
 static void
 n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp,
-			   char *fp, int count)
+			   const char *fp, int count)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 	size_t n, head;
@@ -1494,7 +1494,7 @@ n_tty_receive_buf_real_raw(struct tty_struct *tty, const unsigned char *cp,
 
 static void
 n_tty_receive_buf_raw(struct tty_struct *tty, const unsigned char *cp,
-		      char *fp, int count)
+		      const char *fp, int count)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 	char flag = TTY_NORMAL;
@@ -1511,7 +1511,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,
-			  char *fp, int count)
+			  const char *fp, int count)
 {
 	char flag = TTY_NORMAL;
 
@@ -1524,7 +1524,7 @@ 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, char *fp, int count)
+		const unsigned char *cp, const char *fp, int count)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 	char flag = TTY_NORMAL;
@@ -1562,7 +1562,7 @@ static void n_tty_receive_buf_standard(struct tty_struct *tty,
 }
 
 static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
-			  char *fp, int count)
+			  const char *fp, int count)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 	bool preops = I_ISTRIP(tty) || (I_IUCLC(tty) && L_IEXTEN(tty));
@@ -1629,7 +1629,7 @@ static void __receive_buf(struct tty_struct *tty, const unsigned char *cp,
  */
 static int
 n_tty_receive_buf_common(struct tty_struct *tty, const unsigned char *cp,
-			 char *fp, int count, int flow)
+			 const char *fp, int count, int flow)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 	int room, n, rcvd = 0, overflow;
@@ -1698,13 +1698,13 @@ 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,
-			      char *fp, int count)
+			      const char *fp, int 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,
-			      char *fp, int count)
+			      const char *fp, int count)
 {
 	return n_tty_receive_buf_common(tty, cp, fp, count, 1);
 }
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 9733469a14b2..55b1f1711341 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -455,7 +455,7 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
  *	Returns the number of bytes processed
  */
 int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
-			  char *f, int count)
+			  const char *f, int count)
 {
 	if (ld->ops->receive_buf2)
 		count = ld->ops->receive_buf2(ld->tty, p, f, count);
@@ -472,7 +472,7 @@ static int
 receive_buf(struct tty_port *port, struct tty_buffer *head, int count)
 {
 	unsigned char *p = char_buf_ptr(head, head->read);
-	char	      *f = NULL;
+	const char *f = NULL;
 	int n;
 
 	if (~head->flags & TTYB_NORMAL)
diff --git a/include/linux/tty.h b/include/linux/tty.h
index e5d6b1f28823..5aad2220266c 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -628,7 +628,7 @@ extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
 extern int tty_unregister_ldisc(int disc);
 extern int tty_set_ldisc(struct tty_struct *tty, int disc);
 extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
-				 char *f, int count);
+				 const char *f, int count);
 
 /* n_tty.c */
 extern void n_tty_inherit_ops(struct tty_ldisc_ops *ops);
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index 31284b55bd4f..c20ca6a75b4c 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -201,11 +201,11 @@ struct tty_ldisc_ops {
 	 * The following routines are called from below.
 	 */
 	void	(*receive_buf)(struct tty_struct *, const unsigned char *cp,
-			       char *fp, int count);
+			       const char *fp, int count);
 	void	(*write_wakeup)(struct tty_struct *);
 	void	(*dcd_change)(struct tty_struct *, unsigned int);
 	int	(*receive_buf2)(struct tty_struct *, const unsigned char *cp,
-				char *fp, int count);
+				const char *fp, int count);
 
 	struct  module *owner;
 
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index 1248faf4d6df..98102ef64004 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -308,7 +308,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,
-				 char *flags, int count)
+				 const char *flags, int count)
 {
 	struct nci_uart *nu = (void *)tty->disc_data;
 
diff --git a/sound/soc/codecs/cx20442.c b/sound/soc/codecs/cx20442.c
index 61dfa86d444d..ec8d6e74b467 100644
--- a/sound/soc/codecs/cx20442.c
+++ b/sound/soc/codecs/cx20442.c
@@ -259,8 +259,8 @@ static int v253_hangup(struct tty_struct *tty)
 }
 
 /* Line discipline .receive_buf() */
-static void v253_receive(struct tty_struct *tty,
-				const unsigned char *cp, char *fp, int count)
+static void v253_receive(struct tty_struct *tty, const unsigned char *cp,
+		const char *fp, int 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 aba0017e870b..55a6736a378e 100644
--- a/sound/soc/ti/ams-delta.c
+++ b/sound/soc/ti/ams-delta.c
@@ -337,8 +337,8 @@ static int cx81801_hangup(struct tty_struct *tty)
 }
 
 /* Line discipline .receive_buf() */
-static void cx81801_receive(struct tty_struct *tty,
-				const unsigned char *cp, char *fp, int count)
+static void cx81801_receive(struct tty_struct *tty, const unsigned char *cp,
+		const char *fp, int count)
 {
 	struct snd_soc_component *component = tty->disc_data;
 	const unsigned char *c;
-- 
2.31.1


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

* [PATCH 12/35] tty: cumulate and document tty_struct::flow* members
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (10 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 11/35] tty: make fp of tty_ldisc_ops::receive_buf{,2} const Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 13/35] tty: cumulate and document tty_struct::ctrl* members Jiri Slaby
                   ` (24 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, David S. Miller,
	Jakub Kicinski, Jonathan Corbet, Arnd Bergmann, Ulf Hansson,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger, Shawn Guo,
	Sascha Hauer, Vineet Gupta, Maciej W. Rozycki

Group the flow flags under a single struct called flow. The new struct
contains 'stopped' and 'tco_stopped' bools which used to be bits in a
bitfield. The struct also contains the lock protecting them to
potentially share the same cache line.

Note that commit c545b66c6922b (tty: Serialize tcflow() with other tty
flow control changes) added a padding to the original bitfield. It was
for the bitfield to occupy a whole 64b word to avoid interferring stores
on Alpha (cannot we evaporate this arch with weird implications to C
code yet?). But it doesn't work as expected as the padding
(tty_struct::unused) is aligned to a 8B boundary too and occupies some
bytes from the next word.

So make it reliable by:
1) setting __aligned of the struct -- that aligns the start, and
2) making 'unsigned long unused[0]' as the last member of the struct --
   pads the end.

This is also the perfect time to start the documentation of tty_struct
where all this lives. So we start by documenting what these bools
actually serve for. And why we do all the alignment dances. Only the few
up-to-date information from the Theodore's comment made it into this new
Kerneldoc comment.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: "Maciej W. Rozycki" <macro@orcam.me.uk>
---
 Documentation/networking/caif/caif.rst |  4 +--
 drivers/char/pcmcia/synclink_cs.c      |  8 +++---
 drivers/mmc/core/sdio_uart.c           |  2 +-
 drivers/net/caif/caif_serial.c         |  4 +--
 drivers/s390/char/tty3270.c            |  2 +-
 drivers/staging/fwserial/fwserial.c    |  2 +-
 drivers/tty/amiserial.c                |  8 +++---
 drivers/tty/moxa.c                     |  4 +--
 drivers/tty/mxser.c                    | 12 ++++----
 drivers/tty/n_tty.c                    |  8 +++---
 drivers/tty/pty.c                      |  4 +--
 drivers/tty/serial/arc_uart.c          |  2 +-
 drivers/tty/serial/dz.c                |  2 +-
 drivers/tty/synclink_gt.c              |  6 ++--
 drivers/tty/tty_io.c                   | 24 ++++++++--------
 drivers/tty/tty_ioctl.c                | 16 +++++------
 drivers/tty/tty_port.c                 |  2 +-
 drivers/tty/vt/keyboard.c              |  2 +-
 drivers/tty/vt/vt.c                    |  4 +--
 include/linux/serial_core.h            |  2 +-
 include/linux/tty.h                    | 38 +++++++++++++++-----------
 include/linux/tty_driver.h             |  4 +--
 22 files changed, 83 insertions(+), 77 deletions(-)

diff --git a/Documentation/networking/caif/caif.rst b/Documentation/networking/caif/caif.rst
index 81a14373d780..d922d419c513 100644
--- a/Documentation/networking/caif/caif.rst
+++ b/Documentation/networking/caif/caif.rst
@@ -69,9 +69,9 @@ There are debugfs parameters provided for serial communication.
 
   - 0x01 - tty->warned is on.
   - 0x04 - tty->packed is on.
-  - 0x08 - tty->flow_stopped is on.
+  - 0x08 - tty->flow.tco_stopped is on.
   - 0x10 - tty->hw_stopped is on.
-  - 0x20 - tty->stopped is on.
+  - 0x20 - tty->flow.stopped is on.
 
 * last_tx_msg: Binary blob Prints the last transmitted frame.
 
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 3287a7627ed0..b4707bc3aee8 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -985,7 +985,7 @@ static void tx_done(MGSLPC_INFO *info, struct tty_struct *tty)
 	else
 #endif
 	{
-		if (tty && (tty->stopped || tty->hw_stopped)) {
+		if (tty && (tty->flow.stopped || tty->hw_stopped)) {
 			tx_stop(info);
 			return;
 		}
@@ -1005,7 +1005,7 @@ static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty)
 		if (!info->tx_active)
 			return;
 	} else {
-		if (tty && (tty->stopped || tty->hw_stopped)) {
+		if (tty && (tty->flow.stopped || tty->hw_stopped)) {
 			tx_stop(info);
 			return;
 		}
@@ -1525,7 +1525,7 @@ static void mgslpc_flush_chars(struct tty_struct *tty)
 	if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_chars"))
 		return;
 
-	if (info->tx_count <= 0 || tty->stopped ||
+	if (info->tx_count <= 0 || tty->flow.stopped ||
 	    tty->hw_stopped || !info->tx_buf)
 		return;
 
@@ -1594,7 +1594,7 @@ static int mgslpc_write(struct tty_struct * tty,
 		ret += c;
 	}
 start:
-	if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
+	if (info->tx_count && !tty->flow.stopped && !tty->hw_stopped) {
 		spin_lock_irqsave(&info->lock, flags);
 		if (!info->tx_active)
 			tx_start(info, tty);
diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c
index be4067281caa..dbcac2b7f2fe 100644
--- a/drivers/mmc/core/sdio_uart.c
+++ b/drivers/mmc/core/sdio_uart.c
@@ -439,7 +439,7 @@ static void sdio_uart_transmit_chars(struct sdio_uart_port *port)
 	tty = tty_port_tty_get(&port->port);
 
 	if (tty == NULL || !kfifo_len(xmit) ||
-				tty->stopped || tty->hw_stopped) {
+				tty->flow.stopped || tty->hw_stopped) {
 		sdio_uart_stop_tx(port);
 		tty_kref_put(tty);
 		return;
diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index fb3ca4e11fe5..3996cf7dc9ba 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -87,8 +87,8 @@ static void ldisc_tx_wakeup(struct tty_struct *tty);
 static inline void update_tty_status(struct ser_device *ser)
 {
 	ser->tty_status =
-		ser->tty->stopped << 5 |
-		ser->tty->flow_stopped << 3 |
+		ser->tty->flow.stopped << 5 |
+		ser->tty->flow.tco_stopped << 3 |
 		ser->tty->packet << 2;
 }
 static inline void debugfs_init(struct ser_device *ser, struct tty_struct *tty)
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 307a80f85c07..1b68564799fa 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -1640,7 +1640,7 @@ tty3270_do_write(struct tty3270 *tp, struct tty_struct *tty,
 	int i_msg, i;
 
 	spin_lock_bh(&tp->view.lock);
-	for (i_msg = 0; !tty->stopped && i_msg < count; i_msg++) {
+	for (i_msg = 0; !tty->flow.stopped && i_msg < count; i_msg++) {
 		if (tp->esc_state != 0) {
 			/* Continue escape sequence. */
 			tty3270_escape_sequence(tp, buf[i_msg]);
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index 1ee6382cafc4..4245532d2fe0 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -722,7 +722,7 @@ static int fwtty_tx(struct fwtty_port *port, bool drain)
 
 	/* try to write as many dma transactions out as possible */
 	n = -EAGAIN;
-	while (!tty->stopped && !tty->hw_stopped &&
+	while (!tty->flow.stopped && !tty->hw_stopped &&
 	       !test_bit(STOP_TX, &port->flags)) {
 		txn = kmem_cache_alloc(fwtty_txn_cache, GFP_ATOMIC);
 		if (!txn) {
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index ca48ce5a0862..a4b8876091d2 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -148,7 +148,7 @@ static __inline__ void rtsdtr_ctrl(int bits)
  * ------------------------------------------------------------
  * rs_stop() and rs_start()
  *
- * This routines are called before setting or resetting tty->stopped.
+ * This routines are called before setting or resetting tty->flow.stopped.
  * They enable or disable transmitter interrupts, as necessary.
  * ------------------------------------------------------------
  */
@@ -309,7 +309,7 @@ static void transmit_chars(struct serial_state *info)
 		return;
 	}
 	if (info->xmit.head == info->xmit.tail
-	    || info->tport.tty->stopped
+	    || info->tport.tty->flow.stopped
 	    || info->tport.tty->hw_stopped) {
 		info->IER &= ~UART_IER_THRI;
 	        custom.intena = IF_TBE;
@@ -768,7 +768,7 @@ static void rs_flush_chars(struct tty_struct *tty)
 	unsigned long flags;
 
 	if (info->xmit.head == info->xmit.tail
-	    || tty->stopped
+	    || tty->flow.stopped
 	    || tty->hw_stopped
 	    || !info->xmit.buf)
 		return;
@@ -812,7 +812,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
 	local_irq_restore(flags);
 
 	if (info->xmit.head != info->xmit.tail
-	    && !tty->stopped
+	    && !tty->flow.stopped
 	    && !tty->hw_stopped
 	    && !(info->IER & UART_IER_THRI)) {
 		info->IER |= UART_IER_THRI;
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 4d4f15b5cd29..847ad3dac107 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -1221,7 +1221,7 @@ static int moxa_write_room(struct tty_struct *tty)
 {
 	struct moxa_port *ch;
 
-	if (tty->stopped)
+	if (tty->flow.stopped)
 		return 0;
 	ch = tty->driver_data;
 	if (ch == NULL)
@@ -1374,7 +1374,7 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
 			clear_bit(EMPTYWAIT, &p->statusflags);
 			tty_wakeup(tty);
 		}
-		if (test_bit(LOWWAIT, &p->statusflags) && !tty->stopped &&
+		if (test_bit(LOWWAIT, &p->statusflags) && !tty->flow.stopped &&
 				MoxaPortTxQueue(p) <= WAKEUP_CHARS) {
 			clear_bit(LOWWAIT, &p->statusflags);
 			tty_wakeup(tty);
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 16a852ecbe8a..85271e109014 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -1118,7 +1118,7 @@ static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int cou
 		total += c;
 	}
 
-	if (info->xmit_cnt && !tty->stopped) {
+	if (info->xmit_cnt && !tty->flow.stopped) {
 		if (!tty->hw_stopped ||
 				(info->type == PORT_16550A) ||
 				(info->board->chip_flag)) {
@@ -1149,7 +1149,7 @@ static int mxser_put_char(struct tty_struct *tty, unsigned char ch)
 	info->xmit_head &= SERIAL_XMIT_SIZE - 1;
 	info->xmit_cnt++;
 	spin_unlock_irqrestore(&info->slock, flags);
-	if (!tty->stopped) {
+	if (!tty->flow.stopped) {
 		if (!tty->hw_stopped ||
 				(info->type == PORT_16550A) ||
 				info->board->chip_flag) {
@@ -1169,7 +1169,7 @@ static void mxser_flush_chars(struct tty_struct *tty)
 	struct mxser_port *info = tty->driver_data;
 	unsigned long flags;
 
-	if (info->xmit_cnt <= 0 || tty->stopped || !info->port.xmit_buf ||
+	if (info->xmit_cnt <= 0 || tty->flow.stopped || !info->port.xmit_buf ||
 			(tty->hw_stopped && info->type != PORT_16550A &&
 			 !info->board->chip_flag))
 		return;
@@ -1917,7 +1917,7 @@ static void mxser_unthrottle(struct tty_struct *tty)
 /*
  * mxser_stop() and mxser_start()
  *
- * This routines are called before setting or resetting tty->stopped.
+ * This routines are called before setting or resetting tty->flow.stopped.
  * They enable or disable transmitter interrupts, as necessary.
  */
 static void mxser_stop(struct tty_struct *tty)
@@ -1963,7 +1963,7 @@ static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termi
 
 	/* Handle sw stopped */
 	if ((old_termios->c_iflag & IXON) && !I_IXON(tty)) {
-		tty->stopped = 0;
+		tty->flow.stopped = 0;
 
 		if (info->board->chip_flag) {
 			spin_lock_irqsave(&info->slock, flags);
@@ -2175,7 +2175,7 @@ static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port
 	if (port->port.xmit_buf == NULL)
 		return;
 
-	if (port->xmit_cnt <= 0 || tty->stopped ||
+	if (port->xmit_cnt <= 0 || tty->flow.stopped ||
 			(tty->hw_stopped &&
 			(port->type != PORT_16550A) &&
 			(!port->board->chip_flag))) {
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index c32318da5190..3566bb577eb0 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -1289,7 +1289,7 @@ static void n_tty_receive_char_special(struct tty_struct *tty, unsigned char c)
 		}
 	}
 
-	if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) {
+	if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) {
 		start_tty(tty);
 		process_echoes(tty);
 	}
@@ -1398,7 +1398,7 @@ static void n_tty_receive_char(struct tty_struct *tty, unsigned char c)
 {
 	struct n_tty_data *ldata = tty->disc_data;
 
-	if (tty->stopped && !tty->flow_stopped && I_IXON(tty) && I_IXANY(tty)) {
+	if (tty->flow.stopped && !tty->flow.tco_stopped && I_IXON(tty) && I_IXANY(tty)) {
 		start_tty(tty);
 		process_echoes(tty);
 	}
@@ -1427,7 +1427,7 @@ static void n_tty_receive_char_closing(struct tty_struct *tty, unsigned char c)
 		if (c == STOP_CHAR(tty))
 			stop_tty(tty);
 		else if (c == START_CHAR(tty) ||
-			 (tty->stopped && !tty->flow_stopped && I_IXANY(tty) &&
+			 (tty->flow.stopped && !tty->flow.tco_stopped && I_IXANY(tty) &&
 			  c != INTR_CHAR(tty) && c != QUIT_CHAR(tty) &&
 			  c != SUSP_CHAR(tty))) {
 			start_tty(tty);
@@ -1797,7 +1797,7 @@ static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
 	 * Fix tty hang when I_IXON(tty) is cleared, but the tty
 	 * been stopped by STOP_CHAR(tty) before it.
 	 */
-	if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow_stopped) {
+	if (!I_IXON(tty) && old && (old->c_iflag & IXON) && !tty->flow.tco_stopped) {
 		start_tty(tty);
 		process_echoes(tty);
 	}
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 9b5d4ae5d8f2..017f28150a32 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -113,7 +113,7 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
 	struct tty_struct *to = tty->link;
 	unsigned long flags;
 
-	if (tty->stopped)
+	if (tty->flow.stopped)
 		return 0;
 
 	if (c > 0) {
@@ -138,7 +138,7 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
 
 static int pty_write_room(struct tty_struct *tty)
 {
-	if (tty->stopped)
+	if (tty->flow.stopped)
 		return 0;
 	return tty_buffer_space_avail(tty->link->port);
 }
diff --git a/drivers/tty/serial/arc_uart.c b/drivers/tty/serial/arc_uart.c
index 1a9444b6b57e..596217d10d5c 100644
--- a/drivers/tty/serial/arc_uart.c
+++ b/drivers/tty/serial/arc_uart.c
@@ -149,7 +149,7 @@ static unsigned int arc_serial_tx_empty(struct uart_port *port)
 /*
  * Driver internal routine, used by both tty(serial core) as well as tx-isr
  *  -Called under spinlock in either cases
- *  -also tty->stopped has already been checked
+ *  -also tty->flow.stopped has already been checked
  *     = by uart_start( ) before calling us
  *     = tx_ist checks that too before calling
  */
diff --git a/drivers/tty/serial/dz.c b/drivers/tty/serial/dz.c
index 4552742c3859..6d91e9b6284d 100644
--- a/drivers/tty/serial/dz.c
+++ b/drivers/tty/serial/dz.c
@@ -115,7 +115,7 @@ static void dz_out(struct dz_port *dport, unsigned offset, u16 value)
  * rs_stop () and rs_start ()
  *
  * These routines are called before setting or resetting
- * tty->stopped. They enable or disable transmitter interrupts,
+ * tty->flow.stopped. They enable or disable transmitter interrupts,
  * as necessary.
  * ------------------------------------------------------------
  */
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index 5523cf7bd1c2..1555dccc28af 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -768,7 +768,7 @@ static int write(struct tty_struct *tty,
 	if (!info->tx_buf || (count > info->max_frame_size))
 		return -EIO;
 
-	if (!count || tty->stopped || tty->hw_stopped)
+	if (!count || tty->flow.stopped || tty->hw_stopped)
 		return 0;
 
 	spin_lock_irqsave(&info->lock, flags);
@@ -889,7 +889,7 @@ static void flush_chars(struct tty_struct *tty)
 		return;
 	DBGINFO(("%s flush_chars entry tx_count=%d\n", info->device_name, info->tx_count));
 
-	if (info->tx_count <= 0 || tty->stopped ||
+	if (info->tx_count <= 0 || tty->flow.stopped ||
 	    tty->hw_stopped || !info->tx_buf)
 		return;
 
@@ -2241,7 +2241,7 @@ static void isr_txeom(struct slgt_info *info, unsigned short status)
 		else
 #endif
 		{
-			if (info->port.tty && (info->port.tty->stopped || info->port.tty->hw_stopped)) {
+			if (info->port.tty && (info->port.tty->flow.stopped || info->port.tty->hw_stopped)) {
 				tx_stop(info);
 				return;
 			}
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 5b5e99604989..9734be2eb00e 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -778,14 +778,14 @@ EXPORT_SYMBOL(tty_hung_up_p);
  *	but not always.
  *
  *	Locking:
- *		flow_lock
+ *		flow.lock
  */
 
 void __stop_tty(struct tty_struct *tty)
 {
-	if (tty->stopped)
+	if (tty->flow.stopped)
 		return;
-	tty->stopped = 1;
+	tty->flow.stopped = true;
 	if (tty->ops->stop)
 		tty->ops->stop(tty);
 }
@@ -794,9 +794,9 @@ void stop_tty(struct tty_struct *tty)
 {
 	unsigned long flags;
 
-	spin_lock_irqsave(&tty->flow_lock, flags);
+	spin_lock_irqsave(&tty->flow.lock, flags);
 	__stop_tty(tty);
-	spin_unlock_irqrestore(&tty->flow_lock, flags);
+	spin_unlock_irqrestore(&tty->flow.lock, flags);
 }
 EXPORT_SYMBOL(stop_tty);
 
@@ -809,14 +809,14 @@ EXPORT_SYMBOL(stop_tty);
  *	start method is invoked and the line discipline woken.
  *
  *	Locking:
- *		flow_lock
+ *		flow.lock
  */
 
 void __start_tty(struct tty_struct *tty)
 {
-	if (!tty->stopped || tty->flow_stopped)
+	if (!tty->flow.stopped || tty->flow.tco_stopped)
 		return;
-	tty->stopped = 0;
+	tty->flow.stopped = false;
 	if (tty->ops->start)
 		tty->ops->start(tty);
 	tty_wakeup(tty);
@@ -826,9 +826,9 @@ void start_tty(struct tty_struct *tty)
 {
 	unsigned long flags;
 
-	spin_lock_irqsave(&tty->flow_lock, flags);
+	spin_lock_irqsave(&tty->flow.lock, flags);
 	__start_tty(tty);
-	spin_unlock_irqrestore(&tty->flow_lock, flags);
+	spin_unlock_irqrestore(&tty->flow.lock, flags);
 }
 EXPORT_SYMBOL(start_tty);
 
@@ -1172,7 +1172,7 @@ ssize_t redirected_tty_write(struct kiocb *iocb, struct iov_iter *iter)
 
 int tty_send_xchar(struct tty_struct *tty, char ch)
 {
-	int	was_stopped = tty->stopped;
+	bool was_stopped = tty->flow.stopped;
 
 	if (tty->ops->send_xchar) {
 		down_read(&tty->termios_rwsem);
@@ -3141,7 +3141,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
 	INIT_WORK(&tty->hangup_work, do_tty_hangup);
 	mutex_init(&tty->atomic_write_lock);
 	spin_lock_init(&tty->ctrl_lock);
-	spin_lock_init(&tty->flow_lock);
+	spin_lock_init(&tty->flow.lock);
 	spin_lock_init(&tty->files_lock);
 	INIT_LIST_HEAD(&tty->tty_files);
 	INIT_WORK(&tty->SAK_work, do_SAK_work);
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 41f7449d0464..07c88ccfb17a 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -846,20 +846,20 @@ int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
 			return retval;
 		switch (arg) {
 		case TCOOFF:
-			spin_lock_irq(&tty->flow_lock);
-			if (!tty->flow_stopped) {
-				tty->flow_stopped = 1;
+			spin_lock_irq(&tty->flow.lock);
+			if (!tty->flow.tco_stopped) {
+				tty->flow.tco_stopped = true;
 				__stop_tty(tty);
 			}
-			spin_unlock_irq(&tty->flow_lock);
+			spin_unlock_irq(&tty->flow.lock);
 			break;
 		case TCOON:
-			spin_lock_irq(&tty->flow_lock);
-			if (tty->flow_stopped) {
-				tty->flow_stopped = 0;
+			spin_lock_irq(&tty->flow.lock);
+			if (tty->flow.tco_stopped) {
+				tty->flow.tco_stopped = false;
 				__start_tty(tty);
 			}
-			spin_unlock_irq(&tty->flow_lock);
+			spin_unlock_irq(&tty->flow.lock);
 			break;
 		case TCIOFF:
 			if (STOP_CHAR(tty) != __DISABLED_CHAR)
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 303c198fbf5c..0eb523207828 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -587,7 +587,7 @@ int tty_port_close_start(struct tty_port *port,
 
 	if (tty_port_initialized(port)) {
 		/* Don't block on a stalled port, just pull the chain */
-		if (tty->flow_stopped)
+		if (tty->flow.tco_stopped)
 			tty_driver_flush_buffer(tty);
 		if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
 			tty_wait_until_sent(tty, port->closing_wait);
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index 5d2309742718..4b0d69042ceb 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -515,7 +515,7 @@ static void fn_hold(struct vc_data *vc)
 	 * these routines are also activated by ^S/^Q.
 	 * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)
 	 */
-	if (tty->stopped)
+	if (tty->flow.stopped)
 		start_tty(tty);
 	else
 		stop_tty(tty);
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index e5040bdadcd6..38c677fb6505 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -2888,7 +2888,7 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
 
 	param.vc = vc;
 
-	while (!tty->stopped && count) {
+	while (!tty->flow.stopped && count) {
 		int orig = *buf;
 		buf++;
 		n++;
@@ -3265,7 +3265,7 @@ static int con_put_char(struct tty_struct *tty, unsigned char ch)
 
 static int con_write_room(struct tty_struct *tty)
 {
-	if (tty->stopped)
+	if (tty->flow.stopped)
 		return 0;
 	return 32768;		/* No limit, really; we're not buffering */
 }
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index d7ed00f1594e..7445c8fd88c0 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -428,7 +428,7 @@ int uart_resume_port(struct uart_driver *reg, struct uart_port *port);
 static inline int uart_tx_stopped(struct uart_port *port)
 {
 	struct tty_struct *tty = port->state->port.tty;
-	if ((tty && tty->stopped) || port->hw_stopped)
+	if ((tty && tty->flow.stopped) || port->hw_stopped)
 		return 1;
 	return 0;
 }
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 5aad2220266c..df3a69b2e1ea 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -243,20 +243,22 @@ struct tty_port {
 #define TTY_PORT_KOPENED	5	/* device exclusively opened by
 					   kernel */
 
-/*
- * Where all of the state associated with a tty is kept while the tty
- * is open.  Since the termios state should be kept even if the tty
- * has been closed --- for things like the baud rate, etc --- it is
- * not stored here, but rather a pointer to the real state is stored
- * here.  Possible the winsize structure should have the same
- * treatment, but (1) the default 80x24 is usually right and (2) it's
- * most often used by a windowing system, which will set the correct
- * size each time the window is created or resized anyway.
- * 						- TYT, 9/14/92
- */
-
 struct tty_operations;
 
+/**
+ * struct tty_struct - state associated with a tty while open
+ *
+ * @flow.lock: lock for flow members
+ * @flow.stopped: tty stopped/started by tty_stop/tty_start
+ * @flow.tco_stopped: tty stopped/started by TCOOFF/TCOON ioctls (it has
+ *		      precedense over @flow.stopped)
+ * @flow.unused: alignment for Alpha, so that no members other than @flow.* are
+ *		 modified by the same 64b word store. The @flow's __aligned is
+ *		 there for the very same reason.
+ *
+ * All of the state associated with a tty while the tty is open. Persistent
+ * storage for tty devices is referenced here as @port in struct tty_port.
+ */
 struct tty_struct {
 	int	magic;
 	struct kref kref;
@@ -275,7 +277,6 @@ struct tty_struct {
 	struct rw_semaphore termios_rwsem;
 	struct mutex winsize_mutex;
 	spinlock_t ctrl_lock;
-	spinlock_t flow_lock;
 	/* Termios values are protected by the termios rwsem */
 	struct ktermios termios, termios_locked;
 	char name[64];
@@ -288,9 +289,14 @@ struct tty_struct {
 	unsigned long flags;
 	int count;
 	struct winsize winsize;		/* winsize_mutex */
-	unsigned long stopped:1,	/* flow_lock */
-		      flow_stopped:1,
-		      unused:BITS_PER_LONG - 2;
+
+	struct {
+		spinlock_t lock;
+		bool stopped;
+		bool tco_stopped;
+		unsigned long unused[0];
+	} __aligned(sizeof(unsigned long)) flow;
+
 	int hw_stopped;
 	unsigned long ctrl_status:8,	/* ctrl_lock */
 		      packet:1,
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 2f719b471d52..653fa5af3a22 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -153,7 +153,7 @@
  * 	This routine notifies the tty driver that it should stop
  * 	outputting characters to the tty device.  
  *
- *	Called with ->flow_lock held. Serialized with start() method.
+ *	Called with ->flow.lock held. Serialized with start() method.
  *
  *	Optional:
  *
@@ -164,7 +164,7 @@
  * 	This routine notifies the tty driver that it resume sending
  *	characters to the tty device.
  *
- *	Called with ->flow_lock held. Serialized with stop() method.
+ *	Called with ->flow.lock held. Serialized with stop() method.
  *
  *	Optional:
  *
-- 
2.31.1


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

* [PATCH 13/35] tty: cumulate and document tty_struct::ctrl* members
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (11 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 12/35] tty: cumulate and document tty_struct::flow* members Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 14/35] tty: set tty_ldisc_ops::num statically Jiri Slaby
                   ` (23 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, David S. Miller,
	Jakub Kicinski, netdev

Group the ctrl members under a single struct called ctrl. The new struct
contains 'pgrp', 'session', 'pktstatus', and 'packet'. 'pktstatus' and
'packet' used to be bits in a bitfield. The struct also contains the
lock protecting them to share the same cache line.

Note that commit c545b66c6922b (tty: Serialize tcflow() with other tty
flow control changes) added a padding to the original bitfield. It was
for the bitfield to occupy a whole 64b word to avoid interferring stores
on Alpha (cannot we evaporate this arch with weird implications to C
code yet?). But it doesn't work as expected as the padding
(tty_struct::ctrl_unused) is aligned to a 8B boundary too and occupies
some bytes from the next word.

So make it reliable by:
1) setting __aligned of the struct -- that aligns the start, and
2) making 'unsigned long unused[0]' as the last member of the struct --
   pads the end.

Add a kerneldoc comment for this grouped members.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: netdev@vger.kernel.org
---
 drivers/net/caif/caif_serial.c |  2 +-
 drivers/tty/n_tty.c            | 30 ++++++------
 drivers/tty/pty.c              | 62 ++++++++++++-------------
 drivers/tty/tty_io.c           | 44 +++++++++---------
 drivers/tty/tty_jobctrl.c      | 84 +++++++++++++++++-----------------
 drivers/tty/vt/vt.c            |  4 +-
 include/linux/tty.h            | 26 +++++++----
 7 files changed, 130 insertions(+), 122 deletions(-)

diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index 3996cf7dc9ba..b0566588ce33 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -89,7 +89,7 @@ static inline void update_tty_status(struct ser_device *ser)
 	ser->tty_status =
 		ser->tty->flow.stopped << 5 |
 		ser->tty->flow.tco_stopped << 3 |
-		ser->tty->packet << 2;
+		ser->tty->ctrl.packet << 2;
 }
 static inline void debugfs_init(struct ser_device *ser, struct tty_struct *tty)
 {
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 3566bb577eb0..8ce712eec026 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -342,10 +342,10 @@ static void n_tty_packet_mode_flush(struct tty_struct *tty)
 {
 	unsigned long flags;
 
-	if (tty->link->packet) {
-		spin_lock_irqsave(&tty->ctrl_lock, flags);
-		tty->ctrl_status |= TIOCPKT_FLUSHREAD;
-		spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+	if (tty->link->ctrl.packet) {
+		spin_lock_irqsave(&tty->ctrl.lock, flags);
+		tty->ctrl.pktstatus |= TIOCPKT_FLUSHREAD;
+		spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 		wake_up_interruptible(&tty->link->read_wait);
 	}
 }
@@ -361,7 +361,7 @@ static void n_tty_packet_mode_flush(struct tty_struct *tty)
  *	Holds termios_rwsem to exclude producer/consumer while
  *	buffer indices are reset.
  *
- *	Locking: ctrl_lock, exclusive termios_rwsem
+ *	Locking: ctrl.lock, exclusive termios_rwsem
  */
 
 static void n_tty_flush_buffer(struct tty_struct *tty)
@@ -1103,7 +1103,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
  *	buffer is 'output'. The signal is processed first to alert any current
  *	readers or writers to discontinue and exit their i/o loops.
  *
- *	Locking: ctrl_lock
+ *	Locking: ctrl.lock
  */
 
 static void __isig(int sig, struct tty_struct *tty)
@@ -2025,7 +2025,7 @@ static bool canon_copy_from_read_buf(struct tty_struct *tty,
  *
  *	Locking: redirected write test is safe
  *		 current->signal->tty check is safe
- *		 ctrl_lock to safely reference tty->pgrp
+ *		 ctrl.lock to safely reference tty->ctrl.pgrp
  */
 
 static int job_control(struct tty_struct *tty, struct file *file)
@@ -2072,7 +2072,7 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 	int minimum, time;
 	ssize_t retval = 0;
 	long timeout;
-	int packet;
+	bool packet;
 	size_t tail;
 
 	/*
@@ -2128,20 +2128,20 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 		}
 	}
 
-	packet = tty->packet;
+	packet = tty->ctrl.packet;
 	tail = ldata->read_tail;
 
 	add_wait_queue(&tty->read_wait, &wait);
 	while (nr) {
 		/* First test for status change. */
-		if (packet && tty->link->ctrl_status) {
+		if (packet && tty->link->ctrl.pktstatus) {
 			unsigned char cs;
 			if (kb != kbuf)
 				break;
-			spin_lock_irq(&tty->link->ctrl_lock);
-			cs = tty->link->ctrl_status;
-			tty->link->ctrl_status = 0;
-			spin_unlock_irq(&tty->link->ctrl_lock);
+			spin_lock_irq(&tty->link->ctrl.lock);
+			cs = tty->link->ctrl.pktstatus;
+			tty->link->ctrl.pktstatus = 0;
+			spin_unlock_irq(&tty->link->ctrl.lock);
 			*kb++ = cs;
 			nr--;
 			break;
@@ -2368,7 +2368,7 @@ static __poll_t n_tty_poll(struct tty_struct *tty, struct file *file,
 		if (input_available_p(tty, 1))
 			mask |= EPOLLIN | EPOLLRDNORM;
 	}
-	if (tty->packet && tty->link->ctrl_status)
+	if (tty->ctrl.packet && tty->link->ctrl.pktstatus)
 		mask |= EPOLLPRI | EPOLLIN | EPOLLRDNORM;
 	if (test_bit(TTY_OTHER_CLOSED, &tty->flags))
 		mask |= EPOLLHUP;
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 017f28150a32..3e7b5c811f9b 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -57,9 +57,9 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
 	set_bit(TTY_IO_ERROR, &tty->flags);
 	wake_up_interruptible(&tty->read_wait);
 	wake_up_interruptible(&tty->write_wait);
-	spin_lock_irq(&tty->ctrl_lock);
-	tty->packet = 0;
-	spin_unlock_irq(&tty->ctrl_lock);
+	spin_lock_irq(&tty->ctrl.lock);
+	tty->ctrl.packet = false;
+	spin_unlock_irq(&tty->ctrl.lock);
 	/* Review - krefs on tty_link ?? */
 	if (!tty->link)
 		return;
@@ -185,16 +185,16 @@ static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
 	if (get_user(pktmode, arg))
 		return -EFAULT;
 
-	spin_lock_irq(&tty->ctrl_lock);
+	spin_lock_irq(&tty->ctrl.lock);
 	if (pktmode) {
-		if (!tty->packet) {
-			tty->link->ctrl_status = 0;
+		if (!tty->ctrl.packet) {
+			tty->link->ctrl.pktstatus = 0;
 			smp_mb();
-			tty->packet = 1;
+			tty->ctrl.packet = true;
 		}
 	} else
-		tty->packet = 0;
-	spin_unlock_irq(&tty->ctrl_lock);
+		tty->ctrl.packet = false;
+	spin_unlock_irq(&tty->ctrl.lock);
 
 	return 0;
 }
@@ -202,7 +202,7 @@ static int pty_set_pktmode(struct tty_struct *tty, int __user *arg)
 /* Get the packet mode of a pty */
 static int pty_get_pktmode(struct tty_struct *tty, int __user *arg)
 {
-	int pktmode = tty->packet;
+	int pktmode = tty->ctrl.packet;
 
 	return put_user(pktmode, arg);
 }
@@ -232,11 +232,11 @@ static void pty_flush_buffer(struct tty_struct *tty)
 		return;
 
 	tty_buffer_flush(to, NULL);
-	if (to->packet) {
-		spin_lock_irq(&tty->ctrl_lock);
-		tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
+	if (to->ctrl.packet) {
+		spin_lock_irq(&tty->ctrl.lock);
+		tty->ctrl.pktstatus |= TIOCPKT_FLUSHWRITE;
 		wake_up_interruptible(&to->read_wait);
-		spin_unlock_irq(&tty->ctrl_lock);
+		spin_unlock_irq(&tty->ctrl.lock);
 	}
 }
 
@@ -266,7 +266,7 @@ static void pty_set_termios(struct tty_struct *tty,
 					struct ktermios *old_termios)
 {
 	/* See if packet mode change of state. */
-	if (tty->link && tty->link->packet) {
+	if (tty->link && tty->link->ctrl.packet) {
 		int extproc = (old_termios->c_lflag & EXTPROC) | L_EXTPROC(tty);
 		int old_flow = ((old_termios->c_iflag & IXON) &&
 				(old_termios->c_cc[VSTOP] == '\023') &&
@@ -275,17 +275,17 @@ static void pty_set_termios(struct tty_struct *tty,
 				STOP_CHAR(tty) == '\023' &&
 				START_CHAR(tty) == '\021');
 		if ((old_flow != new_flow) || extproc) {
-			spin_lock_irq(&tty->ctrl_lock);
+			spin_lock_irq(&tty->ctrl.lock);
 			if (old_flow != new_flow) {
-				tty->ctrl_status &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
+				tty->ctrl.pktstatus &= ~(TIOCPKT_DOSTOP | TIOCPKT_NOSTOP);
 				if (new_flow)
-					tty->ctrl_status |= TIOCPKT_DOSTOP;
+					tty->ctrl.pktstatus |= TIOCPKT_DOSTOP;
 				else
-					tty->ctrl_status |= TIOCPKT_NOSTOP;
+					tty->ctrl.pktstatus |= TIOCPKT_NOSTOP;
 			}
 			if (extproc)
-				tty->ctrl_status |= TIOCPKT_IOCTL;
-			spin_unlock_irq(&tty->ctrl_lock);
+				tty->ctrl.pktstatus |= TIOCPKT_IOCTL;
+			spin_unlock_irq(&tty->ctrl.lock);
 			wake_up_interruptible(&tty->link->read_wait);
 		}
 	}
@@ -346,11 +346,11 @@ static void pty_start(struct tty_struct *tty)
 {
 	unsigned long flags;
 
-	if (tty->link && tty->link->packet) {
-		spin_lock_irqsave(&tty->ctrl_lock, flags);
-		tty->ctrl_status &= ~TIOCPKT_STOP;
-		tty->ctrl_status |= TIOCPKT_START;
-		spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+	if (tty->link && tty->link->ctrl.packet) {
+		spin_lock_irqsave(&tty->ctrl.lock, flags);
+		tty->ctrl.pktstatus &= ~TIOCPKT_STOP;
+		tty->ctrl.pktstatus |= TIOCPKT_START;
+		spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 		wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN);
 	}
 }
@@ -359,11 +359,11 @@ static void pty_stop(struct tty_struct *tty)
 {
 	unsigned long flags;
 
-	if (tty->link && tty->link->packet) {
-		spin_lock_irqsave(&tty->ctrl_lock, flags);
-		tty->ctrl_status &= ~TIOCPKT_START;
-		tty->ctrl_status |= TIOCPKT_STOP;
-		spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+	if (tty->link && tty->link->ctrl.packet) {
+		spin_lock_irqsave(&tty->ctrl.lock, flags);
+		tty->ctrl.pktstatus &= ~TIOCPKT_START;
+		tty->ctrl.pktstatus |= TIOCPKT_STOP;
+		spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 		wake_up_interruptible_poll(&tty->link->read_wait, EPOLLIN);
 	}
 }
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 9734be2eb00e..362845dc1c19 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -638,15 +638,15 @@ static void __tty_hangup(struct tty_struct *tty, int exit_session)
 
 	tty_ldisc_hangup(tty, cons_filp != NULL);
 
-	spin_lock_irq(&tty->ctrl_lock);
+	spin_lock_irq(&tty->ctrl.lock);
 	clear_bit(TTY_THROTTLED, &tty->flags);
 	clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
-	put_pid(tty->session);
-	put_pid(tty->pgrp);
-	tty->session = NULL;
-	tty->pgrp = NULL;
-	tty->ctrl_status = 0;
-	spin_unlock_irq(&tty->ctrl_lock);
+	put_pid(tty->ctrl.session);
+	put_pid(tty->ctrl.pgrp);
+	tty->ctrl.session = NULL;
+	tty->ctrl.pgrp = NULL;
+	tty->ctrl.pktstatus = 0;
+	spin_unlock_irq(&tty->ctrl.lock);
 
 	/*
 	 * If one of the devices matches a console pointer, we
@@ -1559,8 +1559,8 @@ static void release_one_tty(struct work_struct *work)
 	list_del_init(&tty->tty_files);
 	spin_unlock(&tty->files_lock);
 
-	put_pid(tty->pgrp);
-	put_pid(tty->session);
+	put_pid(tty->ctrl.pgrp);
+	put_pid(tty->ctrl.session);
 	free_tty_struct(tty);
 }
 
@@ -1861,9 +1861,9 @@ int tty_release(struct inode *inode, struct file *filp)
 	 */
 	if (!tty->count) {
 		read_lock(&tasklist_lock);
-		session_clear_tty(tty->session);
+		session_clear_tty(tty->ctrl.session);
 		if (o_tty)
-			session_clear_tty(o_tty->session);
+			session_clear_tty(o_tty->ctrl.session);
 		read_unlock(&tasklist_lock);
 	}
 
@@ -2250,16 +2250,16 @@ static int __tty_fasync(int fd, struct file *filp, int on)
 		enum pid_type type;
 		struct pid *pid;
 
-		spin_lock_irqsave(&tty->ctrl_lock, flags);
-		if (tty->pgrp) {
-			pid = tty->pgrp;
+		spin_lock_irqsave(&tty->ctrl.lock, flags);
+		if (tty->ctrl.pgrp) {
+			pid = tty->ctrl.pgrp;
 			type = PIDTYPE_PGID;
 		} else {
 			pid = task_pid(current);
 			type = PIDTYPE_TGID;
 		}
 		get_pid(pid);
-		spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+		spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 		__f_setown(filp, pid, type, 0);
 		put_pid(pid);
 		retval = 0;
@@ -2381,7 +2381,7 @@ EXPORT_SYMBOL(tty_do_resize);
  *
  *	Locking:
  *		Driver dependent. The default do_resize method takes the
- *	tty termios mutex and ctrl_lock. The console takes its own lock
+ *	tty termios mutex and ctrl.lock. The console takes its own lock
  *	then calls into the default method.
  */
 
@@ -3039,9 +3039,9 @@ void __do_SAK(struct tty_struct *tty)
 	if (!tty)
 		return;
 
-	spin_lock_irqsave(&tty->ctrl_lock, flags);
-	session = get_pid(tty->session);
-	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+	spin_lock_irqsave(&tty->ctrl.lock, flags);
+	session = get_pid(tty->ctrl.session);
+	spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 
 	tty_ldisc_flush(tty);
 
@@ -3129,8 +3129,8 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
 		kfree(tty);
 		return NULL;
 	}
-	tty->session = NULL;
-	tty->pgrp = NULL;
+	tty->ctrl.session = NULL;
+	tty->ctrl.pgrp = NULL;
 	mutex_init(&tty->legacy_mutex);
 	mutex_init(&tty->throttle_mutex);
 	init_rwsem(&tty->termios_rwsem);
@@ -3140,7 +3140,7 @@ struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
 	init_waitqueue_head(&tty->read_wait);
 	INIT_WORK(&tty->hangup_work, do_tty_hangup);
 	mutex_init(&tty->atomic_write_lock);
-	spin_lock_init(&tty->ctrl_lock);
+	spin_lock_init(&tty->ctrl.lock);
 	spin_lock_init(&tty->flow.lock);
 	spin_lock_init(&tty->files_lock);
 	INIT_LIST_HEAD(&tty->tty_files);
diff --git a/drivers/tty/tty_jobctrl.c b/drivers/tty/tty_jobctrl.c
index 7813dc910a19..6119b5e48610 100644
--- a/drivers/tty/tty_jobctrl.c
+++ b/drivers/tty/tty_jobctrl.c
@@ -28,7 +28,7 @@ static int is_ignored(int sig)
  *	not in the foreground, send a SIGTTOU.  If the signal is blocked or
  *	ignored, go ahead and perform the operation.  (POSIX 7.2)
  *
- *	Locking: ctrl_lock
+ *	Locking: ctrl.lock
  */
 int __tty_check_change(struct tty_struct *tty, int sig)
 {
@@ -42,9 +42,9 @@ int __tty_check_change(struct tty_struct *tty, int sig)
 	rcu_read_lock();
 	pgrp = task_pgrp(current);
 
-	spin_lock_irqsave(&tty->ctrl_lock, flags);
-	tty_pgrp = tty->pgrp;
-	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+	spin_lock_irqsave(&tty->ctrl.lock, flags);
+	tty_pgrp = tty->ctrl.pgrp;
+	spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 
 	if (tty_pgrp && pgrp != tty_pgrp) {
 		if (is_ignored(sig)) {
@@ -99,16 +99,16 @@ static void __proc_set_tty(struct tty_struct *tty)
 {
 	unsigned long flags;
 
-	spin_lock_irqsave(&tty->ctrl_lock, flags);
+	spin_lock_irqsave(&tty->ctrl.lock, flags);
 	/*
 	 * The session and fg pgrp references will be non-NULL if
 	 * tiocsctty() is stealing the controlling tty
 	 */
-	put_pid(tty->session);
-	put_pid(tty->pgrp);
-	tty->pgrp = get_pid(task_pgrp(current));
-	tty->session = get_pid(task_session(current));
-	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+	put_pid(tty->ctrl.session);
+	put_pid(tty->ctrl.pgrp);
+	tty->ctrl.pgrp = get_pid(task_pgrp(current));
+	tty->ctrl.session = get_pid(task_session(current));
+	spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 	if (current->signal->tty) {
 		tty_debug(tty, "current tty %s not NULL!!\n",
 			  current->signal->tty->name);
@@ -135,7 +135,7 @@ void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty)
 	spin_lock_irq(&current->sighand->siglock);
 	if (current->signal->leader &&
 	    !current->signal->tty &&
-	    tty->session == NULL) {
+	    tty->ctrl.session == NULL) {
 		/*
 		 * Don't let a process that only has write access to the tty
 		 * obtain the privileges associated with having a tty as
@@ -200,8 +200,8 @@ int tty_signal_session_leader(struct tty_struct *tty, int exit_session)
 	struct pid *tty_pgrp = NULL;
 
 	read_lock(&tasklist_lock);
-	if (tty->session) {
-		do_each_pid_task(tty->session, PIDTYPE_SID, p) {
+	if (tty->ctrl.session) {
+		do_each_pid_task(tty->ctrl.session, PIDTYPE_SID, p) {
 			spin_lock_irq(&p->sighand->siglock);
 			if (p->signal->tty == tty) {
 				p->signal->tty = NULL;
@@ -218,13 +218,14 @@ int tty_signal_session_leader(struct tty_struct *tty, int exit_session)
 			__group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
 			__group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
 			put_pid(p->signal->tty_old_pgrp);  /* A noop */
-			spin_lock(&tty->ctrl_lock);
-			tty_pgrp = get_pid(tty->pgrp);
-			if (tty->pgrp)
-				p->signal->tty_old_pgrp = get_pid(tty->pgrp);
-			spin_unlock(&tty->ctrl_lock);
+			spin_lock(&tty->ctrl.lock);
+			tty_pgrp = get_pid(tty->ctrl.pgrp);
+			if (tty->ctrl.pgrp)
+				p->signal->tty_old_pgrp =
+					get_pid(tty->ctrl.pgrp);
+			spin_unlock(&tty->ctrl.lock);
 			spin_unlock_irq(&p->sighand->siglock);
-		} while_each_pid_task(tty->session, PIDTYPE_SID, p);
+		} while_each_pid_task(tty->ctrl.session, PIDTYPE_SID, p);
 	}
 	read_unlock(&tasklist_lock);
 
@@ -309,12 +310,12 @@ void disassociate_ctty(int on_exit)
 		unsigned long flags;
 
 		tty_lock(tty);
-		spin_lock_irqsave(&tty->ctrl_lock, flags);
-		put_pid(tty->session);
-		put_pid(tty->pgrp);
-		tty->session = NULL;
-		tty->pgrp = NULL;
-		spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+		spin_lock_irqsave(&tty->ctrl.lock, flags);
+		put_pid(tty->ctrl.session);
+		put_pid(tty->ctrl.pgrp);
+		tty->ctrl.session = NULL;
+		tty->ctrl.pgrp = NULL;
+		spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 		tty_unlock(tty);
 		tty_kref_put(tty);
 	}
@@ -363,7 +364,8 @@ static int tiocsctty(struct tty_struct *tty, struct file *file, int arg)
 	tty_lock(tty);
 	read_lock(&tasklist_lock);
 
-	if (current->signal->leader && (task_session(current) == tty->session))
+	if (current->signal->leader &&
+			task_session(current) == tty->ctrl.session)
 		goto unlock;
 
 	/*
@@ -375,7 +377,7 @@ static int tiocsctty(struct tty_struct *tty, struct file *file, int arg)
 		goto unlock;
 	}
 
-	if (tty->session) {
+	if (tty->ctrl.session) {
 		/*
 		 * This tty is already the controlling
 		 * tty for another session group!
@@ -384,7 +386,7 @@ static int tiocsctty(struct tty_struct *tty, struct file *file, int arg)
 			/*
 			 * Steal it away
 			 */
-			session_clear_tty(tty->session);
+			session_clear_tty(tty->ctrl.session);
 		} else {
 			ret = -EPERM;
 			goto unlock;
@@ -416,9 +418,9 @@ struct pid *tty_get_pgrp(struct tty_struct *tty)
 	unsigned long flags;
 	struct pid *pgrp;
 
-	spin_lock_irqsave(&tty->ctrl_lock, flags);
-	pgrp = get_pid(tty->pgrp);
-	spin_unlock_irqrestore(&tty->ctrl_lock, flags);
+	spin_lock_irqsave(&tty->ctrl.lock, flags);
+	pgrp = get_pid(tty->ctrl.pgrp);
+	spin_unlock_irqrestore(&tty->ctrl.lock, flags);
 
 	return pgrp;
 }
@@ -499,10 +501,10 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
 	if (pgrp_nr < 0)
 		return -EINVAL;
 
-	spin_lock_irq(&real_tty->ctrl_lock);
+	spin_lock_irq(&real_tty->ctrl.lock);
 	if (!current->signal->tty ||
 	    (current->signal->tty != real_tty) ||
-	    (real_tty->session != task_session(current))) {
+	    (real_tty->ctrl.session != task_session(current))) {
 		retval = -ENOTTY;
 		goto out_unlock_ctrl;
 	}
@@ -515,12 +517,12 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
 	if (session_of_pgrp(pgrp) != task_session(current))
 		goto out_unlock;
 	retval = 0;
-	put_pid(real_tty->pgrp);
-	real_tty->pgrp = get_pid(pgrp);
+	put_pid(real_tty->ctrl.pgrp);
+	real_tty->ctrl.pgrp = get_pid(pgrp);
 out_unlock:
 	rcu_read_unlock();
 out_unlock_ctrl:
-	spin_unlock_irq(&real_tty->ctrl_lock);
+	spin_unlock_irq(&real_tty->ctrl.lock);
 	return retval;
 }
 
@@ -545,16 +547,16 @@ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t _
 	if (tty == real_tty && current->signal->tty != real_tty)
 		return -ENOTTY;
 
-	spin_lock_irqsave(&real_tty->ctrl_lock, flags);
-	if (!real_tty->session)
+	spin_lock_irqsave(&real_tty->ctrl.lock, flags);
+	if (!real_tty->ctrl.session)
 		goto err;
-	sid = pid_vnr(real_tty->session);
-	spin_unlock_irqrestore(&real_tty->ctrl_lock, flags);
+	sid = pid_vnr(real_tty->ctrl.session);
+	spin_unlock_irqrestore(&real_tty->ctrl.lock, flags);
 
 	return put_user(sid, p);
 
 err:
-	spin_unlock_irqrestore(&real_tty->ctrl_lock, flags);
+	spin_unlock_irqrestore(&real_tty->ctrl.lock, flags);
 	return -ENOTTY;
 }
 
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 38c677fb6505..706f066eb711 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -1189,7 +1189,7 @@ static inline int resize_screen(struct vc_data *vc, int width, int height,
  *	information and perform any necessary signal handling.
  *
  *	Caller must hold the console semaphore. Takes the termios rwsem and
- *	ctrl_lock of the tty IFF a tty is passed.
+ *	ctrl.lock of the tty IFF a tty is passed.
  */
 
 static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
@@ -1355,7 +1355,7 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int rows)
  *	the actual work.
  *
  *	Takes the console sem and the called methods then take the tty
- *	termios_rwsem and the tty ctrl_lock in that order.
+ *	termios_rwsem and the tty ctrl.lock in that order.
  */
 static int vt_resize(struct tty_struct *tty, struct winsize *ws)
 {
diff --git a/include/linux/tty.h b/include/linux/tty.h
index df3a69b2e1ea..283ac5f29052 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -255,6 +255,13 @@ struct tty_operations;
  * @flow.unused: alignment for Alpha, so that no members other than @flow.* are
  *		 modified by the same 64b word store. The @flow's __aligned is
  *		 there for the very same reason.
+ * @ctrl.lock: lock for ctrl members
+ * @ctrl.pgrp: process group of this tty (setpgrp(2))
+ * @ctrl.session: session of this tty (setsid(2)). Writes are protected by both
+ *		  @ctrl.lock and legacy mutex, readers must use at least one of
+ *		  them.
+ * @ctrl.pktstatus: packet mode status (bitwise OR of TIOCPKT_* constants)
+ * @ctrl.packet: packet mode enabled
  *
  * All of the state associated with a tty while the tty is open. Persistent
  * storage for tty devices is referenced here as @port in struct tty_port.
@@ -276,16 +283,9 @@ struct tty_struct {
 	struct mutex throttle_mutex;
 	struct rw_semaphore termios_rwsem;
 	struct mutex winsize_mutex;
-	spinlock_t ctrl_lock;
 	/* Termios values are protected by the termios rwsem */
 	struct ktermios termios, termios_locked;
 	char name[64];
-	struct pid *pgrp;		/* Protected by ctrl lock */
-	/*
-	 * Writes protected by both ctrl lock and legacy mutex, readers must use
-	 * at least one of them.
-	 */
-	struct pid *session;
 	unsigned long flags;
 	int count;
 	struct winsize winsize;		/* winsize_mutex */
@@ -297,10 +297,16 @@ struct tty_struct {
 		unsigned long unused[0];
 	} __aligned(sizeof(unsigned long)) flow;
 
+	struct {
+		spinlock_t lock;
+		struct pid *pgrp;
+		struct pid *session;
+		unsigned char pktstatus;
+		bool packet;
+		unsigned long unused[0];
+	} __aligned(sizeof(unsigned long)) ctrl;
+
 	int hw_stopped;
-	unsigned long ctrl_status:8,	/* ctrl_lock */
-		      packet:1,
-		      unused_ctrl:BITS_PER_LONG - 9;
 	unsigned int receive_room;	/* Bytes free for queue */
 	int flow_change;
 
-- 
2.31.1


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

* [PATCH 14/35] tty: set tty_ldisc_ops::num statically
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (12 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 13/35] tty: cumulate and document tty_struct::ctrl* members Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 15/35] n_gsm: use goto-failpaths in gsm_init Jiri Slaby
                   ` (22 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, William Hubbs,
	Chris Brannon, Kirk Reiser, Samuel Thibault, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Dmitry Torokhov,
	Arnd Bergmann, David S. Miller, Jakub Kicinski,
	Wolfgang Grandegger, Marc Kleine-Budde, Andreas Koensgen,
	Paul Mackerras, Rodolfo Giometti, Peter Ujfalusi, Liam Girdwood,
	Mark Brown, Jaroslav Kysela, Takashi Iwai

There is no reason to pass the ldisc number to tty_register_ldisc
separately. Just set it in the already defined tty_ldisc_ops in all the
ldiscs.

This simplifies tty_register_ldisc a bit too (no need to set the num
member there).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: William Hubbs <w.d.hubbs@gmail.com>
Cc: Chris Brannon <chris@the-brannons.com>
Cc: Kirk Reiser <kirk@reisers.ca>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Andreas Koensgen <ajk@comnets.uni-bremen.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Rodolfo Giometti <giometti@enneenne.com>
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
---
 drivers/accessibility/speakup/spk_ttyio.c | 3 ++-
 drivers/bluetooth/hci_ldisc.c             | 3 ++-
 drivers/input/serio/serport.c             | 3 ++-
 drivers/misc/ti-st/st_core.c              | 3 ++-
 drivers/net/caif/caif_serial.c            | 3 ++-
 drivers/net/can/slcan.c                   | 3 ++-
 drivers/net/hamradio/6pack.c              | 4 +++-
 drivers/net/hamradio/mkiss.c              | 3 ++-
 drivers/net/ppp/ppp_async.c               | 3 ++-
 drivers/net/ppp/ppp_synctty.c             | 3 ++-
 drivers/net/slip/slip.c                   | 3 ++-
 drivers/pps/clients/pps-ldisc.c           | 3 ++-
 drivers/tty/n_gsm.c                       | 3 ++-
 drivers/tty/n_hdlc.c                      | 3 ++-
 drivers/tty/n_null.c                      | 3 ++-
 drivers/tty/n_tty.c                       | 3 ++-
 drivers/tty/tty_ldisc.c                   | 7 +++----
 include/linux/tty.h                       | 2 +-
 net/nfc/nci/uart.c                        | 3 ++-
 sound/soc/ti/ams-delta.c                  | 3 ++-
 20 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index b7fd094700d9..8faa27bae6bf 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -105,6 +105,7 @@ static int spk_ttyio_receive_buf2(struct tty_struct *tty,
 
 static struct tty_ldisc_ops spk_ttyio_ldisc_ops = {
 	.owner          = THIS_MODULE,
+	.num		= N_SPEAKUP,
 	.name           = "speakup_ldisc",
 	.open           = spk_ttyio_ldisc_open,
 	.close          = spk_ttyio_ldisc_close,
@@ -212,7 +213,7 @@ static int spk_ttyio_initialise_ldisc(struct spk_synth *synth)
 
 void spk_ttyio_register_ldisc(void)
 {
-	if (tty_register_ldisc(N_SPEAKUP, &spk_ttyio_ldisc_ops))
+	if (tty_register_ldisc(&spk_ttyio_ldisc_ops))
 		pr_warn("speakup: Error registering line discipline. Most synths won't work.\n");
 }
 
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index e785851a92c1..ee32006e8fc9 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -821,6 +821,7 @@ static __poll_t hci_uart_tty_poll(struct tty_struct *tty,
 
 static struct tty_ldisc_ops hci_uart_ldisc = {
 	.owner		= THIS_MODULE,
+	.num		= N_HCI,
 	.name		= "n_hci",
 	.open		= hci_uart_tty_open,
 	.close		= hci_uart_tty_close,
@@ -840,7 +841,7 @@ static int __init hci_uart_init(void)
 	BT_INFO("HCI UART driver ver %s", VERSION);
 
 	/* Register the tty discipline */
-	err = tty_register_ldisc(N_HCI, &hci_uart_ldisc);
+	err = tty_register_ldisc(&hci_uart_ldisc);
 	if (err) {
 		BT_ERR("HCI line discipline registration failed. (%d)", err);
 		return err;
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index ff3715315592..870b1d2606fc 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -274,6 +274,7 @@ static void serport_ldisc_write_wakeup(struct tty_struct * tty)
 
 static struct tty_ldisc_ops serport_ldisc = {
 	.owner =	THIS_MODULE,
+	.num =		N_MOUSE,
 	.name =		"input",
 	.open =		serport_ldisc_open,
 	.close =	serport_ldisc_close,
@@ -294,7 +295,7 @@ static struct tty_ldisc_ops serport_ldisc = {
 static int __init serport_init(void)
 {
 	int retval;
-	retval = tty_register_ldisc(N_MOUSE, &serport_ldisc);
+	retval = tty_register_ldisc(&serport_ldisc);
 	if (retval)
 		printk(KERN_ERR "serport.c: Error registering line discipline.\n");
 
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 239a75502cd6..a4f5d02940c7 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -845,6 +845,7 @@ static void st_tty_flush_buffer(struct tty_struct *tty)
 }
 
 static struct tty_ldisc_ops st_ldisc_ops = {
+	.num = N_TI_WL,
 	.name = "n_st",
 	.open = st_tty_open,
 	.close = st_tty_close,
@@ -860,7 +861,7 @@ int st_core_init(struct st_data_s **core_data)
 	struct st_data_s *st_gdata;
 	long err;
 
-	err = tty_register_ldisc(N_TI_WL, &st_ldisc_ops);
+	err = tty_register_ldisc(&st_ldisc_ops);
 	if (err) {
 		pr_err("error registering %d line discipline %ld",
 			   N_TI_WL, err);
diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index b0566588ce33..2407a0f6656d 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -382,6 +382,7 @@ static void ldisc_close(struct tty_struct *tty)
 /* The line discipline structure. */
 static struct tty_ldisc_ops caif_ldisc = {
 	.owner =	THIS_MODULE,
+	.num =		N_CAIF,
 	.name =		"n_caif",
 	.open =		ldisc_open,
 	.close =	ldisc_close,
@@ -431,7 +432,7 @@ static int __init caif_ser_init(void)
 {
 	int ret;
 
-	ret = tty_register_ldisc(N_CAIF, &caif_ldisc);
+	ret = tty_register_ldisc(&caif_ldisc);
 	if (ret < 0)
 		pr_err("cannot register CAIF ldisc=%d err=%d\n", N_CAIF, ret);
 
diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
index 7dc3e79cb5c4..e3f528c82242 100644
--- a/drivers/net/can/slcan.c
+++ b/drivers/net/can/slcan.c
@@ -698,6 +698,7 @@ static int slcan_ioctl(struct tty_struct *tty, struct file *file,
 
 static struct tty_ldisc_ops slc_ldisc = {
 	.owner		= THIS_MODULE,
+	.num		= N_SLCAN,
 	.name		= "slcan",
 	.open		= slcan_open,
 	.close		= slcan_close,
@@ -722,7 +723,7 @@ static int __init slcan_init(void)
 		return -ENOMEM;
 
 	/* Fill in our line protocol discipline, and register it */
-	status = tty_register_ldisc(N_SLCAN, &slc_ldisc);
+	status = tty_register_ldisc(&slc_ldisc);
 	if (status)  {
 		printk(KERN_ERR "slcan: can't register line discipline\n");
 		kfree(slcan_devs);
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index c0a80f04dd8e..4db1d3c4d771 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -744,6 +744,7 @@ static int sixpack_ioctl(struct tty_struct *tty, struct file *file,
 
 static struct tty_ldisc_ops sp_ldisc = {
 	.owner		= THIS_MODULE,
+	.num		= N_6PACK,
 	.name		= "6pack",
 	.open		= sixpack_open,
 	.close		= sixpack_close,
@@ -766,7 +767,8 @@ static int __init sixpack_init_driver(void)
 	printk(msg_banner);
 
 	/* Register the provided line protocol discipline */
-	if ((status = tty_register_ldisc(N_6PACK, &sp_ldisc)) != 0)
+	status = tty_register_ldisc(&sp_ldisc);
+	if (status)
 		printk(msg_regfail, status);
 
 	return status;
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index fc05ded48178..1eb87a5a9394 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -933,6 +933,7 @@ static void mkiss_write_wakeup(struct tty_struct *tty)
 
 static struct tty_ldisc_ops ax_ldisc = {
 	.owner		= THIS_MODULE,
+	.num		= N_AX25,
 	.name		= "mkiss",
 	.open		= mkiss_open,
 	.close		= mkiss_close,
@@ -952,7 +953,7 @@ static int __init mkiss_init_driver(void)
 
 	printk(banner);
 
-	status = tty_register_ldisc(N_AX25, &ax_ldisc);
+	status = tty_register_ldisc(&ax_ldisc);
 	if (status != 0)
 		printk(msg_regfail, status);
 
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index 9f08bd19551f..4bfb66c40c86 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -372,6 +372,7 @@ ppp_asynctty_wakeup(struct tty_struct *tty)
 
 static struct tty_ldisc_ops ppp_ldisc = {
 	.owner  = THIS_MODULE,
+	.num	= N_PPP,
 	.name	= "ppp",
 	.open	= ppp_asynctty_open,
 	.close	= ppp_asynctty_close,
@@ -389,7 +390,7 @@ ppp_async_init(void)
 {
 	int err;
 
-	err = tty_register_ldisc(N_PPP, &ppp_ldisc);
+	err = tty_register_ldisc(&ppp_ldisc);
 	if (err != 0)
 		printk(KERN_ERR "PPP_async: error %d registering line disc.\n",
 		       err);
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index c82c4e6df4cb..0942d3ee48e0 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -365,6 +365,7 @@ ppp_sync_wakeup(struct tty_struct *tty)
 
 static struct tty_ldisc_ops ppp_sync_ldisc = {
 	.owner	= THIS_MODULE,
+	.num	= N_SYNC_PPP,
 	.name	= "pppsync",
 	.open	= ppp_sync_open,
 	.close	= ppp_sync_close,
@@ -382,7 +383,7 @@ ppp_sync_init(void)
 {
 	int err;
 
-	err = tty_register_ldisc(N_SYNC_PPP, &ppp_sync_ldisc);
+	err = tty_register_ldisc(&ppp_sync_ldisc);
 	if (err != 0)
 		printk(KERN_ERR "PPP_sync: error %d registering line disc.\n",
 		       err);
diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c
index 4dda49e61745..938ac0ec0305 100644
--- a/drivers/net/slip/slip.c
+++ b/drivers/net/slip/slip.c
@@ -1263,6 +1263,7 @@ static int sl_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 
 static struct tty_ldisc_ops sl_ldisc = {
 	.owner 		= THIS_MODULE,
+	.num		= N_SLIP,
 	.name 		= "slip",
 	.open 		= slip_open,
 	.close	 	= slip_close,
@@ -1298,7 +1299,7 @@ static int __init slip_init(void)
 		return -ENOMEM;
 
 	/* Fill in our line protocol discipline, and register it */
-	status = tty_register_ldisc(N_SLIP, &sl_ldisc);
+	status = tty_register_ldisc(&sl_ldisc);
 	if (status != 0) {
 		printk(KERN_ERR "SLIP: can't register line discipline (err = %d)\n", status);
 		kfree(slip_devs);
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c
index bf26cc56b863..2a88e678d0b8 100644
--- a/drivers/pps/clients/pps-ldisc.c
+++ b/drivers/pps/clients/pps-ldisc.c
@@ -112,12 +112,13 @@ static int __init pps_tty_init(void)
 
 	/* Init PPS_TTY data */
 	pps_ldisc_ops.owner = THIS_MODULE;
+	pps_ldisc_ops.num = N_PPS;
 	pps_ldisc_ops.name = "pps_tty";
 	pps_ldisc_ops.dcd_change = pps_tty_dcd_change;
 	pps_ldisc_ops.open = pps_tty_open;
 	pps_ldisc_ops.close = pps_tty_close;
 
-	err = tty_register_ldisc(N_PPS, &pps_ldisc_ops);
+	err = tty_register_ldisc(&pps_ldisc_ops);
 	if (err)
 		pr_err("can't register PPS line discipline\n");
 	else
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 477403ecc445..654e439ff6c8 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2857,6 +2857,7 @@ static int gsm_create_network(struct gsm_dlci *dlci, struct gsm_netconfig *nc)
 /* Line discipline for real tty */
 static struct tty_ldisc_ops tty_ldisc_packet = {
 	.owner		 = THIS_MODULE,
+	.num		 = N_GSM0710,
 	.name            = "n_gsm",
 	.open            = gsmld_open,
 	.close           = gsmld_close,
@@ -3242,7 +3243,7 @@ static const struct tty_operations gsmtty_ops = {
 static int __init gsm_init(void)
 {
 	/* Fill in our line protocol discipline, and register it */
-	int status = tty_register_ldisc(N_GSM0710, &tty_ldisc_packet);
+	int status = tty_register_ldisc(&tty_ldisc_packet);
 	if (status != 0) {
 		pr_err("n_gsm: can't register line discipline (err = %d)\n",
 								status);
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 62b1d1a6e0f1..2256039911f5 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -788,6 +788,7 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *buf_list)
 
 static struct tty_ldisc_ops n_hdlc_ldisc = {
 	.owner		= THIS_MODULE,
+	.num		= N_HDLC,
 	.name		= "hdlc",
 	.open		= n_hdlc_tty_open,
 	.close		= n_hdlc_tty_close,
@@ -807,7 +808,7 @@ static int __init n_hdlc_init(void)
 	/* range check maxframe arg */
 	maxframe = clamp(maxframe, 4096, MAX_HDLC_FRAME_SIZE);
 
-	status = tty_register_ldisc(N_HDLC, &n_hdlc_ldisc);
+	status = tty_register_ldisc(&n_hdlc_ldisc);
 	if (!status)
 		pr_info("N_HDLC line discipline registered with maxframe=%d\n",
 				maxframe);
diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c
index 2ff373d2f98d..ee229c812dce 100644
--- a/drivers/tty/n_null.c
+++ b/drivers/tty/n_null.c
@@ -40,6 +40,7 @@ static void n_null_receivebuf(struct tty_struct *tty,
 
 static struct tty_ldisc_ops null_ldisc = {
 	.owner		=	THIS_MODULE,
+	.num		=	N_NULL,
 	.name		=	"n_null",
 	.open		=	n_null_open,
 	.close		=	n_null_close,
@@ -50,7 +51,7 @@ static struct tty_ldisc_ops null_ldisc = {
 
 static int __init n_null_init(void)
 {
-	BUG_ON(tty_register_ldisc(N_NULL, &null_ldisc));
+	BUG_ON(tty_register_ldisc(&null_ldisc));
 	return 0;
 }
 
diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 8ce712eec026..2fe27905c398 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2424,6 +2424,7 @@ static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
 
 static struct tty_ldisc_ops n_tty_ops = {
 	.owner		 = THIS_MODULE,
+	.num		 = N_TTY,
 	.name            = "n_tty",
 	.open            = n_tty_open,
 	.close           = n_tty_close,
@@ -2455,5 +2456,5 @@ EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
 
 void __init n_tty_init(void)
 {
-	tty_register_ldisc(N_TTY, &n_tty_ops);
+	tty_register_ldisc(&n_tty_ops);
 }
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 03f414172f34..9aff04bee4cd 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -59,17 +59,16 @@ static struct tty_ldisc_ops *tty_ldiscs[NR_LDISCS];
  *		takes tty_ldiscs_lock to guard against ldisc races
  */
 
-int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
+int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc)
 {
 	unsigned long flags;
 	int ret = 0;
 
-	if (disc < N_TTY || disc >= NR_LDISCS)
+	if (new_ldisc->num < N_TTY || new_ldisc->num >= NR_LDISCS)
 		return -EINVAL;
 
 	raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
-	tty_ldiscs[disc] = new_ldisc;
-	new_ldisc->num = disc;
+	tty_ldiscs[new_ldisc->num] = new_ldisc;
 	new_ldisc->refcount = 0;
 	raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
 
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 283ac5f29052..95c632299fb4 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -636,7 +636,7 @@ static inline int tty_port_users(struct tty_port *port)
 	return port->count + port->blocked_open;
 }
 
-extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
+extern int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc);
 extern int tty_unregister_ldisc(int disc);
 extern int tty_set_ldisc(struct tty_struct *tty, int disc);
 extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index 98102ef64004..648c26b4bad8 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -442,6 +442,7 @@ EXPORT_SYMBOL_GPL(nci_uart_set_config);
 
 static struct tty_ldisc_ops nci_uart_ldisc = {
 	.owner		= THIS_MODULE,
+	.num		= N_NCI,
 	.name		= "n_nci",
 	.open		= nci_uart_tty_open,
 	.close		= nci_uart_tty_close,
@@ -456,7 +457,7 @@ static struct tty_ldisc_ops nci_uart_ldisc = {
 
 static int __init nci_uart_init(void)
 {
-	return tty_register_ldisc(N_NCI, &nci_uart_ldisc);
+	return tty_register_ldisc(&nci_uart_ldisc);
 }
 
 static void __exit nci_uart_exit(void)
diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c
index 55a6736a378e..fcbb791bf27a 100644
--- a/sound/soc/ti/ams-delta.c
+++ b/sound/soc/ti/ams-delta.c
@@ -396,6 +396,7 @@ static void cx81801_wakeup(struct tty_struct *tty)
 
 static struct tty_ldisc_ops cx81801_ops = {
 	.name = "cx81801",
+	.num = N_V253,
 	.owner = THIS_MODULE,
 	.open = cx81801_open,
 	.close = cx81801_close,
@@ -503,7 +504,7 @@ static int ams_delta_cx20442_init(struct snd_soc_pcm_runtime *rtd)
 	}
 
 	/* Register optional line discipline for over the modem control */
-	ret = tty_register_ldisc(N_V253, &cx81801_ops);
+	ret = tty_register_ldisc(&cx81801_ops);
 	if (ret) {
 		dev_warn(card->dev,
 				"Failed to register line discipline, "
-- 
2.31.1


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

* [PATCH 15/35] n_gsm: use goto-failpaths in gsm_init
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (13 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 14/35] tty: set tty_ldisc_ops::num statically Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 16/35] tty: make tty_ldisc_ops a param in tty_unregister_ldisc Jiri Slaby
                   ` (21 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Use the classic failpath handling using gotos in gsm_init. That way,
tty_unregister_ldisc needs not be repeated on two places.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_gsm.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 654e439ff6c8..cce2ef04caeb 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3252,9 +3252,9 @@ static int __init gsm_init(void)
 
 	gsm_tty_driver = alloc_tty_driver(256);
 	if (!gsm_tty_driver) {
-		tty_unregister_ldisc(N_GSM0710);
 		pr_err("gsm_init: tty allocation failed.\n");
-		return -EINVAL;
+		status = -ENOMEM;
+		goto err_unreg_ldisc;
 	}
 	gsm_tty_driver->driver_name	= "gsmtty";
 	gsm_tty_driver->name		= "gsmtty";
@@ -3270,14 +3270,18 @@ static int __init gsm_init(void)
 	tty_set_operations(gsm_tty_driver, &gsmtty_ops);
 
 	if (tty_register_driver(gsm_tty_driver)) {
-		put_tty_driver(gsm_tty_driver);
-		tty_unregister_ldisc(N_GSM0710);
 		pr_err("gsm_init: tty registration failed.\n");
-		return -EBUSY;
+		status = -EBUSY;
+		goto err_put_driver;
 	}
 	pr_debug("gsm_init: loaded as %d,%d.\n",
 			gsm_tty_driver->major, gsm_tty_driver->minor_start);
 	return 0;
+err_put_driver:
+	put_tty_driver(gsm_tty_driver);
+err_unreg_ldisc:
+	tty_unregister_ldisc(N_GSM0710);
+	return status;
 }
 
 static void __exit gsm_exit(void)
-- 
2.31.1


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

* [PATCH 16/35] tty: make tty_ldisc_ops a param in tty_unregister_ldisc
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (14 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 15/35] n_gsm: use goto-failpaths in gsm_init Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 17/35] tty: drop tty_ldisc_ops::refcount Jiri Slaby
                   ` (20 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, William Hubbs,
	Chris Brannon, Kirk Reiser, Samuel Thibault, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Dmitry Torokhov,
	Arnd Bergmann, David S. Miller, Jakub Kicinski,
	Wolfgang Grandegger, Marc Kleine-Budde, Andreas Koensgen,
	Paul Mackerras, Rodolfo Giometti, Peter Ujfalusi, Liam Girdwood,
	Mark Brown, Jaroslav Kysela, Takashi Iwai

Make tty_unregister_ldisc symmetric to tty_register_ldisc by accepting
struct tty_ldisc_ops as a parameter instead of ldisc number. This avoids
checking of the ldisc number bounds in tty_unregister_ldisc.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: William Hubbs <w.d.hubbs@gmail.com>
Cc: Chris Brannon <chris@the-brannons.com>
Cc: Kirk Reiser <kirk@reisers.ca>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Andreas Koensgen <ajk@comnets.uni-bremen.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Rodolfo Giometti <giometti@enneenne.com>
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
---
 drivers/accessibility/speakup/spk_ttyio.c | 2 +-
 drivers/bluetooth/hci_ldisc.c             | 2 +-
 drivers/input/serio/serport.c             | 2 +-
 drivers/misc/ti-st/st_core.c              | 6 +++---
 drivers/net/caif/caif_serial.c            | 2 +-
 drivers/net/can/slcan.c                   | 2 +-
 drivers/net/hamradio/6pack.c              | 2 +-
 drivers/net/hamradio/mkiss.c              | 2 +-
 drivers/net/ppp/ppp_async.c               | 2 +-
 drivers/net/ppp/ppp_synctty.c             | 2 +-
 drivers/net/slip/slip.c                   | 2 +-
 drivers/pps/clients/pps-ldisc.c           | 2 +-
 drivers/tty/n_gsm.c                       | 4 ++--
 drivers/tty/n_hdlc.c                      | 3 +--
 drivers/tty/n_null.c                      | 2 +-
 drivers/tty/tty_ldisc.c                   | 9 +++------
 include/linux/tty.h                       | 2 +-
 net/nfc/nci/uart.c                        | 2 +-
 sound/soc/ti/ams-delta.c                  | 2 +-
 19 files changed, 24 insertions(+), 28 deletions(-)

diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index 8faa27bae6bf..0b7f1a87eaeb 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -219,7 +219,7 @@ void spk_ttyio_register_ldisc(void)
 
 void spk_ttyio_unregister_ldisc(void)
 {
-	if (tty_unregister_ldisc(N_SPEAKUP))
+	if (tty_unregister_ldisc(&spk_ttyio_ldisc_ops))
 		pr_warn("speakup: Couldn't unregister ldisc\n");
 }
 
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index ee32006e8fc9..31e0c804363c 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -917,7 +917,7 @@ static void __exit hci_uart_exit(void)
 #endif
 
 	/* Release tty registration of line discipline */
-	err = tty_unregister_ldisc(N_HCI);
+	err = tty_unregister_ldisc(&hci_uart_ldisc);
 	if (err)
 		BT_ERR("Can't unregister HCI line discipline (%d)", err);
 }
diff --git a/drivers/input/serio/serport.c b/drivers/input/serio/serport.c
index 870b1d2606fc..7fbbe00e3553 100644
--- a/drivers/input/serio/serport.c
+++ b/drivers/input/serio/serport.c
@@ -304,7 +304,7 @@ static int __init serport_init(void)
 
 static void __exit serport_exit(void)
 {
-	tty_unregister_ldisc(N_MOUSE);
+	tty_unregister_ldisc(&serport_ldisc);
 }
 
 module_init(serport_init);
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index a4f5d02940c7..174ae8e52805 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -872,7 +872,7 @@ int st_core_init(struct st_data_s **core_data)
 	st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
 	if (!st_gdata) {
 		pr_err("memory allocation failed");
-		err = tty_unregister_ldisc(N_TI_WL);
+		err = tty_unregister_ldisc(&st_ldisc_ops);
 		if (err)
 			pr_err("unable to un-register ldisc %ld", err);
 		err = -ENOMEM;
@@ -892,7 +892,7 @@ int st_core_init(struct st_data_s **core_data)
 	if (err) {
 		pr_err("error during st_ll initialization(%ld)", err);
 		kfree(st_gdata);
-		err = tty_unregister_ldisc(N_TI_WL);
+		err = tty_unregister_ldisc(&st_ldisc_ops);
 		if (err)
 			pr_err("unable to un-register ldisc");
 		return err;
@@ -919,7 +919,7 @@ void st_core_exit(struct st_data_s *st_gdata)
 		kfree_skb(st_gdata->rx_skb);
 		kfree_skb(st_gdata->tx_skb);
 		/* TTY ldisc cleanup */
-		err = tty_unregister_ldisc(N_TI_WL);
+		err = tty_unregister_ldisc(&st_ldisc_ops);
 		if (err)
 			pr_err("unable to un-register ldisc %ld", err);
 		/* free the global data pointer */
diff --git a/drivers/net/caif/caif_serial.c b/drivers/net/caif/caif_serial.c
index 2407a0f6656d..d0c24dba4a86 100644
--- a/drivers/net/caif/caif_serial.c
+++ b/drivers/net/caif/caif_serial.c
@@ -447,7 +447,7 @@ static void __exit caif_ser_exit(void)
 	spin_unlock(&ser_lock);
 	ser_release(NULL);
 	cancel_work_sync(&ser_release_work);
-	tty_unregister_ldisc(N_CAIF);
+	tty_unregister_ldisc(&caif_ldisc);
 	debugfs_remove_recursive(debugfsdir);
 }
 
diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
index e3f528c82242..03a2dbd3c367 100644
--- a/drivers/net/can/slcan.c
+++ b/drivers/net/can/slcan.c
@@ -784,7 +784,7 @@ static void __exit slcan_exit(void)
 	kfree(slcan_devs);
 	slcan_devs = NULL;
 
-	i = tty_unregister_ldisc(N_SLCAN);
+	i = tty_unregister_ldisc(&slc_ldisc);
 	if (i)
 		printk(KERN_ERR "slcan: can't unregister ldisc (err %d)\n", i);
 }
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index 4db1d3c4d771..aac24f9caceb 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -781,7 +781,7 @@ static void __exit sixpack_exit_driver(void)
 {
 	int ret;
 
-	if ((ret = tty_unregister_ldisc(N_6PACK)))
+	if ((ret = tty_unregister_ldisc(&sp_ldisc)))
 		printk(msg_unregfail, ret);
 }
 
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index 1eb87a5a9394..750c6afc9302 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -967,7 +967,7 @@ static void __exit mkiss_exit_driver(void)
 {
 	int ret;
 
-	if ((ret = tty_unregister_ldisc(N_AX25)))
+	if ((ret = tty_unregister_ldisc(&ax_ldisc)))
 		printk(msg_unregfail, ret);
 }
 
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index 4bfb66c40c86..b2d454d01eba 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -1016,7 +1016,7 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,
 
 static void __exit ppp_async_cleanup(void)
 {
-	if (tty_unregister_ldisc(N_PPP) != 0)
+	if (tty_unregister_ldisc(&ppp_ldisc) != 0)
 		printk(KERN_ERR "failed to unregister PPP line discipline\n");
 }
 
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index 0942d3ee48e0..ca403bde56fb 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -727,7 +727,7 @@ ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
 static void __exit
 ppp_sync_cleanup(void)
 {
-	if (tty_unregister_ldisc(N_SYNC_PPP) != 0)
+	if (tty_unregister_ldisc(&ppp_sync_ldisc) != 0)
 		printk(KERN_ERR "failed to unregister Sync PPP line discipline\n");
 }
 
diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c
index 938ac0ec0305..867efff40a0e 100644
--- a/drivers/net/slip/slip.c
+++ b/drivers/net/slip/slip.c
@@ -1360,7 +1360,7 @@ static void __exit slip_exit(void)
 	kfree(slip_devs);
 	slip_devs = NULL;
 
-	i = tty_unregister_ldisc(N_SLIP);
+	i = tty_unregister_ldisc(&sl_ldisc);
 	if (i != 0)
 		printk(KERN_ERR "SLIP: can't unregister line discipline (err = %d)\n", i);
 }
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c
index 2a88e678d0b8..91b947f37774 100644
--- a/drivers/pps/clients/pps-ldisc.c
+++ b/drivers/pps/clients/pps-ldisc.c
@@ -131,7 +131,7 @@ static void __exit pps_tty_cleanup(void)
 {
 	int err;
 
-	err = tty_unregister_ldisc(N_PPS);
+	err = tty_unregister_ldisc(&pps_ldisc_ops);
 	if (err)
 		pr_err("can't unregister PPS line discipline\n");
 	else
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index cce2ef04caeb..db7d4a30af91 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3280,13 +3280,13 @@ static int __init gsm_init(void)
 err_put_driver:
 	put_tty_driver(gsm_tty_driver);
 err_unreg_ldisc:
-	tty_unregister_ldisc(N_GSM0710);
+	tty_unregister_ldisc(&tty_ldisc_packet);
 	return status;
 }
 
 static void __exit gsm_exit(void)
 {
-	int status = tty_unregister_ldisc(N_GSM0710);
+	int status = tty_unregister_ldisc(&tty_ldisc_packet);
 	if (status != 0)
 		pr_err("n_gsm: can't unregister line discipline (err = %d)\n",
 								status);
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 2256039911f5..c2afbfe0a1d5 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -822,8 +822,7 @@ static int __init n_hdlc_init(void)
 
 static void __exit n_hdlc_exit(void)
 {
-	/* Release tty registration of line discipline */
-	int status = tty_unregister_ldisc(N_HDLC);
+	int status = tty_unregister_ldisc(&n_hdlc_ldisc);
 
 	if (status)
 		pr_err("N_HDLC: can't unregister line discipline (err = %d)\n",
diff --git a/drivers/tty/n_null.c b/drivers/tty/n_null.c
index ee229c812dce..f913b665af72 100644
--- a/drivers/tty/n_null.c
+++ b/drivers/tty/n_null.c
@@ -57,7 +57,7 @@ static int __init n_null_init(void)
 
 static void __exit n_null_exit(void)
 {
-	tty_unregister_ldisc(N_NULL);
+	tty_unregister_ldisc(&null_ldisc);
 }
 
 module_init(n_null_init);
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 9aff04bee4cd..d02deeb5e584 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -87,19 +87,16 @@ EXPORT_SYMBOL(tty_register_ldisc);
  *		takes tty_ldiscs_lock to guard against ldisc races
  */
 
-int tty_unregister_ldisc(int disc)
+int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc)
 {
 	unsigned long flags;
 	int ret = 0;
 
-	if (disc < N_TTY || disc >= NR_LDISCS)
-		return -EINVAL;
-
 	raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
-	if (tty_ldiscs[disc]->refcount)
+	if (tty_ldiscs[ldisc->num]->refcount)
 		ret = -EBUSY;
 	else
-		tty_ldiscs[disc] = NULL;
+		tty_ldiscs[ldisc->num] = NULL;
 	raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
 
 	return ret;
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 95c632299fb4..6a72d0ff6391 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -637,7 +637,7 @@ static inline int tty_port_users(struct tty_port *port)
 }
 
 extern int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc);
-extern int tty_unregister_ldisc(int disc);
+extern int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc);
 extern int tty_set_ldisc(struct tty_struct *tty, int disc);
 extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
 				 const char *f, int count);
diff --git a/net/nfc/nci/uart.c b/net/nfc/nci/uart.c
index 648c26b4bad8..502e7a3f8948 100644
--- a/net/nfc/nci/uart.c
+++ b/net/nfc/nci/uart.c
@@ -462,7 +462,7 @@ static int __init nci_uart_init(void)
 
 static void __exit nci_uart_exit(void)
 {
-	tty_unregister_ldisc(N_NCI);
+	tty_unregister_ldisc(&nci_uart_ldisc);
 }
 
 module_init(nci_uart_init);
diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c
index fcbb791bf27a..e89548e48364 100644
--- a/sound/soc/ti/ams-delta.c
+++ b/sound/soc/ti/ams-delta.c
@@ -583,7 +583,7 @@ static int ams_delta_remove(struct platform_device *pdev)
 {
 	struct snd_soc_card *card = platform_get_drvdata(pdev);
 
-	if (tty_unregister_ldisc(N_V253) != 0)
+	if (tty_unregister_ldisc(&cx81801_ops) != 0)
 		dev_warn(&pdev->dev,
 			"failed to unregister V253 line discipline\n");
 
-- 
2.31.1


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

* [PATCH 17/35] tty: drop tty_ldisc_ops::refcount
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (15 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 16/35] tty: make tty_ldisc_ops a param in tty_unregister_ldisc Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 18/35] tty: no checking of tty_unregister_ldisc Jiri Slaby
                   ` (19 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

The refcount is checked only in tty_unregister_ldisc and EBUSY returned
if it is nonzero. But none of the tty_unregister_ldisc callers act
anyhow if this (or any other) error is returned. So remove
tty_ldisc_ops::refcount completely and make tty_unregister_ldisc return
'void' in the next patches. That means we assume tty_unregister_ldisc is
not called while the ldisc might be in use. That relies on
try_module_get in get_ldops and module_put in put_ldops.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_tty.c       |  2 +-
 drivers/tty/tty_ldisc.c   | 14 +++-----------
 include/linux/tty_ldisc.h |  2 --
 3 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 2fe27905c398..0ec93f1a61f5 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -2450,7 +2450,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
 {
 	*ops = n_tty_ops;
 	ops->owner = NULL;
-	ops->refcount = ops->flags = 0;
+	ops->flags = 0;
 }
 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
 
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index d02deeb5e584..98e8316fd28a 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -69,7 +69,6 @@ int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc)
 
 	raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
 	tty_ldiscs[new_ldisc->num] = new_ldisc;
-	new_ldisc->refcount = 0;
 	raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
 
 	return ret;
@@ -90,16 +89,12 @@ EXPORT_SYMBOL(tty_register_ldisc);
 int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc)
 {
 	unsigned long flags;
-	int ret = 0;
 
 	raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
-	if (tty_ldiscs[ldisc->num]->refcount)
-		ret = -EBUSY;
-	else
-		tty_ldiscs[ldisc->num] = NULL;
+	tty_ldiscs[ldisc->num] = NULL;
 	raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
 
-	return ret;
+	return 0;
 }
 EXPORT_SYMBOL(tty_unregister_ldisc);
 
@@ -113,10 +108,8 @@ static struct tty_ldisc_ops *get_ldops(int disc)
 	ldops = tty_ldiscs[disc];
 	if (ldops) {
 		ret = ERR_PTR(-EAGAIN);
-		if (try_module_get(ldops->owner)) {
-			ldops->refcount++;
+		if (try_module_get(ldops->owner))
 			ret = ldops;
-		}
 	}
 	raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
 	return ret;
@@ -127,7 +120,6 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
-	ldops->refcount--;
 	module_put(ldops->owner);
 	raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
 }
diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
index c20ca6a75b4c..fbe9de278629 100644
--- a/include/linux/tty_ldisc.h
+++ b/include/linux/tty_ldisc.h
@@ -208,8 +208,6 @@ struct tty_ldisc_ops {
 				const char *fp, int count);
 
 	struct  module *owner;
-
-	int refcount;
 };
 
 struct tty_ldisc {
-- 
2.31.1


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

* [PATCH 18/35] tty: no checking of tty_unregister_ldisc
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (16 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 17/35] tty: drop tty_ldisc_ops::refcount Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 19/35] tty: return void from tty_unregister_ldisc Jiri Slaby
                   ` (18 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, William Hubbs,
	Chris Brannon, Kirk Reiser, Samuel Thibault, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, Arnd Bergmann,
	Wolfgang Grandegger, Marc Kleine-Budde, David S. Miller,
	Jakub Kicinski, Andreas Koensgen, Paul Mackerras,
	Rodolfo Giometti, Peter Ujfalusi, Liam Girdwood, Mark Brown,
	Jaroslav Kysela, Takashi Iwai

tty_unregister_ldisc now returns 0 = success. No need to check the
return value. In fact, the users only warned if an error occured and
didn't do anything useful anyway -- the ldisc module was unloaded in any
case.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: William Hubbs <w.d.hubbs@gmail.com>
Cc: Chris Brannon <chris@the-brannons.com>
Cc: Kirk Reiser <kirk@reisers.ca>
Cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Wolfgang Grandegger <wg@grandegger.com>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Andreas Koensgen <ajk@comnets.uni-bremen.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Rodolfo Giometti <giometti@enneenne.com>
Cc: Peter Ujfalusi <peter.ujfalusi@gmail.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
---
 drivers/accessibility/speakup/spk_ttyio.c |  3 +--
 drivers/bluetooth/hci_ldisc.c             |  7 +------
 drivers/misc/ti-st/st_core.c              | 12 +++---------
 drivers/net/can/slcan.c                   |  4 +---
 drivers/net/hamradio/6pack.c              |  8 +-------
 drivers/net/hamradio/mkiss.c              |  8 +-------
 drivers/net/ppp/ppp_async.c               |  3 +--
 drivers/net/ppp/ppp_synctty.c             |  3 +--
 drivers/net/slip/slip.c                   |  4 +---
 drivers/pps/clients/pps-ldisc.c           |  8 +-------
 drivers/tty/n_gsm.c                       |  5 +----
 drivers/tty/n_hdlc.c                      |  8 +-------
 sound/soc/ti/ams-delta.c                  |  4 +---
 13 files changed, 15 insertions(+), 62 deletions(-)

diff --git a/drivers/accessibility/speakup/spk_ttyio.c b/drivers/accessibility/speakup/spk_ttyio.c
index 0b7f1a87eaeb..0d1f397cd896 100644
--- a/drivers/accessibility/speakup/spk_ttyio.c
+++ b/drivers/accessibility/speakup/spk_ttyio.c
@@ -219,8 +219,7 @@ void spk_ttyio_register_ldisc(void)
 
 void spk_ttyio_unregister_ldisc(void)
 {
-	if (tty_unregister_ldisc(&spk_ttyio_ldisc_ops))
-		pr_warn("speakup: Couldn't unregister ldisc\n");
+	tty_unregister_ldisc(&spk_ttyio_ldisc_ops);
 }
 
 static int spk_ttyio_out(struct spk_synth *in_synth, const char ch)
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 31e0c804363c..5ed2cfa7da1d 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -883,8 +883,6 @@ static int __init hci_uart_init(void)
 
 static void __exit hci_uart_exit(void)
 {
-	int err;
-
 #ifdef CONFIG_BT_HCIUART_H4
 	h4_deinit();
 #endif
@@ -916,10 +914,7 @@ static void __exit hci_uart_exit(void)
 	mrvl_deinit();
 #endif
 
-	/* Release tty registration of line discipline */
-	err = tty_unregister_ldisc(&hci_uart_ldisc);
-	if (err)
-		BT_ERR("Can't unregister HCI line discipline (%d)", err);
+	tty_unregister_ldisc(&hci_uart_ldisc);
 }
 
 module_init(hci_uart_init);
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 174ae8e52805..85315e726644 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -872,9 +872,7 @@ int st_core_init(struct st_data_s **core_data)
 	st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
 	if (!st_gdata) {
 		pr_err("memory allocation failed");
-		err = tty_unregister_ldisc(&st_ldisc_ops);
-		if (err)
-			pr_err("unable to un-register ldisc %ld", err);
+		tty_unregister_ldisc(&st_ldisc_ops);
 		err = -ENOMEM;
 		return err;
 	}
@@ -892,9 +890,7 @@ int st_core_init(struct st_data_s **core_data)
 	if (err) {
 		pr_err("error during st_ll initialization(%ld)", err);
 		kfree(st_gdata);
-		err = tty_unregister_ldisc(&st_ldisc_ops);
-		if (err)
-			pr_err("unable to un-register ldisc");
+		tty_unregister_ldisc(&st_ldisc_ops);
 		return err;
 	}
 
@@ -919,9 +915,7 @@ void st_core_exit(struct st_data_s *st_gdata)
 		kfree_skb(st_gdata->rx_skb);
 		kfree_skb(st_gdata->tx_skb);
 		/* TTY ldisc cleanup */
-		err = tty_unregister_ldisc(&st_ldisc_ops);
-		if (err)
-			pr_err("unable to un-register ldisc %ld", err);
+		tty_unregister_ldisc(&st_ldisc_ops);
 		/* free the global data pointer */
 		kfree(st_gdata);
 	}
diff --git a/drivers/net/can/slcan.c b/drivers/net/can/slcan.c
index 03a2dbd3c367..d42ec7d1bc14 100644
--- a/drivers/net/can/slcan.c
+++ b/drivers/net/can/slcan.c
@@ -784,9 +784,7 @@ static void __exit slcan_exit(void)
 	kfree(slcan_devs);
 	slcan_devs = NULL;
 
-	i = tty_unregister_ldisc(&slc_ldisc);
-	if (i)
-		printk(KERN_ERR "slcan: can't unregister ldisc (err %d)\n", i);
+	tty_unregister_ldisc(&slc_ldisc);
 }
 
 module_init(slcan_init);
diff --git a/drivers/net/hamradio/6pack.c b/drivers/net/hamradio/6pack.c
index aac24f9caceb..686c38c46113 100644
--- a/drivers/net/hamradio/6pack.c
+++ b/drivers/net/hamradio/6pack.c
@@ -774,15 +774,9 @@ static int __init sixpack_init_driver(void)
 	return status;
 }
 
-static const char msg_unregfail[] = KERN_ERR \
-	"6pack: can't unregister line discipline (err = %d)\n";
-
 static void __exit sixpack_exit_driver(void)
 {
-	int ret;
-
-	if ((ret = tty_unregister_ldisc(&sp_ldisc)))
-		printk(msg_unregfail, ret);
+	tty_unregister_ldisc(&sp_ldisc);
 }
 
 /* encode an AX.25 packet into 6pack */
diff --git a/drivers/net/hamradio/mkiss.c b/drivers/net/hamradio/mkiss.c
index 750c6afc9302..e3294a0a9800 100644
--- a/drivers/net/hamradio/mkiss.c
+++ b/drivers/net/hamradio/mkiss.c
@@ -960,15 +960,9 @@ static int __init mkiss_init_driver(void)
 	return status;
 }
 
-static const char msg_unregfail[] = KERN_ERR \
-	"mkiss: can't unregister line discipline (err = %d)\n";
-
 static void __exit mkiss_exit_driver(void)
 {
-	int ret;
-
-	if ((ret = tty_unregister_ldisc(&ax_ldisc)))
-		printk(msg_unregfail, ret);
+	tty_unregister_ldisc(&ax_ldisc);
 }
 
 MODULE_AUTHOR("Ralf Baechle DL5RB <ralf@linux-mips.org>");
diff --git a/drivers/net/ppp/ppp_async.c b/drivers/net/ppp/ppp_async.c
index b2d454d01eba..29a93d6bfe37 100644
--- a/drivers/net/ppp/ppp_async.c
+++ b/drivers/net/ppp/ppp_async.c
@@ -1016,8 +1016,7 @@ static void async_lcp_peek(struct asyncppp *ap, unsigned char *data,
 
 static void __exit ppp_async_cleanup(void)
 {
-	if (tty_unregister_ldisc(&ppp_ldisc) != 0)
-		printk(KERN_ERR "failed to unregister PPP line discipline\n");
+	tty_unregister_ldisc(&ppp_ldisc);
 }
 
 module_init(ppp_async_init);
diff --git a/drivers/net/ppp/ppp_synctty.c b/drivers/net/ppp/ppp_synctty.c
index ca403bde56fb..af3e048695b6 100644
--- a/drivers/net/ppp/ppp_synctty.c
+++ b/drivers/net/ppp/ppp_synctty.c
@@ -727,8 +727,7 @@ ppp_sync_input(struct syncppp *ap, const unsigned char *buf,
 static void __exit
 ppp_sync_cleanup(void)
 {
-	if (tty_unregister_ldisc(&ppp_sync_ldisc) != 0)
-		printk(KERN_ERR "failed to unregister Sync PPP line discipline\n");
+	tty_unregister_ldisc(&ppp_sync_ldisc);
 }
 
 module_init(ppp_sync_init);
diff --git a/drivers/net/slip/slip.c b/drivers/net/slip/slip.c
index 867efff40a0e..dc84cb844319 100644
--- a/drivers/net/slip/slip.c
+++ b/drivers/net/slip/slip.c
@@ -1360,9 +1360,7 @@ static void __exit slip_exit(void)
 	kfree(slip_devs);
 	slip_devs = NULL;
 
-	i = tty_unregister_ldisc(&sl_ldisc);
-	if (i != 0)
-		printk(KERN_ERR "SLIP: can't unregister line discipline (err = %d)\n", i);
+	tty_unregister_ldisc(&sl_ldisc);
 }
 
 module_init(slip_init);
diff --git a/drivers/pps/clients/pps-ldisc.c b/drivers/pps/clients/pps-ldisc.c
index 91b947f37774..d73c4c2ed4e1 100644
--- a/drivers/pps/clients/pps-ldisc.c
+++ b/drivers/pps/clients/pps-ldisc.c
@@ -129,13 +129,7 @@ static int __init pps_tty_init(void)
 
 static void __exit pps_tty_cleanup(void)
 {
-	int err;
-
-	err = tty_unregister_ldisc(&pps_ldisc_ops);
-	if (err)
-		pr_err("can't unregister PPS line discipline\n");
-	else
-		pr_info("PPS line discipline removed\n");
+	tty_unregister_ldisc(&pps_ldisc_ops);
 }
 
 module_init(pps_tty_init);
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index db7d4a30af91..157b26ef6259 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3286,10 +3286,7 @@ static int __init gsm_init(void)
 
 static void __exit gsm_exit(void)
 {
-	int status = tty_unregister_ldisc(&tty_ldisc_packet);
-	if (status != 0)
-		pr_err("n_gsm: can't unregister line discipline (err = %d)\n",
-								status);
+	tty_unregister_ldisc(&tty_ldisc_packet);
 	tty_unregister_driver(gsm_tty_driver);
 	put_tty_driver(gsm_tty_driver);
 }
diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index c2afbfe0a1d5..d899ee4e0116 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -822,13 +822,7 @@ static int __init n_hdlc_init(void)
 
 static void __exit n_hdlc_exit(void)
 {
-	int status = tty_unregister_ldisc(&n_hdlc_ldisc);
-
-	if (status)
-		pr_err("N_HDLC: can't unregister line discipline (err = %d)\n",
-				status);
-	else
-		pr_info("N_HDLC: line discipline unregistered\n");
+	tty_unregister_ldisc(&n_hdlc_ldisc);
 }
 
 module_init(n_hdlc_init);
diff --git a/sound/soc/ti/ams-delta.c b/sound/soc/ti/ams-delta.c
index e89548e48364..ecd24d412a9b 100644
--- a/sound/soc/ti/ams-delta.c
+++ b/sound/soc/ti/ams-delta.c
@@ -583,9 +583,7 @@ static int ams_delta_remove(struct platform_device *pdev)
 {
 	struct snd_soc_card *card = platform_get_drvdata(pdev);
 
-	if (tty_unregister_ldisc(&cx81801_ops) != 0)
-		dev_warn(&pdev->dev,
-			"failed to unregister V253 line discipline\n");
+	tty_unregister_ldisc(&cx81801_ops);
 
 	snd_soc_unregister_card(card);
 	card->dev = NULL;
-- 
2.31.1


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

* [PATCH 19/35] tty: return void from tty_unregister_ldisc
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (17 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 18/35] tty: no checking of tty_unregister_ldisc Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 20/35] ti-st: use goto-failpath in st_core_init Jiri Slaby
                   ` (17 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Now that noone checks the return value of tty_unregister_ldisc, make the
function return 'void'.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/tty_ldisc.c | 4 +---
 include/linux/tty.h     | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 98e8316fd28a..8edd73ab9148 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -86,15 +86,13 @@ EXPORT_SYMBOL(tty_register_ldisc);
  *		takes tty_ldiscs_lock to guard against ldisc races
  */
 
-int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc)
+void tty_unregister_ldisc(struct tty_ldisc_ops *ldisc)
 {
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
 	tty_ldiscs[ldisc->num] = NULL;
 	raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
-
-	return 0;
 }
 EXPORT_SYMBOL(tty_unregister_ldisc);
 
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 6a72d0ff6391..e18a4f1ac39d 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -637,7 +637,7 @@ static inline int tty_port_users(struct tty_port *port)
 }
 
 extern int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc);
-extern int tty_unregister_ldisc(struct tty_ldisc_ops *ldisc);
+extern void tty_unregister_ldisc(struct tty_ldisc_ops *ldisc);
 extern int tty_set_ldisc(struct tty_struct *tty, int disc);
 extern int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
 				 const char *f, int count);
-- 
2.31.1


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

* [PATCH 20/35] ti-st: use goto-failpath in st_core_init
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (18 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 19/35] tty: return void from tty_unregister_ldisc Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 21/35] ti-st: use tty_write_room Jiri Slaby
                   ` (16 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Arnd Bergmann

Use the classic failpath handling using gotos in st_core_init. That way,
tty_unregister_ldisc needs not be repeated on two places.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Arnd Bergmann <arnd@arndb.de>
---
 drivers/misc/ti-st/st_core.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 85315e726644..05c015140cad 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -872,9 +872,8 @@ int st_core_init(struct st_data_s **core_data)
 	st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
 	if (!st_gdata) {
 		pr_err("memory allocation failed");
-		tty_unregister_ldisc(&st_ldisc_ops);
 		err = -ENOMEM;
-		return err;
+		goto err_unreg_ldisc;
 	}
 
 	/* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
@@ -889,15 +888,18 @@ int st_core_init(struct st_data_s **core_data)
 	err = st_ll_init(st_gdata);
 	if (err) {
 		pr_err("error during st_ll initialization(%ld)", err);
-		kfree(st_gdata);
-		tty_unregister_ldisc(&st_ldisc_ops);
-		return err;
+		goto err_free_gdata;
 	}
 
 	INIT_WORK(&st_gdata->work_write_wakeup, work_fn_write_wakeup);
 
 	*core_data = st_gdata;
 	return 0;
+err_free_gdata:
+	kfree(st_gdata);
+err_unreg_ldisc:
+	tty_unregister_ldisc(&st_ldisc_ops);
+	return err;
 }
 
 void st_core_exit(struct st_data_s *st_gdata)
-- 
2.31.1


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

* [PATCH 21/35] ti-st: use tty_write_room
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (19 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 20/35] ti-st: use goto-failpath in st_core_init Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
                   ` (15 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Arnd Bergmann

Don't access tty->ops->write_room directly, use tty_write_room helper
instead.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Arnd Bergmann <arnd@arndb.de>
---
 drivers/misc/ti-st/st_core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index 05c015140cad..7f6976a9f508 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -52,13 +52,12 @@ static void remove_channel_from_table(struct st_data_s *st_gdata,
  */
 int st_get_uart_wr_room(struct st_data_s *st_gdata)
 {
-	struct tty_struct *tty;
 	if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
 		pr_err("tty unavailable to perform write");
 		return -1;
 	}
-	tty = st_gdata->tty;
-	return tty->ops->write_room(tty);
+
+	return tty_write_room(st_gdata->tty);
 }
 
 /*
-- 
2.31.1


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

* [PATCH 22/35] tty: make tty_operations::write_room return uint
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (20 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 21/35] ti-st: use tty_write_room Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:25   ` Geert Uytterhoeven
                     ` (5 more replies)
  2021-05-05  9:19 ` [PATCH 23/35] USB: serial: make usb_serial_driver::write_room " Jiri Slaby
                   ` (14 subsequent siblings)
  36 siblings, 6 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, Geert Uytterhoeven,
	James E.J. Bottomley, Helge Deller, Jeff Dike,
	Richard Weinberger, Anton Ivanov, Chris Zankel, Max Filippov,
	Arnd Bergmann, Samuel Iglesias Gonsalvez, Jens Taprogge,
	Karsten Keil, Scott Branden, Ulf Hansson, David S. Miller,
	Jakub Kicinski, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, David Lin, Johan Hovold, Alex Elder,
	Laurentiu Tudor, Jiri Kosina, David Sterba, Shawn Guo,
	Sascha Hauer, Oliver Neukum, Felipe Balbi, Mathias Nyman,
	Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz

Line disciplines expect a positive value or zero returned from
tty->ops->write_room (invoked by tty_write_room). So make this
assumption explicit by using unsigned int as a return value. Both of
tty->ops->write_room and tty_write_room.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Cc: Jens Taprogge <jens.taprogge@taprogge.org>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Scott Branden <scott.branden@broadcom.com>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: David Sterba <dsterba@suse.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
---
 arch/alpha/kernel/srmcons.c            | 2 +-
 arch/m68k/emu/nfcon.c                  | 2 +-
 arch/parisc/kernel/pdc_cons.c          | 2 +-
 arch/um/drivers/line.c                 | 6 +++---
 arch/um/drivers/line.h                 | 2 +-
 arch/xtensa/platforms/iss/console.c    | 2 +-
 drivers/char/pcmcia/synclink_cs.c      | 2 +-
 drivers/char/ttyprintk.c               | 2 +-
 drivers/ipack/devices/ipoctal.c        | 2 +-
 drivers/isdn/capi/capi.c               | 6 +++---
 drivers/misc/bcm-vk/bcm_vk_tty.c       | 2 +-
 drivers/mmc/core/sdio_uart.c           | 2 +-
 drivers/net/usb/hso.c                  | 4 ++--
 drivers/s390/char/con3215.c            | 2 +-
 drivers/s390/char/sclp_tty.c           | 4 ++--
 drivers/s390/char/sclp_vt220.c         | 4 ++--
 drivers/s390/char/tty3270.c            | 2 +-
 drivers/staging/fwserial/fwserial.c    | 6 +++---
 drivers/staging/gdm724x/gdm_tty.c      | 2 +-
 drivers/staging/greybus/uart.c         | 2 +-
 drivers/tty/amiserial.c                | 2 +-
 drivers/tty/ehv_bytechan.c             | 4 ++--
 drivers/tty/goldfish.c                 | 2 +-
 drivers/tty/hvc/hvc_console.c          | 2 +-
 drivers/tty/hvc/hvcs.c                 | 2 +-
 drivers/tty/hvc/hvsi.c                 | 4 ++--
 drivers/tty/ipwireless/tty.c           | 2 +-
 drivers/tty/mips_ejtag_fdc.c           | 4 ++--
 drivers/tty/moxa.c                     | 8 ++++----
 drivers/tty/mxser.c                    | 2 +-
 drivers/tty/n_gsm.c                    | 2 +-
 drivers/tty/nozomi.c                   | 4 ++--
 drivers/tty/pty.c                      | 2 +-
 drivers/tty/serial/kgdb_nmi.c          | 2 +-
 drivers/tty/serial/serial_core.c       | 4 ++--
 drivers/tty/synclink_gt.c              | 6 +++---
 drivers/tty/tty_ioctl.c                | 2 +-
 drivers/tty/ttynull.c                  | 2 +-
 drivers/tty/vcc.c                      | 4 ++--
 drivers/tty/vt/vt.c                    | 2 +-
 drivers/usb/class/cdc-acm.c            | 2 +-
 drivers/usb/gadget/function/u_serial.c | 6 +++---
 drivers/usb/host/xhci-dbgtty.c         | 4 ++--
 drivers/usb/serial/usb-serial.c        | 2 +-
 include/linux/tty.h                    | 2 +-
 include/linux/tty_driver.h             | 4 ++--
 net/bluetooth/rfcomm/tty.c             | 2 +-
 47 files changed, 71 insertions(+), 71 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index 438b10c44d73..2110b7e7f988 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -142,7 +142,7 @@ srmcons_write(struct tty_struct *tty,
 	return count;
 }
 
-static int
+static unsigned int
 srmcons_write_room(struct tty_struct *tty)
 {
 	return 512;
diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c
index 57e8c8fb5eba..92636c89d65b 100644
--- a/arch/m68k/emu/nfcon.c
+++ b/arch/m68k/emu/nfcon.c
@@ -85,7 +85,7 @@ static int nfcon_tty_put_char(struct tty_struct *tty, unsigned char ch)
 	return 1;
 }
 
-static int nfcon_tty_write_room(struct tty_struct *tty)
+static unsigned int nfcon_tty_write_room(struct tty_struct *tty)
 {
 	return 64;
 }
diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c
index 7ed404c60a9e..fe2ed0bbd07e 100644
--- a/arch/parisc/kernel/pdc_cons.c
+++ b/arch/parisc/kernel/pdc_cons.c
@@ -103,7 +103,7 @@ static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *bu
 	return count;
 }
 
-static int pdc_console_tty_write_room(struct tty_struct *tty)
+static unsigned int pdc_console_tty_write_room(struct tty_struct *tty)
 {
 	return 32768; /* no limit, no buffer used */
 }
diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 1c70a31e7c5b..2b8810ba5470 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -32,7 +32,7 @@ static irqreturn_t line_interrupt(int irq, void *data)
  *
  * Should be called while holding line->lock (this does not modify data).
  */
-static int write_room(struct line *line)
+static unsigned int write_room(struct line *line)
 {
 	int n;
 
@@ -47,11 +47,11 @@ static int write_room(struct line *line)
 	return n - 1;
 }
 
-int line_write_room(struct tty_struct *tty)
+unsigned int line_write_room(struct tty_struct *tty)
 {
 	struct line *line = tty->driver_data;
 	unsigned long flags;
-	int room;
+	unsigned int room;
 
 	spin_lock_irqsave(&line->lock, flags);
 	room = write_room(line);
diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
index 01d21e76144f..861edf329569 100644
--- a/arch/um/drivers/line.h
+++ b/arch/um/drivers/line.h
@@ -70,7 +70,7 @@ extern void line_set_termios(struct tty_struct *tty, struct ktermios * old);
 extern 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);
-extern int line_write_room(struct tty_struct *tty);
+extern unsigned int line_write_room(struct tty_struct *tty);
 extern void line_throttle(struct tty_struct *tty);
 extern void line_unthrottle(struct tty_struct *tty);
 
diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index a3dda25a4e45..98ac3a7fdb0a 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -100,7 +100,7 @@ static void rs_flush_chars(struct tty_struct *tty)
 {
 }
 
-static int rs_write_room(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;
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index b4707bc3aee8..e4b2c68f44f5 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1609,7 +1609,7 @@ static int mgslpc_write(struct tty_struct * tty,
 
 /* Return the count of free bytes in transmit buffer
  */
-static int mgslpc_write_room(struct tty_struct *tty)
+static unsigned int mgslpc_write_room(struct tty_struct *tty)
 {
 	MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
 	int ret;
diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index 93f5d11c830b..e93b0af92339 100644
--- a/drivers/char/ttyprintk.c
+++ b/drivers/char/ttyprintk.c
@@ -132,7 +132,7 @@ static int tpk_write(struct tty_struct *tty,
 /*
  * TTY operations write_room function.
  */
-static int tpk_write_room(struct tty_struct *tty)
+static unsigned int tpk_write_room(struct tty_struct *tty)
 {
 	return TPK_MAX_ROOM;
 }
diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index 3940714e4397..ea0f1aeaaa06 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -460,7 +460,7 @@ static int ipoctal_write_tty(struct tty_struct *tty,
 	return char_copied;
 }
 
-static int ipoctal_write_room(struct tty_struct *tty)
+static unsigned int ipoctal_write_room(struct tty_struct *tty)
 {
 	struct ipoctal_channel *channel = tty->driver_data;
 
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index fdf87acccd06..c50c454006b3 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1175,14 +1175,14 @@ static void capinc_tty_flush_chars(struct tty_struct *tty)
 	handle_minor_recv(mp);
 }
 
-static int capinc_tty_write_room(struct tty_struct *tty)
+static unsigned int capinc_tty_write_room(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
-	int room;
+	unsigned int room;
 
 	room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue);
 	room *= CAPI_MAX_BLKSIZE;
-	pr_debug("capinc_tty_write_room = %d\n", room);
+	pr_debug("capinc_tty_write_room = %u\n", room);
 	return room;
 }
 
diff --git a/drivers/misc/bcm-vk/bcm_vk_tty.c b/drivers/misc/bcm-vk/bcm_vk_tty.c
index 4d02692ecfc7..dae9eeed84a2 100644
--- a/drivers/misc/bcm-vk/bcm_vk_tty.c
+++ b/drivers/misc/bcm-vk/bcm_vk_tty.c
@@ -214,7 +214,7 @@ static int bcm_vk_tty_write(struct tty_struct *tty,
 	return count;
 }
 
-static int bcm_vk_tty_write_room(struct tty_struct *tty)
+static unsigned int bcm_vk_tty_write_room(struct tty_struct *tty)
 {
 	struct bcm_vk *vk = dev_get_drvdata(tty->dev);
 
diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c
index dbcac2b7f2fe..c8f4eca7aad4 100644
--- a/drivers/mmc/core/sdio_uart.c
+++ b/drivers/mmc/core/sdio_uart.c
@@ -797,7 +797,7 @@ static int sdio_uart_write(struct tty_struct *tty, const unsigned char *buf,
 	return ret;
 }
 
-static int sdio_uart_write_room(struct tty_struct *tty)
+static unsigned int sdio_uart_write_room(struct tty_struct *tty)
 {
 	struct sdio_uart_port *port = tty->driver_data;
 	return FIFO_SIZE - kfifo_len(&port->xmit_fifo);
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index 3ef4b2841402..bb8bb85308ab 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1357,10 +1357,10 @@ static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf,
 }
 
 /* how much room is there for writing */
-static int hso_serial_write_room(struct tty_struct *tty)
+static unsigned int hso_serial_write_room(struct tty_struct *tty)
 {
 	struct hso_serial *serial = tty->driver_data;
-	int room;
+	unsigned int room;
 	unsigned long flags;
 
 	spin_lock_irqsave(&serial->serial_lock, flags);
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index 1fd5bca9fa20..c9fd4a05931a 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -924,7 +924,7 @@ static void tty3215_close(struct tty_struct *tty, struct file * filp)
 /*
  * Returns the amount of free space in the output buffer.
  */
-static int tty3215_write_room(struct tty_struct *tty)
+static unsigned int tty3215_write_room(struct tty_struct *tty)
 {
 	struct raw3215_info *raw = tty->driver_data;
 
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index 4456ceb23bd2..ea1e43fd16bc 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -86,12 +86,12 @@ sclp_tty_close(struct tty_struct *tty, struct file *filp)
  * a string of newlines. Every newline creates a new message which
  * needs 82 bytes.
  */
-static int
+static unsigned int
 sclp_tty_write_room (struct tty_struct *tty)
 {
 	unsigned long flags;
 	struct list_head *l;
-	int count;
+	unsigned int count;
 
 	spin_lock_irqsave(&sclp_tty_lock, flags);
 	count = 0;
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index 7f4445b0f819..b621adee35f0 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -609,12 +609,12 @@ sclp_vt220_flush_chars(struct tty_struct *tty)
  * to change as output buffers get emptied, or if the output flow
  * control is acted.
  */
-static int
+static unsigned int
 sclp_vt220_write_room(struct tty_struct *tty)
 {
 	unsigned long flags;
 	struct list_head *l;
-	int count;
+	unsigned int count;
 
 	spin_lock_irqsave(&sclp_vt220_lock, flags);
 	count = 0;
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 1b68564799fa..82d4c961ed06 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -1071,7 +1071,7 @@ static void tty3270_cleanup(struct tty_struct *tty)
 /*
  * We always have room.
  */
-static int
+static unsigned int
 tty3270_write_room(struct tty_struct *tty)
 {
 	return INT_MAX;
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index 4245532d2fe0..a151cd76d24e 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -1113,16 +1113,16 @@ static int fwtty_write(struct tty_struct *tty, const unsigned char *buf, int c)
 	return (n < 0) ? 0 : n;
 }
 
-static int fwtty_write_room(struct tty_struct *tty)
+static unsigned int fwtty_write_room(struct tty_struct *tty)
 {
 	struct fwtty_port *port = tty->driver_data;
-	int n;
+	unsigned int n;
 
 	spin_lock_bh(&port->lock);
 	n = dma_fifo_avail(&port->tx_fifo);
 	spin_unlock_bh(&port->lock);
 
-	fwtty_dbg(port, "%d\n", n);
+	fwtty_dbg(port, "%u\n", n);
 
 	return n;
 }
diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
index 0ccc8c24e754..279de2cd9c4a 100644
--- a/drivers/staging/gdm724x/gdm_tty.c
+++ b/drivers/staging/gdm724x/gdm_tty.c
@@ -183,7 +183,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,
 	return len;
 }
 
-static int gdm_tty_write_room(struct tty_struct *tty)
+static unsigned int gdm_tty_write_room(struct tty_struct *tty)
 {
 	struct gdm *gdm = tty->driver_data;
 
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index b1e63f7798b0..529eccb99b6c 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -440,7 +440,7 @@ static int gb_tty_write(struct tty_struct *tty, const unsigned char *buf,
 	return count;
 }
 
-static int gb_tty_write_room(struct tty_struct *tty)
+static unsigned int gb_tty_write_room(struct tty_struct *tty)
 {
 	struct gb_tty *gb_tty = tty->driver_data;
 	unsigned long flags;
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index a4b8876091d2..ee1f4d72cd5e 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -827,7 +827,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
 	return ret;
 }
 
-static int rs_write_room(struct tty_struct *tty)
+static unsigned int rs_write_room(struct tty_struct *tty)
 {
 	struct serial_state *info = tty->driver_data;
 
diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
index 3c6dd06ec5fb..445e5ff9b36d 100644
--- a/drivers/tty/ehv_bytechan.c
+++ b/drivers/tty/ehv_bytechan.c
@@ -536,11 +536,11 @@ static void ehv_bc_tty_close(struct tty_struct *ttys, struct file *filp)
  * how much write room the driver can guarantee will be sent OR BUFFERED.  This
  * driver MUST honor the return value.
  */
-static int ehv_bc_tty_write_room(struct tty_struct *ttys)
+static unsigned int ehv_bc_tty_write_room(struct tty_struct *ttys)
 {
 	struct ehv_bc_data *bc = ttys->driver_data;
 	unsigned long flags;
-	int count;
+	unsigned int count;
 
 	spin_lock_irqsave(&bc->lock, flags);
 	count = CIRC_SPACE(bc->head, bc->tail, BUF_SIZE);
diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c
index cd23a4b05c8f..e4f9a60dcc18 100644
--- a/drivers/tty/goldfish.c
+++ b/drivers/tty/goldfish.c
@@ -193,7 +193,7 @@ static int goldfish_tty_write(struct tty_struct *tty, const unsigned char *buf,
 	return count;
 }
 
-static int goldfish_tty_write_room(struct tty_struct *tty)
+static unsigned int goldfish_tty_write_room(struct tty_struct *tty)
 {
 	return 0x10000;
 }
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index cdcc64ea2554..a3725eb69cd3 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -586,7 +586,7 @@ static void hvc_set_winsz(struct work_struct *work)
  * how much write room the driver can guarantee will be sent OR BUFFERED.  This
  * driver MUST honor the return value.
  */
-static int hvc_write_room(struct tty_struct *tty)
+static unsigned int hvc_write_room(struct tty_struct *tty)
 {
 	struct hvc_struct *hp = tty->driver_data;
 
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 197988c55e0c..f43f2f94d8bd 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -1376,7 +1376,7 @@ static int hvcs_write(struct tty_struct *tty,
  * absolutely WILL BUFFER if we can't send it.  This driver MUST honor the
  * return value, hence the reason for hvcs_struct buffering.
  */
-static int hvcs_write_room(struct tty_struct *tty)
+static unsigned int hvcs_write_room(struct tty_struct *tty)
 {
 	struct hvcs_struct *hvcsd = tty->driver_data;
 
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index e8c58f9bd263..0a56f44e6b12 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -890,7 +890,7 @@ static void hvsi_write_worker(struct work_struct *work)
 	spin_unlock_irqrestore(&hp->lock, flags);
 }
 
-static int hvsi_write_room(struct tty_struct *tty)
+static unsigned int hvsi_write_room(struct tty_struct *tty)
 {
 	struct hvsi_struct *hp = tty->driver_data;
 
@@ -929,7 +929,7 @@ static int hvsi_write(struct tty_struct *tty,
 	 * will see there is no room in outbuf and return.
 	 */
 	while ((count > 0) && (hvsi_write_room(tty) > 0)) {
-		int chunksize = min(count, hvsi_write_room(tty));
+		int chunksize = min_t(int, count, hvsi_write_room(tty));
 
 		BUG_ON(hp->n_outbuf < 0);
 		memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
index 99bb2f149ff5..ab562838313b 100644
--- a/drivers/tty/ipwireless/tty.c
+++ b/drivers/tty/ipwireless/tty.c
@@ -228,7 +228,7 @@ static int ipw_write(struct tty_struct *linux_tty,
 	return count;
 }
 
-static int ipw_write_room(struct tty_struct *linux_tty)
+static unsigned int ipw_write_room(struct tty_struct *linux_tty)
 {
 	struct ipw_tty *tty = linux_tty->driver_data;
 	int room;
diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c
index a8e19b4833bf..f427e8e154d7 100644
--- a/drivers/tty/mips_ejtag_fdc.c
+++ b/drivers/tty/mips_ejtag_fdc.c
@@ -840,11 +840,11 @@ static int mips_ejtag_fdc_tty_write(struct tty_struct *tty,
 	return total;
 }
 
-static int mips_ejtag_fdc_tty_write_room(struct tty_struct *tty)
+static unsigned int mips_ejtag_fdc_tty_write_room(struct tty_struct *tty)
 {
 	struct mips_ejtag_fdc_tty_port *dport = tty->driver_data;
 	struct mips_ejtag_fdc_tty *priv = dport->driver;
-	int room;
+	unsigned int room;
 
 	/* Report the space in the xmit buffer */
 	spin_lock(&dport->xmit_lock);
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 847ad3dac107..e4fe9315de29 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -188,7 +188,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_room(struct tty_struct *);
+static unsigned int moxa_write_room(struct tty_struct *);
 static void moxa_flush_buffer(struct tty_struct *);
 static int moxa_chars_in_buffer(struct tty_struct *);
 static void moxa_set_termios(struct tty_struct *, struct ktermios *);
@@ -218,7 +218,7 @@ static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int);
 static int MoxaPortReadData(struct moxa_port *);
 static int MoxaPortTxQueue(struct moxa_port *);
 static int MoxaPortRxQueue(struct moxa_port *);
-static int MoxaPortTxFree(struct moxa_port *);
+static unsigned int MoxaPortTxFree(struct moxa_port *);
 static void MoxaPortTxDisable(struct moxa_port *);
 static void MoxaPortTxEnable(struct moxa_port *);
 static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *);
@@ -1217,7 +1217,7 @@ static int moxa_write(struct tty_struct *tty,
 	return len;
 }
 
-static int moxa_write_room(struct tty_struct *tty)
+static unsigned int moxa_write_room(struct tty_struct *tty)
 {
 	struct moxa_port *ch;
 
@@ -1992,7 +1992,7 @@ static int MoxaPortTxQueue(struct moxa_port *port)
 	return (wptr - rptr) & mask;
 }
 
-static int MoxaPortTxFree(struct moxa_port *port)
+static unsigned int MoxaPortTxFree(struct moxa_port *port)
 {
 	void __iomem *ofsAddr = port->tableAddr;
 	u16 rptr, wptr, mask;
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 85271e109014..5851a45d828c 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -1183,7 +1183,7 @@ static void mxser_flush_chars(struct tty_struct *tty)
 	spin_unlock_irqrestore(&info->slock, flags);
 }
 
-static int mxser_write_room(struct tty_struct *tty)
+static unsigned int mxser_write_room(struct tty_struct *tty)
 {
 	struct mxser_port *info = tty->driver_data;
 	int ret;
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 157b26ef6259..06f0c6d39620 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3056,7 +3056,7 @@ static int gsmtty_write(struct tty_struct *tty, const unsigned char *buf,
 	return sent;
 }
 
-static int gsmtty_write_room(struct tty_struct *tty)
+static unsigned int gsmtty_write_room(struct tty_struct *tty)
 {
 	struct gsm_dlci *dlci = tty->driver_data;
 	if (dlci->state == DLCI_CLOSED)
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index 9a2d78ace49b..c55475a9a184 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -1636,10 +1636,10 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
  * If the port is unplugged report lots of room and let the bits
  * dribble away so we don't block anything.
  */
-static int ntty_write_room(struct tty_struct *tty)
+static unsigned int ntty_write_room(struct tty_struct *tty)
 {
 	struct port *port = tty->driver_data;
-	int room = 4096;
+	unsigned int room = 4096;
 	const struct nozomi *dc = get_dc_by_tty(tty);
 
 	if (dc)
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 3e7b5c811f9b..eb8556b19592 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -136,7 +136,7 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
  *	the other device.
  */
 
-static int pty_write_room(struct tty_struct *tty)
+static unsigned int pty_write_room(struct tty_struct *tty)
 {
 	if (tty->flow.stopped)
 		return 0;
diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
index db059b66438e..b193bbc666d4 100644
--- a/drivers/tty/serial/kgdb_nmi.c
+++ b/drivers/tty/serial/kgdb_nmi.c
@@ -298,7 +298,7 @@ static void kgdb_nmi_tty_hangup(struct tty_struct *tty)
 	tty_port_hangup(&priv->port);
 }
 
-static int kgdb_nmi_tty_write_room(struct tty_struct *tty)
+static unsigned int kgdb_nmi_tty_write_room(struct tty_struct *tty)
 {
 	/* Actually, we can handle any amount as we use polled writes. */
 	return 2048;
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 87f7127b57e6..cb46a65a5dd8 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -616,12 +616,12 @@ static int uart_write(struct tty_struct *tty,
 	return ret;
 }
 
-static int uart_write_room(struct tty_struct *tty)
+static unsigned int uart_write_room(struct tty_struct *tty)
 {
 	struct uart_state *state = tty->driver_data;
 	struct uart_port *port;
 	unsigned long flags;
-	int ret;
+	unsigned int ret;
 
 	port = uart_port_lock(state, flags);
 	ret = uart_circ_chars_free(&state->xmit);
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index 1555dccc28af..583aa8342112 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -868,15 +868,15 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
 	DBGINFO(("%s wait_until_sent exit\n", info->device_name));
 }
 
-static int write_room(struct tty_struct *tty)
+static unsigned int write_room(struct tty_struct *tty)
 {
 	struct slgt_info *info = tty->driver_data;
-	int ret;
+	unsigned int ret;
 
 	if (sanity_check(info, tty->name, "write_room"))
 		return 0;
 	ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
-	DBGINFO(("%s write_room=%d\n", info->device_name, ret));
+	DBGINFO(("%s write_room=%u\n", info->device_name, ret));
 	return ret;
 }
 
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 07c88ccfb17a..d8834784b586 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -73,7 +73,7 @@ EXPORT_SYMBOL(tty_chars_in_buffer);
  *	returned and data may be lost as there will be no flow control.
  */
  
-int tty_write_room(struct tty_struct *tty)
+unsigned int tty_write_room(struct tty_struct *tty)
 {
 	if (tty->ops->write_room)
 		return tty->ops->write_room(tty);
diff --git a/drivers/tty/ttynull.c b/drivers/tty/ttynull.c
index 17f05b7eb6d3..af3311a24917 100644
--- a/drivers/tty/ttynull.c
+++ b/drivers/tty/ttynull.c
@@ -35,7 +35,7 @@ static int ttynull_write(struct tty_struct *tty, const unsigned char *buf,
 	return count;
 }
 
-static int ttynull_write_room(struct tty_struct *tty)
+static unsigned int ttynull_write_room(struct tty_struct *tty)
 {
 	return 65536;
 }
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index 0a3a71e14df4..d82ce3bb82c3 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -870,10 +870,10 @@ static int vcc_write(struct tty_struct *tty, const unsigned char *buf,
 	return total_sent ? total_sent : rv;
 }
 
-static int vcc_write_room(struct tty_struct *tty)
+static unsigned int vcc_write_room(struct tty_struct *tty)
 {
 	struct vcc_port *port;
-	u64 num;
+	unsigned int num;
 
 	port = vcc_get_ne(tty->index);
 	if (unlikely(!port)) {
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 706f066eb711..96c130714930 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3263,7 +3263,7 @@ static int con_put_char(struct tty_struct *tty, unsigned char ch)
 	return do_con_write(tty, &ch, 1);
 }
 
-static int con_write_room(struct tty_struct *tty)
+static unsigned int con_write_room(struct tty_struct *tty)
 {
 	if (tty->flow.stopped)
 		return 0;
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index ca7a61190dd9..76b7fd234238 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -838,7 +838,7 @@ static int acm_tty_write(struct tty_struct *tty,
 	return count;
 }
 
-static int acm_tty_write_room(struct tty_struct *tty)
+static unsigned int acm_tty_write_room(struct tty_struct *tty)
 {
 	struct acm *acm = tty->driver_data;
 	/*
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 1e59204ec7aa..676a920d9d6b 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -774,18 +774,18 @@ static void gs_flush_chars(struct tty_struct *tty)
 	spin_unlock_irqrestore(&port->port_lock, flags);
 }
 
-static int gs_write_room(struct tty_struct *tty)
+static unsigned int gs_write_room(struct tty_struct *tty)
 {
 	struct gs_port	*port = tty->driver_data;
 	unsigned long	flags;
-	int		room = 0;
+	unsigned int room = 0;
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	if (port->port_usb)
 		room = kfifo_avail(&port->port_write_buf);
 	spin_unlock_irqrestore(&port->port_lock, flags);
 
-	pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
+	pr_vdebug("gs_write_room: (%d,%p) room=%u\n",
 		port->port_num, tty, room);
 
 	return room;
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index ae4e4ab638b5..cd3ab35dd689 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -240,11 +240,11 @@ static void dbc_tty_flush_chars(struct tty_struct *tty)
 	spin_unlock_irqrestore(&port->port_lock, flags);
 }
 
-static int dbc_tty_write_room(struct tty_struct *tty)
+static unsigned int dbc_tty_write_room(struct tty_struct *tty)
 {
 	struct dbc_port		*port = tty->driver_data;
 	unsigned long		flags;
-	int			room = 0;
+	unsigned int		room;
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	room = kfifo_avail(&port->write_fifo);
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 98b33b1b5357..055096831daf 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -376,7 +376,7 @@ static int serial_write(struct tty_struct *tty, const unsigned char *buf,
 	return retval;
 }
 
-static int serial_write_room(struct tty_struct *tty)
+static unsigned int serial_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 
diff --git a/include/linux/tty.h b/include/linux/tty.h
index e18a4f1ac39d..d18fc34d3054 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -459,7 +459,7 @@ extern void tty_write_message(struct tty_struct *tty, char *msg);
 extern int tty_send_xchar(struct tty_struct *tty, char ch);
 extern int tty_put_char(struct tty_struct *tty, unsigned char c);
 extern int tty_chars_in_buffer(struct tty_struct *tty);
-extern int tty_write_room(struct tty_struct *tty);
+extern unsigned int tty_write_room(struct tty_struct *tty);
 extern void tty_driver_flush_buffer(struct tty_struct *tty);
 extern void tty_throttle(struct tty_struct *tty);
 extern void tty_unthrottle(struct tty_struct *tty);
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index 653fa5af3a22..ea5b15c72764 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -89,7 +89,7 @@
  *
  *	Note: Do not call this function directly, call tty_driver_flush_chars
  * 
- * int  (*write_room)(struct tty_struct *tty);
+ * unsigned int  (*write_room)(struct tty_struct *tty);
  *
  * 	This routine returns the numbers of characters the tty driver
  * 	will accept for queuing to be written.  This number is subject
@@ -256,7 +256,7 @@ struct tty_operations {
 		      const unsigned char *buf, int count);
 	int  (*put_char)(struct tty_struct *tty, unsigned char ch);
 	void (*flush_chars)(struct tty_struct *tty);
-	int  (*write_room)(struct tty_struct *tty);
+	unsigned int (*write_room)(struct tty_struct *tty);
 	int  (*chars_in_buffer)(struct tty_struct *tty);
 	int  (*ioctl)(struct tty_struct *tty,
 		    unsigned int cmd, unsigned long arg);
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index a58584949a95..a5e3d957f20f 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -807,7 +807,7 @@ static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, in
 	return sent;
 }
 
-static int rfcomm_tty_write_room(struct tty_struct *tty)
+static unsigned int rfcomm_tty_write_room(struct tty_struct *tty)
 {
 	struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
 	int room = 0;
-- 
2.31.1


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

* [PATCH 23/35] USB: serial: make usb_serial_driver::write_room return uint
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (21 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-19  9:07   ` Johan Hovold
  2021-05-05  9:19 ` [PATCH 24/35] tty: make tty_buffer_space_avail " Jiri Slaby
                   ` (13 subsequent siblings)
  36 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Johan Hovold, linux-usb

Line disciplines expect a positive value or zero returned from
tty->ops->write_room (invoked by tty_write_room). Both of them were
switched in the previous patch. So now, switch also
usb_serial_driver::write_room and all its users.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Johan Hovold <johan@kernel.org>
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/serial/cyberjack.c        | 4 ++--
 drivers/usb/serial/cypress_m8.c       | 8 ++++----
 drivers/usb/serial/digi_acceleport.c  | 8 ++++----
 drivers/usb/serial/garmin_gps.c       | 2 +-
 drivers/usb/serial/generic.c          | 6 +++---
 drivers/usb/serial/io_edgeport.c      | 6 +++---
 drivers/usb/serial/io_ti.c            | 6 +++---
 drivers/usb/serial/ir-usb.c           | 6 +++---
 drivers/usb/serial/keyspan.c          | 4 ++--
 drivers/usb/serial/kobil_sct.c        | 4 ++--
 drivers/usb/serial/mos7720.c          | 6 +++---
 drivers/usb/serial/mos7840.c          | 7 +++----
 drivers/usb/serial/opticon.c          | 2 +-
 drivers/usb/serial/oti6858.c          | 6 +++---
 drivers/usb/serial/quatech2.c         | 4 ++--
 drivers/usb/serial/sierra.c           | 2 +-
 drivers/usb/serial/ti_usb_3410_5052.c | 8 ++++----
 drivers/usb/serial/usb-wwan.h         | 2 +-
 drivers/usb/serial/usb_wwan.c         | 6 +++---
 include/linux/usb/serial.h            | 4 ++--
 20 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index cf389224d528..51e5aac3bf4c 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -53,7 +53,7 @@ static int  cyberjack_open(struct tty_struct *tty,
 static void cyberjack_close(struct usb_serial_port *port);
 static int cyberjack_write(struct tty_struct *tty,
 	struct usb_serial_port *port, const unsigned char *buf, int count);
-static int cyberjack_write_room(struct tty_struct *tty);
+static unsigned int cyberjack_write_room(struct tty_struct *tty);
 static void cyberjack_read_int_callback(struct urb *urb);
 static void cyberjack_read_bulk_callback(struct urb *urb);
 static void cyberjack_write_bulk_callback(struct urb *urb);
@@ -240,7 +240,7 @@ static int cyberjack_write(struct tty_struct *tty,
 	return count;
 }
 
-static int cyberjack_write_room(struct tty_struct *tty)
+static unsigned int cyberjack_write_room(struct tty_struct *tty)
 {
 	/* FIXME: .... */
 	return CYBERJACK_LOCAL_BUF_SIZE;
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 166ee2286fda..5e7d2f9fa0c2 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -122,7 +122,7 @@ static void cypress_dtr_rts(struct usb_serial_port *port, int on);
 static int  cypress_write(struct tty_struct *tty, struct usb_serial_port *port,
 			const unsigned char *buf, int count);
 static void cypress_send(struct usb_serial_port *port);
-static int  cypress_write_room(struct tty_struct *tty);
+static unsigned int cypress_write_room(struct tty_struct *tty);
 static void cypress_earthmate_init_termios(struct tty_struct *tty);
 static void cypress_set_termios(struct tty_struct *tty,
 			struct usb_serial_port *port, struct ktermios *old);
@@ -789,18 +789,18 @@ static void cypress_send(struct usb_serial_port *port)
 
 
 /* returns how much space is available in the soft buffer */
-static int cypress_write_room(struct tty_struct *tty)
+static unsigned int cypress_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct cypress_private *priv = usb_get_serial_port_data(port);
-	int room = 0;
+	unsigned int room;
 	unsigned long flags;
 
 	spin_lock_irqsave(&priv->lock, flags);
 	room = kfifo_avail(&priv->write_fifo);
 	spin_unlock_irqrestore(&priv->lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
 	return room;
 }
 
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 8b2f06539f2c..5deb900450ee 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -223,7 +223,7 @@ static int digi_tiocmset(struct tty_struct *tty, unsigned int set,
 static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
 		const unsigned char *buf, int count);
 static void digi_write_bulk_callback(struct urb *urb);
-static int digi_write_room(struct tty_struct *tty);
+static unsigned int digi_write_room(struct tty_struct *tty);
 static int digi_chars_in_buffer(struct tty_struct *tty);
 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port);
 static void digi_close(struct usb_serial_port *port);
@@ -1020,11 +1020,11 @@ static void digi_write_bulk_callback(struct urb *urb)
 		tty_port_tty_wakeup(&port->port);
 }
 
-static int digi_write_room(struct tty_struct *tty)
+static unsigned int digi_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct digi_port *priv = usb_get_serial_port_data(port);
-	int room;
+	unsigned int room;
 	unsigned long flags = 0;
 
 	spin_lock_irqsave(&priv->dp_port_lock, flags);
@@ -1035,7 +1035,7 @@ static int digi_write_room(struct tty_struct *tty)
 		room = port->bulk_out_size - 2 - priv->dp_out_buf_len;
 
 	spin_unlock_irqrestore(&priv->dp_port_lock, flags);
-	dev_dbg(&port->dev, "digi_write_room: port=%d, room=%d\n", priv->dp_port_num, room);
+	dev_dbg(&port->dev, "digi_write_room: port=%d, room=%u\n", priv->dp_port_num, room);
 	return room;
 
 }
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index 50e8bdc77e71..756d1ac7e96f 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -1113,7 +1113,7 @@ static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port,
 }
 
 
-static int garmin_write_room(struct tty_struct *tty)
+static unsigned int garmin_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	/*
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index d10aa3d2ee49..bc3cf66af0de 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -230,11 +230,11 @@ int usb_serial_generic_write(struct tty_struct *tty,
 }
 EXPORT_SYMBOL_GPL(usb_serial_generic_write);
 
-int usb_serial_generic_write_room(struct tty_struct *tty)
+unsigned int usb_serial_generic_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	unsigned long flags;
-	int room;
+	unsigned int room;
 
 	if (!port->bulk_out_size)
 		return 0;
@@ -243,7 +243,7 @@ int usb_serial_generic_write_room(struct tty_struct *tty)
 	room = kfifo_avail(&port->write_fifo);
 	spin_unlock_irqrestore(&port->lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
 	return room;
 }
 
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index e6fe3882bf69..f6cedc87d3e4 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -1355,11 +1355,11 @@ static void send_more_port_data(struct edgeport_serial *edge_serial,
  *	we return the amount of room that we have for this port	(the txCredits)
  *	otherwise we return a negative error number.
  *****************************************************************************/
-static int edge_write_room(struct tty_struct *tty)
+static unsigned int edge_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct edgeport_port *edge_port = usb_get_serial_port_data(port);
-	int room;
+	unsigned int room;
 	unsigned long flags;
 
 	if (edge_port == NULL)
@@ -1377,7 +1377,7 @@ static int edge_write_room(struct tty_struct *tty)
 	room = edge_port->txCredits - edge_port->txfifo.count;
 	spin_unlock_irqrestore(&edge_port->ep_lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
 	return room;
 }
 
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 39503fdccebf..94c82c33e629 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2067,11 +2067,11 @@ static void edge_send(struct usb_serial_port *port, struct tty_struct *tty)
 		tty_wakeup(tty);
 }
 
-static int edge_write_room(struct tty_struct *tty)
+static unsigned int edge_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct edgeport_port *edge_port = usb_get_serial_port_data(port);
-	int room = 0;
+	unsigned int room;
 	unsigned long flags;
 
 	if (edge_port == NULL)
@@ -2083,7 +2083,7 @@ static int edge_write_room(struct tty_struct *tty)
 	room = kfifo_avail(&port->write_fifo);
 	spin_unlock_irqrestore(&edge_port->ep_lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
 	return room;
 }
 
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index 172261a908d8..7b44dbea95cd 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -47,7 +47,7 @@ static int xbof = -1;
 static int  ir_startup (struct usb_serial *serial);
 static int ir_write(struct tty_struct *tty, struct usb_serial_port *port,
 		const unsigned char *buf, int count);
-static int ir_write_room(struct tty_struct *tty);
+static unsigned int ir_write_room(struct tty_struct *tty);
 static void ir_write_bulk_callback(struct urb *urb);
 static void ir_process_read_urb(struct urb *urb);
 static void ir_set_termios(struct tty_struct *tty,
@@ -339,10 +339,10 @@ static void ir_write_bulk_callback(struct urb *urb)
 	usb_serial_port_softint(port);
 }
 
-static int ir_write_room(struct tty_struct *tty)
+static unsigned int ir_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
-	int count = 0;
+	unsigned int count = 0;
 
 	if (port->bulk_out_size == 0)
 		return 0;
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index b04a029e3657..87b89c99d517 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1453,13 +1453,13 @@ static void usa67_glocont_callback(struct urb *urb)
 	}
 }
 
-static int keyspan_write_room(struct tty_struct *tty)
+static unsigned int keyspan_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct keyspan_port_private	*p_priv;
 	const struct keyspan_device_details	*d_details;
 	int				flip;
-	int				data_len;
+	unsigned int			data_len;
 	struct urb			*this_urb;
 
 	p_priv = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index a9bc546626ab..4ed8b8b0a361 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -53,7 +53,7 @@ static int  kobil_open(struct tty_struct *tty, struct usb_serial_port *port);
 static void kobil_close(struct usb_serial_port *port);
 static int  kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
 			 const unsigned char *buf, int count);
-static int  kobil_write_room(struct tty_struct *tty);
+static unsigned int kobil_write_room(struct tty_struct *tty);
 static int  kobil_ioctl(struct tty_struct *tty,
 			unsigned int cmd, unsigned long arg);
 static int  kobil_tiocmget(struct tty_struct *tty);
@@ -358,7 +358,7 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port,
 }
 
 
-static int kobil_write_room(struct tty_struct *tty)
+static unsigned int kobil_write_room(struct tty_struct *tty)
 {
 	/* FIXME */
 	return 8;
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 6ee83886e2c9..d9cc7f840d48 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -1033,11 +1033,11 @@ static void mos7720_break(struct tty_struct *tty, int break_state)
  *	If successful, we return the amount of room that we have for this port
  *	Otherwise we return a negative error number.
  */
-static int mos7720_write_room(struct tty_struct *tty)
+static unsigned int mos7720_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct moschip_port *mos7720_port;
-	int room = 0;
+	unsigned int room = 0;
 	int i;
 
 	mos7720_port = usb_get_serial_port_data(port);
@@ -1051,7 +1051,7 @@ static int mos7720_write_room(struct tty_struct *tty)
 			room += URB_TRANSFER_BUFFER_SIZE;
 	}
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
 	return room;
 }
 
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 28e4093794e0..f25d4ba43b9a 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -815,15 +815,14 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
  *	this function is called by the tty driver when it wants to know how many
  *	bytes of data we can accept for a specific port.
  *	If successful, we return the amount of room that we have for this port
- *	Otherwise we return a negative error number.
  *****************************************************************************/
 
-static int mos7840_write_room(struct tty_struct *tty)
+static unsigned int mos7840_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
 	int i;
-	int room = 0;
+	unsigned int room = 0;
 	unsigned long flags;
 
 	spin_lock_irqsave(&mos7840_port->pool_lock, flags);
@@ -834,7 +833,7 @@ static int mos7840_write_room(struct tty_struct *tty)
 	spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
 
 	room = (room == 0) ? 0 : room - URB_TRANSFER_BUFFER_SIZE + 1;
-	dev_dbg(&mos7840_port->port->dev, "%s - returns %d\n", __func__, room);
+	dev_dbg(&mos7840_port->port->dev, "%s - returns %u\n", __func__, room);
 	return room;
 
 }
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index 40c713fae0c3..37b51947bd0b 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -267,7 +267,7 @@ static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
 	return ret;
 }
 
-static int opticon_write_room(struct tty_struct *tty)
+static unsigned int opticon_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct opticon_private *priv = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index 65cd0341fa78..4ab9f335dd0e 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -126,7 +126,7 @@ static void oti6858_read_bulk_callback(struct urb *urb);
 static void oti6858_write_bulk_callback(struct urb *urb);
 static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
 			const unsigned char *buf, int count);
-static int oti6858_write_room(struct tty_struct *tty);
+static unsigned int oti6858_write_room(struct tty_struct *tty);
 static int oti6858_chars_in_buffer(struct tty_struct *tty);
 static int oti6858_tiocmget(struct tty_struct *tty);
 static int oti6858_tiocmset(struct tty_struct *tty,
@@ -363,10 +363,10 @@ static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
 	return count;
 }
 
-static int oti6858_write_room(struct tty_struct *tty)
+static unsigned int oti6858_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
-	int room = 0;
+	unsigned int room;
 	unsigned long flags;
 
 	spin_lock_irqsave(&port->lock, flags);
diff --git a/drivers/usb/serial/quatech2.c b/drivers/usb/serial/quatech2.c
index 5f2e7f668e68..3b5f2032ecdb 100644
--- a/drivers/usb/serial/quatech2.c
+++ b/drivers/usb/serial/quatech2.c
@@ -870,12 +870,12 @@ static void qt2_update_lsr(struct usb_serial_port *port, unsigned char *ch)
 
 }
 
-static int qt2_write_room(struct tty_struct *tty)
+static unsigned int qt2_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct qt2_port_private *port_priv;
 	unsigned long flags = 0;
-	int r;
+	unsigned int r;
 
 	port_priv = usb_get_serial_port_data(port);
 
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 54e16ffc30a0..753cee5d17a1 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -613,7 +613,7 @@ static void sierra_instat_callback(struct urb *urb)
 	}
 }
 
-static int sierra_write_room(struct tty_struct *tty)
+static unsigned int sierra_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct sierra_port_private *portdata = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index caa46ac23db9..2c543c175296 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -307,7 +307,7 @@ static int ti_open(struct tty_struct *tty, struct usb_serial_port *port);
 static void ti_close(struct usb_serial_port *port);
 static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
 		const unsigned char *data, int count);
-static int ti_write_room(struct tty_struct *tty);
+static unsigned int ti_write_room(struct tty_struct *tty);
 static int ti_chars_in_buffer(struct tty_struct *tty);
 static bool ti_tx_empty(struct usb_serial_port *port);
 static void ti_throttle(struct tty_struct *tty);
@@ -810,18 +810,18 @@ static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
 }
 
 
-static int ti_write_room(struct tty_struct *tty)
+static unsigned int ti_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct ti_port *tport = usb_get_serial_port_data(port);
-	int room = 0;
+	unsigned int room;
 	unsigned long flags;
 
 	spin_lock_irqsave(&tport->tp_lock, flags);
 	room = kfifo_avail(&port->write_fifo);
 	spin_unlock_irqrestore(&tport->tp_lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
 	return room;
 }
 
diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h
index b5331d03092f..6c7c9f3309b0 100644
--- a/drivers/usb/serial/usb-wwan.h
+++ b/drivers/usb/serial/usb-wwan.h
@@ -11,7 +11,7 @@ extern int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port);
 extern void usb_wwan_close(struct usb_serial_port *port);
 extern int usb_wwan_port_probe(struct usb_serial_port *port);
 extern void usb_wwan_port_remove(struct usb_serial_port *port);
-extern int usb_wwan_write_room(struct tty_struct *tty);
+extern unsigned int usb_wwan_write_room(struct tty_struct *tty);
 extern int usb_wwan_tiocmget(struct tty_struct *tty);
 extern int usb_wwan_tiocmset(struct tty_struct *tty,
 			     unsigned int set, unsigned int clear);
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 3eb72c59ede6..06212f08d9f9 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -278,12 +278,12 @@ static void usb_wwan_outdat_callback(struct urb *urb)
 	}
 }
 
-int usb_wwan_write_room(struct tty_struct *tty)
+unsigned int usb_wwan_write_room(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct usb_wwan_port_private *portdata;
 	int i;
-	int data_len = 0;
+	unsigned int data_len = 0;
 	struct urb *this_urb;
 
 	portdata = usb_get_serial_port_data(port);
@@ -294,7 +294,7 @@ int usb_wwan_write_room(struct tty_struct *tty)
 			data_len += OUT_BUFLEN;
 	}
 
-	dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
+	dev_dbg(&port->dev, "%s: %u\n", __func__, data_len);
 	return data_len;
 }
 EXPORT_SYMBOL(usb_wwan_write_room);
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 8c63fa9bfc74..6472d1f7b028 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -276,7 +276,7 @@ struct usb_serial_driver {
 	int  (*write)(struct tty_struct *tty, struct usb_serial_port *port,
 			const unsigned char *buf, int count);
 	/* Called only by the tty layer */
-	int  (*write_room)(struct tty_struct *tty);
+	unsigned int (*write_room)(struct tty_struct *tty);
 	int  (*ioctl)(struct tty_struct *tty,
 		      unsigned int cmd, unsigned long arg);
 	void (*get_serial)(struct tty_struct *tty, struct serial_struct *ss);
@@ -347,7 +347,7 @@ int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *por
 		const unsigned char *buf, int count);
 void usb_serial_generic_close(struct usb_serial_port *port);
 int usb_serial_generic_resume(struct usb_serial *serial);
-int usb_serial_generic_write_room(struct tty_struct *tty);
+unsigned int usb_serial_generic_write_room(struct tty_struct *tty);
 int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
 void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout);
 void usb_serial_generic_read_bulk_callback(struct urb *urb);
-- 
2.31.1


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

* [PATCH 24/35] tty: make tty_buffer_space_avail return uint
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (22 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 23/35] USB: serial: make usb_serial_driver::write_room " Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering Jiri Slaby
                   ` (12 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Joel Stanley

tty_buffer_space_avail returns values >= 0, so make it clear by the
return type.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Joel Stanley <joel@jms.id.au>
---
 drivers/tty/serial/8250/8250_aspeed_vuart.c | 4 ++--
 drivers/tty/tty_buffer.c                    | 2 +-
 include/linux/tty_flip.h                    | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_aspeed_vuart.c b/drivers/tty/serial/8250/8250_aspeed_vuart.c
index 61550f24a2d3..92d9a6164dfa 100644
--- a/drivers/tty/serial/8250/8250_aspeed_vuart.c
+++ b/drivers/tty/serial/8250/8250_aspeed_vuart.c
@@ -320,7 +320,7 @@ static int aspeed_vuart_handle_irq(struct uart_port *port)
 {
 	struct uart_8250_port *up = up_to_u8250p(port);
 	unsigned int iir, lsr;
-	int space, count;
+	unsigned int space, count;
 
 	iir = serial_port_in(port, UART_IIR);
 
@@ -346,7 +346,7 @@ static int aspeed_vuart_handle_irq(struct uart_port *port)
 			}
 
 		} else {
-			count = min(space, 256);
+			count = min(space, 256U);
 
 			do {
 				serial8250_read_char(up, lsr);
diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index 55b1f1711341..585a19f65284 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -88,7 +88,7 @@ EXPORT_SYMBOL_GPL(tty_buffer_unlock_exclusive);
  *	pre-allocate if memory guarantee is required).
  */
 
-int tty_buffer_space_avail(struct tty_port *port)
+unsigned int tty_buffer_space_avail(struct tty_port *port)
 {
 	int space = port->buf.mem_limit - atomic_read(&port->buf.mem_used);
 	return max(space, 0);
diff --git a/include/linux/tty_flip.h b/include/linux/tty_flip.h
index 767f62086bd9..d6729281ec50 100644
--- a/include/linux/tty_flip.h
+++ b/include/linux/tty_flip.h
@@ -3,7 +3,7 @@
 #define _LINUX_TTY_FLIP_H
 
 extern int tty_buffer_set_limit(struct tty_port *port, int limit);
-extern int tty_buffer_space_avail(struct tty_port *port);
+extern unsigned int tty_buffer_space_avail(struct tty_port *port);
 extern int tty_buffer_request_room(struct tty_port *port, size_t size);
 extern int tty_insert_flip_string_flags(struct tty_port *port,
 		const unsigned char *chars, const char *flags, size_t size);
-- 
2.31.1


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

* [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (23 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 24/35] tty: make tty_buffer_space_avail " Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05 11:51   ` Max Filippov
  2021-05-06  5:47   ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint Jiri Slaby
                   ` (11 subsequent siblings)
  36 siblings, 2 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Ivan Kokshaysky,
	Matt Turner, James E.J. Bottomley, Helge Deller, Chris Zankel,
	Max Filippov, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger

The only user of tty_ops::chars_in_buffer is tty_chars_in_buffer. And it
considers tty_ops::chars_in_buffer optional. In case it's NULL, zero is
returned. So remove all those chars_in_buffer from tty_ops which return
zero. (Zero means such driver doesn't buffer.)

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
c: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
---
 arch/alpha/kernel/srmcons.c         |  7 -------
 arch/parisc/kernel/pdc_cons.c       |  6 ------
 arch/xtensa/platforms/iss/console.c |  7 -------
 drivers/s390/char/tty3270.c         | 12 ------------
 drivers/tty/pty.c                   | 17 -----------------
 drivers/tty/vt/vt.c                 |  6 ------
 6 files changed, 55 deletions(-)

diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
index 2110b7e7f988..fc03471a0b0f 100644
--- a/arch/alpha/kernel/srmcons.c
+++ b/arch/alpha/kernel/srmcons.c
@@ -148,12 +148,6 @@ srmcons_write_room(struct tty_struct *tty)
 	return 512;
 }
 
-static int
-srmcons_chars_in_buffer(struct tty_struct *tty)
-{
-	return 0;
-}
-
 static int
 srmcons_open(struct tty_struct *tty, struct file *filp)
 {
@@ -200,7 +194,6 @@ static const struct tty_operations srmcons_ops = {
 	.close		= srmcons_close,
 	.write		= srmcons_write,
 	.write_room	= srmcons_write_room,
-	.chars_in_buffer= srmcons_chars_in_buffer,
 };
 
 static int __init
diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c
index fe2ed0bbd07e..39ccad063533 100644
--- a/arch/parisc/kernel/pdc_cons.c
+++ b/arch/parisc/kernel/pdc_cons.c
@@ -108,17 +108,11 @@ static unsigned int pdc_console_tty_write_room(struct tty_struct *tty)
 	return 32768; /* no limit, no buffer used */
 }
 
-static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty)
-{
-	return 0; /* no buffer */
-}
-
 static const struct tty_operations pdc_console_tty_ops = {
 	.open = pdc_console_tty_open,
 	.close = pdc_console_tty_close,
 	.write = pdc_console_tty_write,
 	.write_room = pdc_console_tty_write_room,
-	.chars_in_buffer = pdc_console_tty_chars_in_buffer,
 };
 
 static void pdc_console_poll(struct timer_list *unused)
diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
index 98ac3a7fdb0a..21184488c277 100644
--- a/arch/xtensa/platforms/iss/console.c
+++ b/arch/xtensa/platforms/iss/console.c
@@ -106,12 +106,6 @@ static unsigned int rs_write_room(struct tty_struct *tty)
 	return 2 * 1024;
 }
 
-static int rs_chars_in_buffer(struct tty_struct *tty)
-{
-	/* the iss doesn't buffer characters */
-	return 0;
-}
-
 static void rs_hangup(struct tty_struct *tty)
 {
 	/* Stub, once again.. */
@@ -135,7 +129,6 @@ static const struct tty_operations serial_ops = {
 	.put_char = rs_put_char,
 	.flush_chars = rs_flush_chars,
 	.write_room = rs_write_room,
-	.chars_in_buffer = rs_chars_in_buffer,
 	.hangup = rs_hangup,
 	.wait_until_sent = rs_wait_until_sent,
 	.proc_show = rs_proc_show,
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index 82d4c961ed06..ba1fbce63fee 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -1756,17 +1756,6 @@ tty3270_flush_chars(struct tty_struct *tty)
 	}
 }
 
-/*
- * Returns the number of characters in the output buffer. This is
- * used in tty_wait_until_sent to wait until all characters have
- * appeared on the screen.
- */
-static int
-tty3270_chars_in_buffer(struct tty_struct *tty)
-{
-	return 0;
-}
-
 static void
 tty3270_flush_buffer(struct tty_struct *tty)
 {
@@ -1892,7 +1881,6 @@ static const struct tty_operations tty3270_ops = {
 	.put_char = tty3270_put_char,
 	.flush_chars = tty3270_flush_chars,
 	.write_room = tty3270_write_room,
-	.chars_in_buffer = tty3270_chars_in_buffer,
 	.flush_buffer = tty3270_flush_buffer,
 	.throttle = tty3270_throttle,
 	.unthrottle = tty3270_unthrottle,
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index eb8556b19592..5ada7e9381eb 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -143,19 +143,6 @@ static unsigned int pty_write_room(struct tty_struct *tty)
 	return tty_buffer_space_avail(tty->link->port);
 }
 
-/**
- *	pty_chars_in_buffer	-	characters currently in our tx queue
- *	@tty: our tty
- *
- *	Report how much we have in the transmit queue. As everything is
- *	instantly at the other end this is easy to implement.
- */
-
-static int pty_chars_in_buffer(struct tty_struct *tty)
-{
-	return 0;
-}
-
 /* Set the lock flag on a pty */
 static int pty_set_lock(struct tty_struct *tty, int __user *arg)
 {
@@ -525,7 +512,6 @@ static const struct tty_operations master_pty_ops_bsd = {
 	.write = pty_write,
 	.write_room = pty_write_room,
 	.flush_buffer = pty_flush_buffer,
-	.chars_in_buffer = pty_chars_in_buffer,
 	.unthrottle = pty_unthrottle,
 	.ioctl = pty_bsd_ioctl,
 	.compat_ioctl = pty_bsd_compat_ioctl,
@@ -541,7 +527,6 @@ static const struct tty_operations slave_pty_ops_bsd = {
 	.write = pty_write,
 	.write_room = pty_write_room,
 	.flush_buffer = pty_flush_buffer,
-	.chars_in_buffer = pty_chars_in_buffer,
 	.unthrottle = pty_unthrottle,
 	.set_termios = pty_set_termios,
 	.cleanup = pty_cleanup,
@@ -776,7 +761,6 @@ static const struct tty_operations ptm_unix98_ops = {
 	.write = pty_write,
 	.write_room = pty_write_room,
 	.flush_buffer = pty_flush_buffer,
-	.chars_in_buffer = pty_chars_in_buffer,
 	.unthrottle = pty_unthrottle,
 	.ioctl = pty_unix98_ioctl,
 	.compat_ioctl = pty_unix98_compat_ioctl,
@@ -794,7 +778,6 @@ static const struct tty_operations pty_unix98_ops = {
 	.write = pty_write,
 	.write_room = pty_write_room,
 	.flush_buffer = pty_flush_buffer,
-	.chars_in_buffer = pty_chars_in_buffer,
 	.unthrottle = pty_unthrottle,
 	.set_termios = pty_set_termios,
 	.start = pty_start,
diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
index 96c130714930..b838f656f4cd 100644
--- a/drivers/tty/vt/vt.c
+++ b/drivers/tty/vt/vt.c
@@ -3270,11 +3270,6 @@ static unsigned int con_write_room(struct tty_struct *tty)
 	return 32768;		/* No limit, really; we're not buffering */
 }
 
-static int con_chars_in_buffer(struct tty_struct *tty)
-{
-	return 0;		/* we're not buffering */
-}
-
 /*
  * con_throttle and con_unthrottle are only used for
  * paste_selection(), which has to stuff in a large number of
@@ -3521,7 +3516,6 @@ static const struct tty_operations con_ops = {
 	.write_room = con_write_room,
 	.put_char = con_put_char,
 	.flush_chars = con_flush_chars,
-	.chars_in_buffer = con_chars_in_buffer,
 	.ioctl = vt_ioctl,
 #ifdef CONFIG_COMPAT
 	.compat_ioctl = vt_compat_ioctl,
-- 
2.31.1


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

* [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (24 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05 10:34   ` Anton Ivanov
  2021-05-05 10:43   ` David Sterba
  2021-05-05  9:19 ` [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer " Jiri Slaby
                   ` (10 subsequent siblings)
  36 siblings, 2 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Jeff Dike,
	Richard Weinberger, Anton Ivanov, Arnd Bergmann,
	Samuel Iglesias Gonsalvez, Jens Taprogge, Karsten Keil,
	Ulf Hansson, David S. Miller, Jakub Kicinski, Heiko Carstens,
	Vasily Gorbik, Christian Borntraeger, David Lin, Johan Hovold,
	Alex Elder, Jiri Kosina, David Sterba, Shawn Guo, Sascha Hauer,
	Oliver Neukum, Felipe Balbi, Mathias Nyman, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz

tty_operations::chars_in_buffer is another hook which is expected to
return values >= 0. So make it explicit by the return type too -- use
unsigned int.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
Cc: Jens Taprogge <jens.taprogge@taprogge.org>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Jiri Kosina <jikos@kernel.org>
Cc: David Sterba <dsterba@suse.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Oliver Neukum <oneukum@suse.com>
Cc: Felipe Balbi <balbi@kernel.org>
Cc: Mathias Nyman <mathias.nyman@intel.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
---
 arch/um/drivers/line.c                 |  4 ++--
 arch/um/drivers/line.h                 |  2 +-
 drivers/char/pcmcia/synclink_cs.c      |  6 +++---
 drivers/ipack/devices/ipoctal.c        |  2 +-
 drivers/isdn/capi/capi.c               |  2 +-
 drivers/mmc/core/sdio_uart.c           |  2 +-
 drivers/net/usb/hso.c                  |  4 ++--
 drivers/s390/char/con3215.c            |  2 +-
 drivers/s390/char/sclp_rw.c            |  4 ++--
 drivers/s390/char/sclp_rw.h            |  2 +-
 drivers/s390/char/sclp_tty.c           |  5 ++---
 drivers/s390/char/sclp_vt220.c         |  5 ++---
 drivers/staging/fwserial/fwserial.c    |  6 +++---
 drivers/staging/greybus/uart.c         |  4 ++--
 drivers/tty/amiserial.c                |  2 +-
 drivers/tty/goldfish.c                 |  2 +-
 drivers/tty/hvc/hvc_console.c          |  2 +-
 drivers/tty/hvc/hvcs.c                 |  2 +-
 drivers/tty/hvc/hvsi.c                 |  2 +-
 drivers/tty/ipwireless/tty.c           |  2 +-
 drivers/tty/mips_ejtag_fdc.c           |  4 ++--
 drivers/tty/moxa.c                     | 10 +++++-----
 drivers/tty/mxser.c                    |  2 +-
 drivers/tty/n_gsm.c                    |  2 +-
 drivers/tty/nozomi.c                   |  2 +-
 drivers/tty/serial/serial_core.c       |  4 ++--
 drivers/tty/synclink_gt.c              |  6 +++---
 drivers/tty/tty_ioctl.c                |  2 +-
 drivers/tty/vcc.c                      |  4 ++--
 drivers/usb/class/cdc-acm.c            |  2 +-
 drivers/usb/gadget/function/u_serial.c |  6 +++---
 drivers/usb/host/xhci-dbgtty.c         |  4 ++--
 drivers/usb/serial/usb-serial.c        |  2 +-
 include/linux/tty.h                    |  2 +-
 include/linux/tty_driver.h             |  2 +-
 net/bluetooth/rfcomm/tty.c             |  2 +-
 36 files changed, 58 insertions(+), 60 deletions(-)

diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 2b8810ba5470..159434851417 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -60,11 +60,11 @@ unsigned int line_write_room(struct tty_struct *tty)
 	return room;
 }
 
-int line_chars_in_buffer(struct tty_struct *tty)
+unsigned int line_chars_in_buffer(struct tty_struct *tty)
 {
 	struct line *line = tty->driver_data;
 	unsigned long flags;
-	int ret;
+	unsigned int ret;
 
 	spin_lock_irqsave(&line->lock, flags);
 	/* write_room subtracts 1 for the needed NULL, so we readd it.*/
diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
index 861edf329569..3325e2bc64e4 100644
--- a/arch/um/drivers/line.h
+++ b/arch/um/drivers/line.h
@@ -67,7 +67,7 @@ extern int line_setup(char **conf, unsigned nlines, char **def,
 extern int line_write(struct tty_struct *tty, const unsigned char *buf,
 		      int len);
 extern void line_set_termios(struct tty_struct *tty, struct ktermios * old);
-extern int line_chars_in_buffer(struct tty_struct *tty);
+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);
 extern unsigned int line_write_room(struct tty_struct *tty);
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index e4b2c68f44f5..9f7420bc5026 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1637,10 +1637,10 @@ static unsigned int mgslpc_write_room(struct tty_struct *tty)
 
 /* Return the count of bytes in transmit buffer
  */
-static int mgslpc_chars_in_buffer(struct tty_struct *tty)
+static unsigned int mgslpc_chars_in_buffer(struct tty_struct *tty)
 {
 	MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
-	int rc;
+	unsigned int rc;
 
 	if (debug_level >= DEBUG_LEVEL_INFO)
 		printk("%s(%d):mgslpc_chars_in_buffer(%s)\n",
@@ -1655,7 +1655,7 @@ static int mgslpc_chars_in_buffer(struct tty_struct *tty)
 		rc = info->tx_count;
 
 	if (debug_level >= DEBUG_LEVEL_INFO)
-		printk("%s(%d):mgslpc_chars_in_buffer(%s)=%d\n",
+		printk("%s(%d):mgslpc_chars_in_buffer(%s)=%u\n",
 			 __FILE__, __LINE__, info->device_name, rc);
 
 	return rc;
diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
index ea0f1aeaaa06..0a3b89c17d08 100644
--- a/drivers/ipack/devices/ipoctal.c
+++ b/drivers/ipack/devices/ipoctal.c
@@ -467,7 +467,7 @@ static unsigned int ipoctal_write_room(struct tty_struct *tty)
 	return PAGE_SIZE - channel->nb_bytes;
 }
 
-static int ipoctal_chars_in_buffer(struct tty_struct *tty)
+static unsigned int ipoctal_chars_in_buffer(struct tty_struct *tty)
 {
 	struct ipoctal_channel *channel = tty->driver_data;
 
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index c50c454006b3..dae80197ad9c 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1186,7 +1186,7 @@ static unsigned int capinc_tty_write_room(struct tty_struct *tty)
 	return room;
 }
 
-static int capinc_tty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int capinc_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
 
diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c
index c8f4eca7aad4..c36242b86b1d 100644
--- a/drivers/mmc/core/sdio_uart.c
+++ b/drivers/mmc/core/sdio_uart.c
@@ -803,7 +803,7 @@ static unsigned int sdio_uart_write_room(struct tty_struct *tty)
 	return FIFO_SIZE - kfifo_len(&port->xmit_fifo);
 }
 
-static int sdio_uart_chars_in_buffer(struct tty_struct *tty)
+static unsigned int sdio_uart_chars_in_buffer(struct tty_struct *tty)
 {
 	struct sdio_uart_port *port = tty->driver_data;
 	return kfifo_len(&port->xmit_fifo);
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index bb8bb85308ab..c7563ed3ac31 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -1404,11 +1404,11 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
 }
 
 /* how many characters in the buffer */
-static int hso_serial_chars_in_buffer(struct tty_struct *tty)
+static unsigned int hso_serial_chars_in_buffer(struct tty_struct *tty)
 {
 	struct hso_serial *serial = tty->driver_data;
-	int chars;
 	unsigned long flags;
+	unsigned int chars;
 
 	/* sanity check */
 	if (serial == NULL)
diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
index c9fd4a05931a..8821927ef875 100644
--- a/drivers/s390/char/con3215.c
+++ b/drivers/s390/char/con3215.c
@@ -980,7 +980,7 @@ static void tty3215_flush_chars(struct tty_struct *tty)
 /*
  * Returns the number of characters in the output buffer
  */
-static int tty3215_chars_in_buffer(struct tty_struct *tty)
+static unsigned int tty3215_chars_in_buffer(struct tty_struct *tty)
 {
 	struct raw3215_info *raw = tty->driver_data;
 
diff --git a/drivers/s390/char/sclp_rw.c b/drivers/s390/char/sclp_rw.c
index d6c84e354df5..5a1bf6eaa9d9 100644
--- a/drivers/s390/char/sclp_rw.c
+++ b/drivers/s390/char/sclp_rw.c
@@ -325,10 +325,10 @@ sclp_buffer_space(struct sclp_buffer *buffer)
 /*
  * Return number of characters in buffer
  */
-int
+unsigned int
 sclp_chars_in_buffer(struct sclp_buffer *buffer)
 {
-	int count;
+	unsigned int count;
 
 	count = buffer->char_sum;
 	if (buffer->current_line != NULL)
diff --git a/drivers/s390/char/sclp_rw.h b/drivers/s390/char/sclp_rw.h
index 93d706e4935c..b4506be79246 100644
--- a/drivers/s390/char/sclp_rw.h
+++ b/drivers/s390/char/sclp_rw.h
@@ -86,7 +86,7 @@ void *sclp_unmake_buffer(struct sclp_buffer *);
 int sclp_buffer_space(struct sclp_buffer *);
 int sclp_write(struct sclp_buffer *buffer, const unsigned char *, int);
 int sclp_emit_buffer(struct sclp_buffer *,void (*)(struct sclp_buffer *,int));
-int sclp_chars_in_buffer(struct sclp_buffer *);
+unsigned int sclp_chars_in_buffer(struct sclp_buffer *);
 
 #ifdef CONFIG_SCLP_CONSOLE
 void sclp_console_pm_event(enum sclp_pm_event sclp_pm_event);
diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
index ea1e43fd16bc..162127ff7845 100644
--- a/drivers/s390/char/sclp_tty.c
+++ b/drivers/s390/char/sclp_tty.c
@@ -280,16 +280,15 @@ sclp_tty_flush_chars(struct tty_struct *tty)
  * characters in the write buffer (will not be written as long as there is a
  * final line feed missing).
  */
-static int
+static unsigned int
 sclp_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	unsigned long flags;
 	struct list_head *l;
 	struct sclp_buffer *t;
-	int count;
+	unsigned int count = 0;
 
 	spin_lock_irqsave(&sclp_tty_lock, flags);
-	count = 0;
 	if (sclp_ttybuf != NULL)
 		count = sclp_chars_in_buffer(sclp_ttybuf);
 	list_for_each(l, &sclp_tty_outqueue) {
diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
index b621adee35f0..24eb3a0b0a9a 100644
--- a/drivers/s390/char/sclp_vt220.c
+++ b/drivers/s390/char/sclp_vt220.c
@@ -629,16 +629,15 @@ sclp_vt220_write_room(struct tty_struct *tty)
 /*
  * Return number of buffered chars.
  */
-static int
+static unsigned int
 sclp_vt220_chars_in_buffer(struct tty_struct *tty)
 {
 	unsigned long flags;
 	struct list_head *l;
 	struct sclp_vt220_request *r;
-	int count;
+	unsigned int count = 0;
 
 	spin_lock_irqsave(&sclp_vt220_lock, flags);
-	count = 0;
 	if (sclp_vt220_current_request != NULL)
 		count = sclp_vt220_chars_stored(sclp_vt220_current_request);
 	list_for_each(l, &sclp_vt220_outqueue) {
diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
index a151cd76d24e..d2b286ea27c5 100644
--- a/drivers/staging/fwserial/fwserial.c
+++ b/drivers/staging/fwserial/fwserial.c
@@ -1127,16 +1127,16 @@ static unsigned int fwtty_write_room(struct tty_struct *tty)
 	return n;
 }
 
-static int fwtty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int fwtty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct fwtty_port *port = tty->driver_data;
-	int n;
+	unsigned int n;
 
 	spin_lock_bh(&port->lock);
 	n = dma_fifo_level(&port->tx_fifo);
 	spin_unlock_bh(&port->lock);
 
-	fwtty_dbg(port, "%d\n", n);
+	fwtty_dbg(port, "%u\n", n);
 
 	return n;
 }
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index 529eccb99b6c..ccfaa0f21b9c 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -457,11 +457,11 @@ static unsigned int gb_tty_write_room(struct tty_struct *tty)
 	return room;
 }
 
-static int gb_tty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int gb_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct gb_tty *gb_tty = tty->driver_data;
 	unsigned long flags;
-	int chars;
+	unsigned int chars;
 
 	spin_lock_irqsave(&gb_tty->write_lock, flags);
 	chars = kfifo_len(&gb_tty->write_fifo);
diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
index ee1f4d72cd5e..5ec19c48fb7a 100644
--- a/drivers/tty/amiserial.c
+++ b/drivers/tty/amiserial.c
@@ -834,7 +834,7 @@ static unsigned int rs_write_room(struct tty_struct *tty)
 	return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
 }
 
-static int rs_chars_in_buffer(struct tty_struct *tty)
+static unsigned int rs_chars_in_buffer(struct tty_struct *tty)
 {
 	struct serial_state *info = tty->driver_data;
 
diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c
index e4f9a60dcc18..ccb683a6e6f5 100644
--- a/drivers/tty/goldfish.c
+++ b/drivers/tty/goldfish.c
@@ -198,7 +198,7 @@ static unsigned int goldfish_tty_write_room(struct tty_struct *tty)
 	return 0x10000;
 }
 
-static int goldfish_tty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int goldfish_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct goldfish_tty *qtty = &goldfish_ttys[tty->index];
 	void __iomem *base = qtty->base;
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
index a3725eb69cd3..d0f0253fb93e 100644
--- a/drivers/tty/hvc/hvc_console.c
+++ b/drivers/tty/hvc/hvc_console.c
@@ -596,7 +596,7 @@ static unsigned int hvc_write_room(struct tty_struct *tty)
 	return hp->outbuf_size - hp->n_outbuf;
 }
 
-static int hvc_chars_in_buffer(struct tty_struct *tty)
+static unsigned int hvc_chars_in_buffer(struct tty_struct *tty)
 {
 	struct hvc_struct *hp = tty->driver_data;
 
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index f43f2f94d8bd..fe5e6b4f43de 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -1386,7 +1386,7 @@ static unsigned int hvcs_write_room(struct tty_struct *tty)
 	return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
 }
 
-static int hvcs_chars_in_buffer(struct tty_struct *tty)
+static unsigned int hvcs_chars_in_buffer(struct tty_struct *tty)
 {
 	struct hvcs_struct *hvcsd = tty->driver_data;
 
diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
index 0a56f44e6b12..bfc15279d5bc 100644
--- a/drivers/tty/hvc/hvsi.c
+++ b/drivers/tty/hvc/hvsi.c
@@ -897,7 +897,7 @@ static unsigned int hvsi_write_room(struct tty_struct *tty)
 	return N_OUTBUF - hp->n_outbuf;
 }
 
-static int hvsi_chars_in_buffer(struct tty_struct *tty)
+static unsigned int hvsi_chars_in_buffer(struct tty_struct *tty)
 {
 	struct hvsi_struct *hp = tty->driver_data;
 
diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
index ab562838313b..e01ca68f24f4 100644
--- a/drivers/tty/ipwireless/tty.c
+++ b/drivers/tty/ipwireless/tty.c
@@ -270,7 +270,7 @@ static int ipwireless_set_serial_info(struct tty_struct *linux_tty,
 	return 0;	/* Keeps the PCMCIA scripts happy. */
 }
 
-static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
+static unsigned int ipw_chars_in_buffer(struct tty_struct *linux_tty)
 {
 	struct ipw_tty *tty = linux_tty->driver_data;
 
diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c
index f427e8e154d7..3b5915b94fac 100644
--- a/drivers/tty/mips_ejtag_fdc.c
+++ b/drivers/tty/mips_ejtag_fdc.c
@@ -854,10 +854,10 @@ static unsigned int mips_ejtag_fdc_tty_write_room(struct tty_struct *tty)
 	return room;
 }
 
-static int mips_ejtag_fdc_tty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int mips_ejtag_fdc_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct mips_ejtag_fdc_tty_port *dport = tty->driver_data;
-	int chars;
+	unsigned int chars;
 
 	/* Report the number of bytes in the xmit buffer */
 	spin_lock(&dport->xmit_lock);
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index e4fe9315de29..64b18177c790 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -190,7 +190,7 @@ static void moxa_close(struct tty_struct *, struct file *);
 static int moxa_write(struct tty_struct *, const unsigned char *, int);
 static unsigned int moxa_write_room(struct tty_struct *);
 static void moxa_flush_buffer(struct tty_struct *);
-static int moxa_chars_in_buffer(struct tty_struct *);
+static unsigned int moxa_chars_in_buffer(struct tty_struct *);
 static void moxa_set_termios(struct tty_struct *, struct ktermios *);
 static void moxa_stop(struct tty_struct *);
 static void moxa_start(struct tty_struct *);
@@ -216,7 +216,7 @@ static int MoxaPortLineStatus(struct moxa_port *);
 static void MoxaPortFlushData(struct moxa_port *, int);
 static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int);
 static int MoxaPortReadData(struct moxa_port *);
-static int MoxaPortTxQueue(struct moxa_port *);
+static unsigned int MoxaPortTxQueue(struct moxa_port *);
 static int MoxaPortRxQueue(struct moxa_port *);
 static unsigned int MoxaPortTxFree(struct moxa_port *);
 static void MoxaPortTxDisable(struct moxa_port *);
@@ -1239,10 +1239,10 @@ static void moxa_flush_buffer(struct tty_struct *tty)
 	tty_wakeup(tty);
 }
 
-static int moxa_chars_in_buffer(struct tty_struct *tty)
+static unsigned int moxa_chars_in_buffer(struct tty_struct *tty)
 {
 	struct moxa_port *ch = tty->driver_data;
-	int chars;
+	unsigned int chars;
 
 	chars = MoxaPortTxQueue(ch);
 	if (chars)
@@ -1981,7 +1981,7 @@ static int MoxaPortReadData(struct moxa_port *port)
 }
 
 
-static int MoxaPortTxQueue(struct moxa_port *port)
+static unsigned int MoxaPortTxQueue(struct moxa_port *port)
 {
 	void __iomem *ofsAddr = port->tableAddr;
 	u16 rptr, wptr, mask;
diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 5851a45d828c..a74e6146a748 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -1192,7 +1192,7 @@ static unsigned int mxser_write_room(struct tty_struct *tty)
 	return ret < 0 ? 0 : ret;
 }
 
-static int mxser_chars_in_buffer(struct tty_struct *tty)
+static unsigned int mxser_chars_in_buffer(struct tty_struct *tty)
 {
 	struct mxser_port *info = tty->driver_data;
 	return info->xmit_cnt;
diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index 06f0c6d39620..bd24dc0d7e96 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -3064,7 +3064,7 @@ static unsigned int gsmtty_write_room(struct tty_struct *tty)
 	return TX_SIZE - kfifo_len(&dlci->fifo);
 }
 
-static int gsmtty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int gsmtty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct gsm_dlci *dlci = tty->driver_data;
 	if (dlci->state == DLCI_CLOSED)
diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index c55475a9a184..62c16731ccd8 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -1776,7 +1776,7 @@ static void ntty_throttle(struct tty_struct *tty)
 }
 
 /* Returns number of chars in buffer, called by tty layer */
-static s32 ntty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int ntty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct port *port = tty->driver_data;
 	struct nozomi *dc = get_dc_by_tty(tty);
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index cb46a65a5dd8..d29329eb52f4 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -629,12 +629,12 @@ static unsigned int uart_write_room(struct tty_struct *tty)
 	return ret;
 }
 
-static int uart_chars_in_buffer(struct tty_struct *tty)
+static unsigned int uart_chars_in_buffer(struct tty_struct *tty)
 {
 	struct uart_state *state = tty->driver_data;
 	struct uart_port *port;
 	unsigned long flags;
-	int ret;
+	unsigned int ret;
 
 	port = uart_port_lock(state, flags);
 	ret = uart_circ_chars_pending(&state->xmit);
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index 583aa8342112..cf87dc66087b 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -1254,14 +1254,14 @@ static int synclink_gt_proc_show(struct seq_file *m, void *v)
 /*
  * return count of bytes in transmit buffer
  */
-static int chars_in_buffer(struct tty_struct *tty)
+static unsigned int chars_in_buffer(struct tty_struct *tty)
 {
 	struct slgt_info *info = tty->driver_data;
-	int count;
+	unsigned int count;
 	if (sanity_check(info, tty->name, "chars_in_buffer"))
 		return 0;
 	count = tbuf_bytes(info);
-	DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count));
+	DBGINFO(("%s chars_in_buffer()=%u\n", info->device_name, count));
 	return count;
 }
 
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index d8834784b586..aa9ecc8be990 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -54,7 +54,7 @@
  *	to be no queue on the device.
  */
 
-int tty_chars_in_buffer(struct tty_struct *tty)
+unsigned int tty_chars_in_buffer(struct tty_struct *tty)
 {
 	if (tty->ops->chars_in_buffer)
 		return tty->ops->chars_in_buffer(tty);
diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
index d82ce3bb82c3..e883b8f12099 100644
--- a/drivers/tty/vcc.c
+++ b/drivers/tty/vcc.c
@@ -888,10 +888,10 @@ static unsigned int vcc_write_room(struct tty_struct *tty)
 	return num;
 }
 
-static int vcc_chars_in_buffer(struct tty_struct *tty)
+static unsigned int vcc_chars_in_buffer(struct tty_struct *tty)
 {
 	struct vcc_port *port;
-	u64 num;
+	unsigned int num;
 
 	port = vcc_get_ne(tty->index);
 	if (unlikely(!port)) {
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 76b7fd234238..81199efe0312 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -848,7 +848,7 @@ static unsigned int acm_tty_write_room(struct tty_struct *tty)
 	return acm_wb_is_avail(acm) ? acm->writesize : 0;
 }
 
-static int acm_tty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int acm_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct acm *acm = tty->driver_data;
 	/*
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index 676a920d9d6b..bffef8e47dac 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -791,17 +791,17 @@ static unsigned int gs_write_room(struct tty_struct *tty)
 	return room;
 }
 
-static int gs_chars_in_buffer(struct tty_struct *tty)
+static unsigned int gs_chars_in_buffer(struct tty_struct *tty)
 {
 	struct gs_port	*port = tty->driver_data;
 	unsigned long	flags;
-	int		chars = 0;
+	unsigned int	chars;
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	chars = kfifo_len(&port->port_write_buf);
 	spin_unlock_irqrestore(&port->port_lock, flags);
 
-	pr_vdebug("gs_chars_in_buffer: (%d,%p) chars=%d\n",
+	pr_vdebug("gs_chars_in_buffer: (%d,%p) chars=%u\n",
 		port->port_num, tty, chars);
 
 	return chars;
diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
index cd3ab35dd689..bef104511352 100644
--- a/drivers/usb/host/xhci-dbgtty.c
+++ b/drivers/usb/host/xhci-dbgtty.c
@@ -253,11 +253,11 @@ static unsigned int dbc_tty_write_room(struct tty_struct *tty)
 	return room;
 }
 
-static int dbc_tty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int dbc_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct dbc_port		*port = tty->driver_data;
 	unsigned long		flags;
-	int			chars = 0;
+	unsigned int		chars;
 
 	spin_lock_irqsave(&port->port_lock, flags);
 	chars = kfifo_len(&port->write_fifo);
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 055096831daf..eeb441c77207 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -385,7 +385,7 @@ static unsigned int serial_write_room(struct tty_struct *tty)
 	return port->serial->type->write_room(tty);
 }
 
-static int serial_chars_in_buffer(struct tty_struct *tty)
+static unsigned int serial_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct usb_serial *serial = port->serial;
diff --git a/include/linux/tty.h b/include/linux/tty.h
index d18fc34d3054..5cf6b2e7331b 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -458,7 +458,7 @@ extern void tty_unregister_device(struct tty_driver *driver, unsigned index);
 extern void tty_write_message(struct tty_struct *tty, char *msg);
 extern int tty_send_xchar(struct tty_struct *tty, char ch);
 extern int tty_put_char(struct tty_struct *tty, unsigned char c);
-extern int tty_chars_in_buffer(struct tty_struct *tty);
+extern unsigned int tty_chars_in_buffer(struct tty_struct *tty);
 extern unsigned int tty_write_room(struct tty_struct *tty);
 extern void tty_driver_flush_buffer(struct tty_struct *tty);
 extern void tty_throttle(struct tty_struct *tty);
diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
index ea5b15c72764..a4694bb125cc 100644
--- a/include/linux/tty_driver.h
+++ b/include/linux/tty_driver.h
@@ -257,7 +257,7 @@ struct tty_operations {
 	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);
-	int  (*chars_in_buffer)(struct tty_struct *tty);
+	unsigned int (*chars_in_buffer)(struct tty_struct *tty);
 	int  (*ioctl)(struct tty_struct *tty,
 		    unsigned int cmd, unsigned long arg);
 	long (*compat_ioctl)(struct tty_struct *tty,
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index a5e3d957f20f..c76dcc0f679b 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -1010,7 +1010,7 @@ static void rfcomm_tty_unthrottle(struct tty_struct *tty)
 	rfcomm_dlc_unthrottle(dev->dlc);
 }
 
-static int rfcomm_tty_chars_in_buffer(struct tty_struct *tty)
+static unsigned int rfcomm_tty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
 
-- 
2.31.1


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

* [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer return uint
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (25 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-19  9:09   ` Johan Hovold
  2021-05-05  9:19 ` [PATCH 28/35] nozomi: simplify ntty_chars_in_buffer Jiri Slaby
                   ` (9 subsequent siblings)
  36 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Johan Hovold, linux-usb

tty_operations::chars_in_buffer was switched to uint in the previous
patch. So do the same for usb_serial_driver's chars_in_buffer too.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Johan Hovold <johan@kernel.org>
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/serial/cypress_m8.c       | 8 ++++----
 drivers/usb/serial/digi_acceleport.c  | 4 ++--
 drivers/usb/serial/generic.c          | 6 +++---
 drivers/usb/serial/io_edgeport.c      | 6 +++---
 drivers/usb/serial/io_ti.c            | 6 +++---
 drivers/usb/serial/mos7720.c          | 6 +++---
 drivers/usb/serial/mos7840.c          | 6 +++---
 drivers/usb/serial/opticon.c          | 4 ++--
 drivers/usb/serial/oti6858.c          | 6 +++---
 drivers/usb/serial/sierra.c           | 6 +++---
 drivers/usb/serial/ti_usb_3410_5052.c | 8 ++++----
 drivers/usb/serial/usb-wwan.h         | 2 +-
 drivers/usb/serial/usb_wwan.c         | 6 +++---
 include/linux/usb/serial.h            | 4 ++--
 14 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 5e7d2f9fa0c2..1dca04e1519d 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -129,7 +129,7 @@ static void cypress_set_termios(struct tty_struct *tty,
 static int  cypress_tiocmget(struct tty_struct *tty);
 static int  cypress_tiocmset(struct tty_struct *tty,
 			unsigned int set, unsigned int clear);
-static int  cypress_chars_in_buffer(struct tty_struct *tty);
+static unsigned int cypress_chars_in_buffer(struct tty_struct *tty);
 static void cypress_throttle(struct tty_struct *tty);
 static void cypress_unthrottle(struct tty_struct *tty);
 static void cypress_set_dead(struct usb_serial_port *port);
@@ -970,18 +970,18 @@ static void cypress_set_termios(struct tty_struct *tty,
 
 
 /* returns amount of data still left in soft buffer */
-static int cypress_chars_in_buffer(struct tty_struct *tty)
+static unsigned int cypress_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct cypress_private *priv = usb_get_serial_port_data(port);
-	int chars = 0;
+	unsigned int chars;
 	unsigned long flags;
 
 	spin_lock_irqsave(&priv->lock, flags);
 	chars = kfifo_len(&priv->write_fifo);
 	spin_unlock_irqrestore(&priv->lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
 	return chars;
 }
 
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 5deb900450ee..19ee8191647c 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -224,7 +224,7 @@ static int digi_write(struct tty_struct *tty, struct usb_serial_port *port,
 		const unsigned char *buf, int count);
 static void digi_write_bulk_callback(struct urb *urb);
 static unsigned int digi_write_room(struct tty_struct *tty);
-static int digi_chars_in_buffer(struct tty_struct *tty);
+static unsigned int digi_chars_in_buffer(struct tty_struct *tty);
 static int digi_open(struct tty_struct *tty, struct usb_serial_port *port);
 static void digi_close(struct usb_serial_port *port);
 static void digi_dtr_rts(struct usb_serial_port *port, int on);
@@ -1040,7 +1040,7 @@ static unsigned int digi_write_room(struct tty_struct *tty)
 
 }
 
-static int digi_chars_in_buffer(struct tty_struct *tty)
+static unsigned int digi_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct digi_port *priv = usb_get_serial_port_data(port);
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index bc3cf66af0de..15b6dee3a8e5 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -247,11 +247,11 @@ unsigned int usb_serial_generic_write_room(struct tty_struct *tty)
 	return room;
 }
 
-int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
+unsigned int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	unsigned long flags;
-	int chars;
+	unsigned int chars;
 
 	if (!port->bulk_out_size)
 		return 0;
@@ -260,7 +260,7 @@ int usb_serial_generic_chars_in_buffer(struct tty_struct *tty)
 	chars = kfifo_len(&port->write_fifo) + port->tx_bytes;
 	spin_unlock_irqrestore(&port->lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
 	return chars;
 }
 EXPORT_SYMBOL_GPL(usb_serial_generic_chars_in_buffer);
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index f6cedc87d3e4..1f8dff4390c7 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -1391,11 +1391,11 @@ static unsigned int edge_write_room(struct tty_struct *tty)
  *	system,
  *	Otherwise we return a negative error number.
  *****************************************************************************/
-static int edge_chars_in_buffer(struct tty_struct *tty)
+static unsigned int edge_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct edgeport_port *edge_port = usb_get_serial_port_data(port);
-	int num_chars;
+	unsigned int num_chars;
 	unsigned long flags;
 
 	if (edge_port == NULL)
@@ -1413,7 +1413,7 @@ static int edge_chars_in_buffer(struct tty_struct *tty)
 						edge_port->txfifo.count;
 	spin_unlock_irqrestore(&edge_port->ep_lock, flags);
 	if (num_chars) {
-		dev_dbg(&port->dev, "%s - returns %d\n", __func__, num_chars);
+		dev_dbg(&port->dev, "%s - returns %u\n", __func__, num_chars);
 	}
 
 	return num_chars;
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index 94c82c33e629..84b848d2794e 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -2087,11 +2087,11 @@ static unsigned int edge_write_room(struct tty_struct *tty)
 	return room;
 }
 
-static int edge_chars_in_buffer(struct tty_struct *tty)
+static unsigned int edge_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct edgeport_port *edge_port = usb_get_serial_port_data(port);
-	int chars = 0;
+	unsigned int chars;
 	unsigned long flags;
 	if (edge_port == NULL)
 		return 0;
@@ -2100,7 +2100,7 @@ static int edge_chars_in_buffer(struct tty_struct *tty)
 	chars = kfifo_len(&port->write_fifo);
 	spin_unlock_irqrestore(&edge_port->ep_lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
 	return chars;
 }
 
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index d9cc7f840d48..ce41009756f3 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -949,11 +949,11 @@ static int mos7720_open(struct tty_struct *tty, struct usb_serial_port *port)
  *	system,
  *	Otherwise we return a negative error number.
  */
-static int mos7720_chars_in_buffer(struct tty_struct *tty)
+static unsigned int mos7720_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	int i;
-	int chars = 0;
+	unsigned int chars = 0;
 	struct moschip_port *mos7720_port;
 
 	mos7720_port = usb_get_serial_port_data(port);
@@ -965,7 +965,7 @@ static int mos7720_chars_in_buffer(struct tty_struct *tty)
 		    mos7720_port->write_urb_pool[i]->status == -EINPROGRESS)
 			chars += URB_TRANSFER_BUFFER_SIZE;
 	}
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
 	return chars;
 }
 
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index f25d4ba43b9a..44f39bf97de1 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -735,12 +735,12 @@ static int mos7840_open(struct tty_struct *tty, struct usb_serial_port *port)
  *	Otherwise we return zero.
  *****************************************************************************/
 
-static int mos7840_chars_in_buffer(struct tty_struct *tty)
+static unsigned int mos7840_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
 	int i;
-	int chars = 0;
+	unsigned int chars = 0;
 	unsigned long flags;
 
 	spin_lock_irqsave(&mos7840_port->pool_lock, flags);
@@ -751,7 +751,7 @@ static int mos7840_chars_in_buffer(struct tty_struct *tty)
 		}
 	}
 	spin_unlock_irqrestore(&mos7840_port->pool_lock, flags);
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
 	return chars;
 
 }
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index 37b51947bd0b..aed28c35caff 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -289,12 +289,12 @@ static unsigned int opticon_write_room(struct tty_struct *tty)
 	return 2048;
 }
 
-static int opticon_chars_in_buffer(struct tty_struct *tty)
+static unsigned int opticon_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct opticon_private *priv = usb_get_serial_port_data(port);
 	unsigned long flags;
-	int count;
+	unsigned int count;
 
 	spin_lock_irqsave(&priv->lock, flags);
 	count = priv->outstanding_bytes;
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index 4ab9f335dd0e..a5caedbe72e2 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -127,7 +127,7 @@ static void oti6858_write_bulk_callback(struct urb *urb);
 static int oti6858_write(struct tty_struct *tty, struct usb_serial_port *port,
 			const unsigned char *buf, int count);
 static unsigned int oti6858_write_room(struct tty_struct *tty);
-static int oti6858_chars_in_buffer(struct tty_struct *tty);
+static unsigned int oti6858_chars_in_buffer(struct tty_struct *tty);
 static int oti6858_tiocmget(struct tty_struct *tty);
 static int oti6858_tiocmset(struct tty_struct *tty,
 				unsigned int set, unsigned int clear);
@@ -376,10 +376,10 @@ static unsigned int oti6858_write_room(struct tty_struct *tty)
 	return room;
 }
 
-static int oti6858_chars_in_buffer(struct tty_struct *tty)
+static unsigned int oti6858_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
-	int chars = 0;
+	unsigned int chars;
 	unsigned long flags;
 
 	spin_lock_irqsave(&port->lock, flags);
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index 753cee5d17a1..4b49b7c33364 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -632,19 +632,19 @@ static unsigned int sierra_write_room(struct tty_struct *tty)
 	return 2048;
 }
 
-static int sierra_chars_in_buffer(struct tty_struct *tty)
+static unsigned int sierra_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct sierra_port_private *portdata = usb_get_serial_port_data(port);
 	unsigned long flags;
-	int chars;
+	unsigned int chars;
 
 	/* NOTE: This overcounts somewhat. */
 	spin_lock_irqsave(&portdata->lock, flags);
 	chars = portdata->outstanding_urbs * MAX_TRANSFER;
 	spin_unlock_irqrestore(&portdata->lock, flags);
 
-	dev_dbg(&port->dev, "%s - %d\n", __func__, chars);
+	dev_dbg(&port->dev, "%s - %u\n", __func__, chars);
 
 	return chars;
 }
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 2c543c175296..34f8ed224abe 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -308,7 +308,7 @@ static void ti_close(struct usb_serial_port *port);
 static int ti_write(struct tty_struct *tty, struct usb_serial_port *port,
 		const unsigned char *data, int count);
 static unsigned int ti_write_room(struct tty_struct *tty);
-static int ti_chars_in_buffer(struct tty_struct *tty);
+static unsigned int ti_chars_in_buffer(struct tty_struct *tty);
 static bool ti_tx_empty(struct usb_serial_port *port);
 static void ti_throttle(struct tty_struct *tty);
 static void ti_unthrottle(struct tty_struct *tty);
@@ -826,18 +826,18 @@ static unsigned int ti_write_room(struct tty_struct *tty)
 }
 
 
-static int ti_chars_in_buffer(struct tty_struct *tty)
+static unsigned int ti_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct ti_port *tport = usb_get_serial_port_data(port);
-	int chars = 0;
+	unsigned int chars;
 	unsigned long flags;
 
 	spin_lock_irqsave(&tport->tp_lock, flags);
 	chars = kfifo_len(&port->write_fifo);
 	spin_unlock_irqrestore(&tport->tp_lock, flags);
 
-	dev_dbg(&port->dev, "%s - returns %d\n", __func__, chars);
+	dev_dbg(&port->dev, "%s - returns %u\n", __func__, chars);
 	return chars;
 }
 
diff --git a/drivers/usb/serial/usb-wwan.h b/drivers/usb/serial/usb-wwan.h
index 6c7c9f3309b0..519101945769 100644
--- a/drivers/usb/serial/usb-wwan.h
+++ b/drivers/usb/serial/usb-wwan.h
@@ -17,7 +17,7 @@ extern int usb_wwan_tiocmset(struct tty_struct *tty,
 			     unsigned int set, unsigned int clear);
 extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port,
 			  const unsigned char *buf, int count);
-extern int usb_wwan_chars_in_buffer(struct tty_struct *tty);
+extern unsigned int usb_wwan_chars_in_buffer(struct tty_struct *tty);
 #ifdef CONFIG_PM
 extern int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message);
 extern int usb_wwan_resume(struct usb_serial *serial);
diff --git a/drivers/usb/serial/usb_wwan.c b/drivers/usb/serial/usb_wwan.c
index 06212f08d9f9..cb01283d4d15 100644
--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -299,12 +299,12 @@ unsigned int usb_wwan_write_room(struct tty_struct *tty)
 }
 EXPORT_SYMBOL(usb_wwan_write_room);
 
-int usb_wwan_chars_in_buffer(struct tty_struct *tty)
+unsigned int usb_wwan_chars_in_buffer(struct tty_struct *tty)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct usb_wwan_port_private *portdata;
 	int i;
-	int data_len = 0;
+	unsigned int data_len = 0;
 	struct urb *this_urb;
 
 	portdata = usb_get_serial_port_data(port);
@@ -316,7 +316,7 @@ int usb_wwan_chars_in_buffer(struct tty_struct *tty)
 		if (this_urb && test_bit(i, &portdata->out_busy))
 			data_len += this_urb->transfer_buffer_length;
 	}
-	dev_dbg(&port->dev, "%s: %d\n", __func__, data_len);
+	dev_dbg(&port->dev, "%s: %u\n", __func__, data_len);
 	return data_len;
 }
 EXPORT_SYMBOL(usb_wwan_chars_in_buffer);
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 6472d1f7b028..95c729446e27 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -284,7 +284,7 @@ struct usb_serial_driver {
 	void (*set_termios)(struct tty_struct *tty,
 			struct usb_serial_port *port, struct ktermios *old);
 	void (*break_ctl)(struct tty_struct *tty, int break_state);
-	int  (*chars_in_buffer)(struct tty_struct *tty);
+	unsigned int (*chars_in_buffer)(struct tty_struct *tty);
 	void (*wait_until_sent)(struct tty_struct *tty, long timeout);
 	bool (*tx_empty)(struct usb_serial_port *port);
 	void (*throttle)(struct tty_struct *tty);
@@ -348,7 +348,7 @@ int usb_serial_generic_write(struct tty_struct *tty, struct usb_serial_port *por
 void usb_serial_generic_close(struct usb_serial_port *port);
 int usb_serial_generic_resume(struct usb_serial *serial);
 unsigned int usb_serial_generic_write_room(struct tty_struct *tty);
-int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
+unsigned int usb_serial_generic_chars_in_buffer(struct tty_struct *tty);
 void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout);
 void usb_serial_generic_read_bulk_callback(struct urb *urb);
 void usb_serial_generic_write_bulk_callback(struct urb *urb);
-- 
2.31.1


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

* [PATCH 28/35] nozomi: simplify ntty_chars_in_buffer
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (26 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer " Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer Jiri Slaby
                   ` (8 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

ntty_chars_in_buffer is overly complicated. Simplify it by inverting the
condition.

Side FIXME: how can dc or port be NULL here?

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/nozomi.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
index 62c16731ccd8..5e0ddf22931e 100644
--- a/drivers/tty/nozomi.c
+++ b/drivers/tty/nozomi.c
@@ -1780,16 +1780,11 @@ static unsigned int ntty_chars_in_buffer(struct tty_struct *tty)
 {
 	struct port *port = tty->driver_data;
 	struct nozomi *dc = get_dc_by_tty(tty);
-	s32 rval = 0;
 
-	if (unlikely(!dc || !port)) {
-		goto exit_in_buffer;
-	}
-
-	rval = kfifo_len(&port->fifo_ul);
+	if (unlikely(!dc || !port))
+		return 0;
 
-exit_in_buffer:
-	return rval;
+	return kfifo_len(&port->fifo_ul);
 }
 
 static const struct tty_port_operations noz_tty_port_ops = {
-- 
2.31.1


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

* [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (27 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 28/35] nozomi: simplify ntty_chars_in_buffer Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-19  9:11   ` Johan Hovold
  2021-05-05  9:19 ` [PATCH 30/35] tty: remove empty tty_operations::flush_buffer Jiri Slaby
                   ` (7 subsequent siblings)
  36 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Johan Hovold, linux-usb

"if"'s true branch in digi_chars_in_buffer returns. So there is no need
for "else" and indented code. Remove this else and shift the code to the
left.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Johan Hovold <johan@kernel.org>
Cc: linux-usb@vger.kernel.org
---
 drivers/usb/serial/digi_acceleport.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 19ee8191647c..0c4d611621c2 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -1050,12 +1050,11 @@ static unsigned int digi_chars_in_buffer(struct tty_struct *tty)
 			priv->dp_port_num, port->bulk_out_size - 2);
 		/* return(port->bulk_out_size - 2); */
 		return 256;
-	} else {
-		dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
-			priv->dp_port_num, priv->dp_out_buf_len);
-		return priv->dp_out_buf_len;
 	}
 
+	dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
+		priv->dp_port_num, priv->dp_out_buf_len);
+	return priv->dp_out_buf_len;
 }
 
 static void digi_dtr_rts(struct usb_serial_port *port, int on)
-- 
2.31.1


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

* [PATCH 30/35] tty: remove empty tty_operations::flush_buffer
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (28 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 31/35] tty: remove empty tty_operations::set_termios Jiri Slaby
                   ` (6 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Karsten Keil,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger

tty_operations::flush_buffer is optional. If it doesn't exist, nothing
is called. So remove almost¹ empty flush_buffer implementations.

¹ capi had an useless pr_debug in it.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
---
 drivers/isdn/capi/capi.c    | 6 ------
 drivers/s390/char/tty3270.c | 6 ------
 2 files changed, 12 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index dae80197ad9c..6d99b93bb09e 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1249,11 +1249,6 @@ static int capinc_tty_break_ctl(struct tty_struct *tty, int state)
 	return 0;
 }
 
-static void capinc_tty_flush_buffer(struct tty_struct *tty)
-{
-	pr_debug("capinc_tty_flush_buffer\n");
-}
-
 static void capinc_tty_set_ldisc(struct tty_struct *tty)
 {
 	pr_debug("capinc_tty_set_ldisc\n");
@@ -1279,7 +1274,6 @@ static const struct tty_operations capinc_ops = {
 	.start = capinc_tty_start,
 	.hangup = capinc_tty_hangup,
 	.break_ctl = capinc_tty_break_ctl,
-	.flush_buffer = capinc_tty_flush_buffer,
 	.set_ldisc = capinc_tty_set_ldisc,
 	.send_xchar = capinc_tty_send_xchar,
 	.install = capinc_tty_install,
diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
index ba1fbce63fee..adc33846bf8e 100644
--- a/drivers/s390/char/tty3270.c
+++ b/drivers/s390/char/tty3270.c
@@ -1756,11 +1756,6 @@ tty3270_flush_chars(struct tty_struct *tty)
 	}
 }
 
-static void
-tty3270_flush_buffer(struct tty_struct *tty)
-{
-}
-
 /*
  * Check for visible/invisible input switches
  */
@@ -1881,7 +1876,6 @@ static const struct tty_operations tty3270_ops = {
 	.put_char = tty3270_put_char,
 	.flush_chars = tty3270_flush_chars,
 	.write_room = tty3270_write_room,
-	.flush_buffer = tty3270_flush_buffer,
 	.throttle = tty3270_throttle,
 	.unthrottle = tty3270_unthrottle,
 	.hangup = tty3270_hangup,
-- 
2.31.1


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

* [PATCH 31/35] tty: remove empty tty_operations::set_termios
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (29 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 30/35] tty: remove empty tty_operations::flush_buffer Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05 10:34   ` Anton Ivanov
  2021-05-05  9:19 ` [PATCH 32/35] isdn: capi, remove optional tty ops Jiri Slaby
                   ` (5 subsequent siblings)
  36 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Jeff Dike,
	Richard Weinberger, Anton Ivanov, Karsten Keil

tty_operations::set_termios is optional. If it doesn't exist, nothing is
called. So remove almost¹ empty set_termios implementations.

¹ capi had an useless pr_debug in it.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
Cc: Karsten Keil <isdn@linux-pingi.de>
---
 arch/um/drivers/line.c          | 5 -----
 arch/um/drivers/line.h          | 1 -
 arch/um/drivers/ssl.c           | 1 -
 arch/um/drivers/stdio_console.c | 1 -
 drivers/isdn/capi/capi.c        | 6 ------
 5 files changed, 14 deletions(-)

diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
index 159434851417..fbc623d2cc07 100644
--- a/arch/um/drivers/line.c
+++ b/arch/um/drivers/line.c
@@ -211,11 +211,6 @@ int line_write(struct tty_struct *tty, const unsigned char *buf, int len)
 	return ret;
 }
 
-void line_set_termios(struct tty_struct *tty, struct ktermios * old)
-{
-	/* nothing */
-}
-
 void line_throttle(struct tty_struct *tty)
 {
 	struct line *line = tty->driver_data;
diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
index 3325e2bc64e4..bdb16b96e76f 100644
--- a/arch/um/drivers/line.h
+++ b/arch/um/drivers/line.h
@@ -66,7 +66,6 @@ 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 void line_set_termios(struct tty_struct *tty, struct ktermios * old);
 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/um/drivers/ssl.c b/arch/um/drivers/ssl.c
index 6476b28d7c5e..41eae2e8fb65 100644
--- a/arch/um/drivers/ssl.c
+++ b/arch/um/drivers/ssl.c
@@ -99,7 +99,6 @@ static const struct tty_operations ssl_ops = {
 	.chars_in_buffer 	= line_chars_in_buffer,
 	.flush_buffer 		= line_flush_buffer,
 	.flush_chars 		= line_flush_chars,
-	.set_termios 		= line_set_termios,
 	.throttle 		= line_throttle,
 	.unthrottle 		= line_unthrottle,
 	.install		= ssl_install,
diff --git a/arch/um/drivers/stdio_console.c b/arch/um/drivers/stdio_console.c
index 37b127941e6f..e8b762f4d8c2 100644
--- a/arch/um/drivers/stdio_console.c
+++ b/arch/um/drivers/stdio_console.c
@@ -106,7 +106,6 @@ static const struct tty_operations console_ops = {
 	.chars_in_buffer 	= line_chars_in_buffer,
 	.flush_buffer 		= line_flush_buffer,
 	.flush_chars 		= line_flush_chars,
-	.set_termios 		= line_set_termios,
 	.throttle 		= line_throttle,
 	.unthrottle 		= line_unthrottle,
 	.hangup			= line_hangup,
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 6d99b93bb09e..693b0bc31395 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1197,11 +1197,6 @@ static unsigned int capinc_tty_chars_in_buffer(struct tty_struct *tty)
 	return mp->outbytes;
 }
 
-static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
-{
-	pr_debug("capinc_tty_set_termios\n");
-}
-
 static void capinc_tty_throttle(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
@@ -1267,7 +1262,6 @@ static const struct tty_operations capinc_ops = {
 	.flush_chars = capinc_tty_flush_chars,
 	.write_room = capinc_tty_write_room,
 	.chars_in_buffer = capinc_tty_chars_in_buffer,
-	.set_termios = capinc_tty_set_termios,
 	.throttle = capinc_tty_throttle,
 	.unthrottle = capinc_tty_unthrottle,
 	.stop = capinc_tty_stop,
-- 
2.31.1


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

* [PATCH 32/35] isdn: capi, remove optional tty ops
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (30 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 31/35] tty: remove empty tty_operations::set_termios Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 33/35] isdn: capi, drop useless pr_debugs Jiri Slaby
                   ` (4 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Karsten Keil, netdev

break_ctl and set_ldisc are optional tty_operations hooks. Given capi
does nothing useful in them, just remove these.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: netdev@vger.kernel.org
---
 drivers/isdn/capi/capi.c | 13 -------------
 1 file changed, 13 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 693b0bc31395..bf8a8809eff1 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1238,17 +1238,6 @@ static void capinc_tty_hangup(struct tty_struct *tty)
 	tty_port_hangup(&mp->port);
 }
 
-static int capinc_tty_break_ctl(struct tty_struct *tty, int state)
-{
-	pr_debug("capinc_tty_break_ctl(%d)\n", state);
-	return 0;
-}
-
-static void capinc_tty_set_ldisc(struct tty_struct *tty)
-{
-	pr_debug("capinc_tty_set_ldisc\n");
-}
-
 static void capinc_tty_send_xchar(struct tty_struct *tty, char ch)
 {
 	pr_debug("capinc_tty_send_xchar(%d)\n", ch);
@@ -1267,8 +1256,6 @@ static const struct tty_operations capinc_ops = {
 	.stop = capinc_tty_stop,
 	.start = capinc_tty_start,
 	.hangup = capinc_tty_hangup,
-	.break_ctl = capinc_tty_break_ctl,
-	.set_ldisc = capinc_tty_set_ldisc,
 	.send_xchar = capinc_tty_send_xchar,
 	.install = capinc_tty_install,
 	.cleanup = capinc_tty_cleanup,
-- 
2.31.1


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

* [PATCH 33/35] isdn: capi, drop useless pr_debugs
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (31 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 32/35] isdn: capi, remove optional tty ops Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-05  9:19 ` [PATCH 34/35] tty: make tty_get_byte_size available Jiri Slaby
                   ` (3 subsequent siblings)
  36 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby, Karsten Keil, netdev

capi have many pr_debugs in tty_operations hooks to print only a
functions name. We have better debugging aids in the kernel many years
now. So remove these useless pr_debugs.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Karsten Keil <isdn@linux-pingi.de>
Cc: netdev@vger.kernel.org
---
 drivers/isdn/capi/capi.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index bf8a8809eff1..d5f9261fa879 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1158,8 +1158,6 @@ static void capinc_tty_flush_chars(struct tty_struct *tty)
 	struct capiminor *mp = tty->driver_data;
 	struct sk_buff *skb;
 
-	pr_debug("capinc_tty_flush_chars\n");
-
 	spin_lock_bh(&mp->outlock);
 	skb = mp->outskb;
 	if (skb) {
@@ -1200,7 +1198,6 @@ static unsigned int capinc_tty_chars_in_buffer(struct tty_struct *tty)
 static void capinc_tty_throttle(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
-	pr_debug("capinc_tty_throttle\n");
 	mp->ttyinstop = 1;
 }
 
@@ -1208,7 +1205,6 @@ static void capinc_tty_unthrottle(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
 
-	pr_debug("capinc_tty_unthrottle\n");
 	mp->ttyinstop = 0;
 	handle_minor_recv(mp);
 }
@@ -1217,7 +1213,6 @@ static void capinc_tty_stop(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
 
-	pr_debug("capinc_tty_stop\n");
 	mp->ttyoutstop = 1;
 }
 
@@ -1225,7 +1220,6 @@ static void capinc_tty_start(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
 
-	pr_debug("capinc_tty_start\n");
 	mp->ttyoutstop = 0;
 	handle_minor_send(mp);
 }
@@ -1234,7 +1228,6 @@ static void capinc_tty_hangup(struct tty_struct *tty)
 {
 	struct capiminor *mp = tty->driver_data;
 
-	pr_debug("capinc_tty_hangup\n");
 	tty_port_hangup(&mp->port);
 }
 
-- 
2.31.1


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

* [PATCH 34/35] tty: make tty_get_byte_size available
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (32 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 33/35] isdn: capi, drop useless pr_debugs Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-06  7:16   ` Joe Perches
  2021-05-10  7:00   ` [PATCH v2 " Jiri Slaby
  2021-05-05  9:19 ` [PATCH 35/35] tty: make use of tty_get_byte_size Jiri Slaby
                   ` (2 subsequent siblings)
  36 siblings, 2 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Many tty drivers contain code to compute bits count depending on termios
cflags. So extract this code from serial core to a separate tty helper
function called tty_get_byte_size.

In the next patch, call to this new function will replace many copies of
this code.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/serial/serial_core.c | 30 +++--------------------
 drivers/tty/tty_ioctl.c          | 41 ++++++++++++++++++++++++++++++++
 include/linux/tty.h              |  2 ++
 3 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index d29329eb52f4..b3fc2b02a705 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -334,39 +334,15 @@ void
 uart_update_timeout(struct uart_port *port, unsigned int cflag,
 		    unsigned int baud)
 {
-	unsigned int bits;
+	unsigned int size;
 
-	/* byte size and parity */
-	switch (cflag & CSIZE) {
-	case CS5:
-		bits = 7;
-		break;
-	case CS6:
-		bits = 8;
-		break;
-	case CS7:
-		bits = 9;
-		break;
-	default:
-		bits = 10;
-		break; /* CS8 */
-	}
-
-	if (cflag & CSTOPB)
-		bits++;
-	if (cflag & PARENB)
-		bits++;
-
-	/*
-	 * The total number of bits to be transmitted in the fifo.
-	 */
-	bits = bits * port->fifosize;
+	size = tty_get_byte_size(cflag, true) * port->fifosize;
 
 	/*
 	 * Figure the timeout to send the above number of bits.
 	 * Add .02 seconds of slop
 	 */
-	port->timeout = (HZ * bits) / baud + HZ/50;
+	port->timeout = (HZ * size) / baud + HZ/50;
 }
 
 EXPORT_SYMBOL(uart_update_timeout);
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index aa9ecc8be990..72d036917b14 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -300,6 +300,47 @@ int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
 }
 EXPORT_SYMBOL(tty_termios_hw_change);
 
+/**
+ *	tty_get_byte_size	-	get size of a byte
+ *	@cflag: termios cflag value
+ *	@account_flags: account for start and stop bits, second stop bit (if
+ *			set), and parity (if set)
+ *
+ *	Get the size of a byte in bits depending on @cflag. Depending on
+ *	@account_flags parameter, the result also accounts start and stop bits,
+ *	the second stop bit, and parity bit.
+ */
+unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
+{
+	unsigned char bits = account_flags ? 2 : 0;
+
+	/* byte size and parity */
+	switch (cflag & CSIZE) {
+	case CS5:
+		bits += 5;
+		break;
+	case CS6:
+		bits += 6;
+		break;
+	case CS7:
+		bits += 7;
+		break;
+	case CS8:
+	default:
+		bits += 8;
+		break;
+	}
+
+	if (account_flags && (cflag & CSTOPB))
+		bits++;
+
+	if (account_flags && (cflag & PARENB))
+		bits++;
+
+	return bits;
+}
+EXPORT_SYMBOL_GPL(tty_get_byte_size);
+
 /**
  *	tty_set_termios		-	update termios values
  *	@tty: tty to update
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 5cf6b2e7331b..a14b4588368c 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -496,6 +496,8 @@ static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
 	return tty_termios_baud_rate(&tty->termios);
 }
 
+unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags);
+
 extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
 extern int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
 extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
-- 
2.31.1


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

* [PATCH 35/35] tty: make use of tty_get_byte_size
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (33 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 34/35] tty: make tty_get_byte_size available Jiri Slaby
@ 2021-05-05  9:19 ` Jiri Slaby
  2021-05-10  9:59   ` Johan Hovold
  2021-05-13 15:04 ` [PATCH 00/35] tty cleanup for 5.14 Greg KH
  2021-06-10  9:02 ` [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available Jiri Slaby
  36 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-05  9:19 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Arnd Bergmann, David Lin,
	Johan Hovold, Alex Elder, Shawn Guo, Sascha Hauer, Andy Gross,
	Bjorn Andersson, Maxime Coquelin, Alexandre Torgue,
	Oliver Neukum

In the previous patch, we introduced tty_get_byte_size for computing
byte size. Here, we make use of it in various tty drivers.

The stats look nice: 16 insertions, 203 deletions.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Andy Gross <agross@kernel.org>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Oliver Neukum <oneukum@suse.com>
---
 drivers/char/pcmcia/synclink_cs.c           |  8 +-----
 drivers/staging/greybus/uart.c              | 16 +----------
 drivers/tty/serial/cpm_uart/cpm_uart_core.c | 19 +-----------
 drivers/tty/serial/mxs-auart.c              | 18 +-----------
 drivers/tty/serial/qcom_geni_serial.c       | 16 +----------
 drivers/tty/serial/sh-sci.c                 | 20 +------------
 drivers/tty/serial/stm32-usart.c            | 32 +--------------------
 drivers/tty/synclink_gt.c                   |  9 +-----
 drivers/usb/class/cdc-acm.c                 | 17 ++---------
 drivers/usb/serial/belkin_sa.c              | 21 ++------------
 drivers/usb/serial/cypress_m8.c             | 19 ++----------
 drivers/usb/serial/pl2303.c                 | 15 +---------
 drivers/usb/serial/whiteheat.c              |  9 +-----
 13 files changed, 16 insertions(+), 203 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 9f7420bc5026..502d04da54ba 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1419,13 +1419,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty)
 
 	/* byte size and parity */
 
-	switch (cflag & CSIZE) {
-	case CS5: info->params.data_bits = 5; break;
-	case CS6: info->params.data_bits = 6; break;
-	case CS7: info->params.data_bits = 7; break;
-	case CS8: info->params.data_bits = 8; break;
-	default:  info->params.data_bits = 7; break;
-	}
+	info->params.data_bits = tty_get_byte_size(cflag, false);
 
 	if (cflag & CSTOPB)
 		info->params.stop_bits = 2;
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index ccfaa0f21b9c..3db2f414f519 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -494,21 +494,7 @@ static void gb_tty_set_termios(struct tty_struct *tty,
 				(termios->c_cflag & PARODD ? 1 : 2) +
 				(termios->c_cflag & CMSPAR ? 2 : 0) : 0;
 
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		newline.data_bits = 5;
-		break;
-	case CS6:
-		newline.data_bits = 6;
-		break;
-	case CS7:
-		newline.data_bits = 7;
-		break;
-	case CS8:
-	default:
-		newline.data_bits = 8;
-		break;
-	}
+	newline.data_bits = tty_get_byte_size(termios->c_cflag, false);
 
 	/* FIXME: needs to clear unsupported bits in the termios */
 	gb_tty->clocal = ((termios->c_cflag & CLOCAL) != 0);
diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
index 58aaa533203b..1ac4746c27ac 100644
--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
@@ -524,24 +524,7 @@ static void cpm_uart_set_termios(struct uart_port *port,
 	scval = 0;
 
 	/* byte size */
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		bits = 5;
-		break;
-	case CS6:
-		bits = 6;
-		break;
-	case CS7:
-		bits = 7;
-		break;
-	case CS8:
-		bits = 8;
-		break;
-		/* Never happens, but GCC is too dumb to figure it out */
-	default:
-		bits = 8;
-		break;
-	}
+	bits = tty_get_byte_size(termios->c_cflag, false);
 	sbits = bits - 5;
 
 	if (termios->c_cflag & CSTOPB) {
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index f414d6acad69..a5cbd7324268 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -971,23 +971,7 @@ static void mxs_auart_settermios(struct uart_port *u,
 	ctrl2 = mxs_read(s, REG_CTRL2);
 
 	/* byte size */
-	switch (cflag & CSIZE) {
-	case CS5:
-		bm = 0;
-		break;
-	case CS6:
-		bm = 1;
-		break;
-	case CS7:
-		bm = 2;
-		break;
-	case CS8:
-		bm = 3;
-		break;
-	default:
-		return;
-	}
-
+	bm = tty_get_byte_size(cflag, false) - 5;
 	ctrl |= AUART_LINECTRL_WLEN(bm);
 
 	/* parity */
diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
index 23d729ed3bf6..9488eefff67c 100644
--- a/drivers/tty/serial/qcom_geni_serial.c
+++ b/drivers/tty/serial/qcom_geni_serial.c
@@ -1050,21 +1050,7 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,
 	}
 
 	/* bits per char */
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		bits_per_char = 5;
-		break;
-	case CS6:
-		bits_per_char = 6;
-		break;
-	case CS7:
-		bits_per_char = 7;
-		break;
-	case CS8:
-	default:
-		bits_per_char = 8;
-		break;
-	}
+	bits_per_char = tty_get_byte_size(termios->c_cflag, false);
 
 	/* stop bits */
 	if (termios->c_cflag & CSTOPB)
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index bef8ca742ed9..b3a692f76a55 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2494,25 +2494,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	uart_update_timeout(port, termios->c_cflag, baud);
 
 	/* byte size and parity */
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		bits = 7;
-		break;
-	case CS6:
-		bits = 8;
-		break;
-	case CS7:
-		bits = 9;
-		break;
-	default:
-		bits = 10;
-		break;
-	}
-
-	if (termios->c_cflag & CSTOPB)
-		bits++;
-	if (termios->c_cflag & PARENB)
-		bits++;
+	bits = tty_get_byte_size(termios->c_cflag, true);
 
 	if (best_clk >= 0) {
 		if (port->type == PORT_SCIFA || port->type == PORT_SCIFB)
diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index c2ae7b392b86..3a36a1a2f55a 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -718,36 +718,6 @@ static void stm32_usart_shutdown(struct uart_port *port)
 	free_irq(port->irq, port);
 }
 
-static unsigned int stm32_usart_get_databits(struct ktermios *termios)
-{
-	unsigned int bits;
-
-	tcflag_t cflag = termios->c_cflag;
-
-	switch (cflag & CSIZE) {
-	/*
-	 * CSIZE settings are not necessarily supported in hardware.
-	 * CSIZE unsupported configurations are handled here to set word length
-	 * to 8 bits word as default configuration and to print debug message.
-	 */
-	case CS5:
-		bits = 5;
-		break;
-	case CS6:
-		bits = 6;
-		break;
-	case CS7:
-		bits = 7;
-		break;
-	/* default including CS8 */
-	default:
-		bits = 8;
-		break;
-	}
-
-	return bits;
-}
-
 static void stm32_usart_set_termios(struct uart_port *port,
 				    struct ktermios *termios,
 				    struct ktermios *old)
@@ -805,7 +775,7 @@ static void stm32_usart_set_termios(struct uart_port *port,
 	if (cflag & CSTOPB)
 		cr2 |= USART_CR2_STOP_2B;
 
-	bits = stm32_usart_get_databits(termios);
+	bits = tty_get_byte_size(cflag, false);
 	stm32_port->rdr_mask = (BIT(bits) - 1);
 
 	if (cflag & PARENB) {
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index cf87dc66087b..af9fcb0e11db 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -2465,14 +2465,7 @@ static void change_params(struct slgt_info *info)
 
 	/* byte size and parity */
 
-	switch (cflag & CSIZE) {
-	case CS5: info->params.data_bits = 5; break;
-	case CS6: info->params.data_bits = 6; break;
-	case CS7: info->params.data_bits = 7; break;
-	case CS8: info->params.data_bits = 8; break;
-	default:  info->params.data_bits = 7; break;
-	}
-
+	info->params.data_bits = tty_get_byte_size(cflag, false);
 	info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1;
 
 	if (cflag & PARENB)
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 81199efe0312..e44b6bbd008b 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1056,21 +1056,8 @@ static void acm_tty_set_termios(struct tty_struct *tty,
 	newline.bParityType = termios->c_cflag & PARENB ?
 				(termios->c_cflag & PARODD ? 1 : 2) +
 				(termios->c_cflag & CMSPAR ? 2 : 0) : 0;
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		newline.bDataBits = 5;
-		break;
-	case CS6:
-		newline.bDataBits = 6;
-		break;
-	case CS7:
-		newline.bDataBits = 7;
-		break;
-	case CS8:
-	default:
-		newline.bDataBits = 8;
-		break;
-	}
+	newline.bDataBits = tty_get_byte_size(termios->c_cflag, false);
+
 	/* FIXME: Needs to clear unsupported bits in the termios */
 	acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
 
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index ed9193f3bb1a..a5bfe8e6c0c9 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -356,25 +356,8 @@ static void belkin_sa_set_termios(struct tty_struct *tty,
 
 	/* set the number of data bits */
 	if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
-		switch (cflag & CSIZE) {
-		case CS5:
-			urb_value = BELKIN_SA_DATA_BITS(5);
-			break;
-		case CS6:
-			urb_value = BELKIN_SA_DATA_BITS(6);
-			break;
-		case CS7:
-			urb_value = BELKIN_SA_DATA_BITS(7);
-			break;
-		case CS8:
-			urb_value = BELKIN_SA_DATA_BITS(8);
-			break;
-		default:
-			dev_dbg(&port->dev,
-				"CSIZE was not CS5-CS8, using default of 8\n");
-			urb_value = BELKIN_SA_DATA_BITS(8);
-			break;
-		}
+		urb_value = BELKIN_SA_DATA_BITS(tty_get_byte_size(cflag,
+					false));
 		if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0)
 			dev_err(&port->dev, "Set data bits error\n");
 	}
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 1dca04e1519d..b135ed1ee512 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -887,23 +887,8 @@ static void cypress_set_termios(struct tty_struct *tty,
 	} else
 		parity_enable = parity_type = 0;
 
-	switch (cflag & CSIZE) {
-	case CS5:
-		data_bits = 0;
-		break;
-	case CS6:
-		data_bits = 1;
-		break;
-	case CS7:
-		data_bits = 2;
-		break;
-	case CS8:
-		data_bits = 3;
-		break;
-	default:
-		dev_err(dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__);
-		data_bits = 3;
-	}
+	data_bits = tty_get_byte_size(cflag, false) - 5;
+
 	spin_lock_irqsave(&priv->lock, flags);
 	oldlines = priv->line_control;
 	if ((cflag & CBAUD) == B0) {
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index fd773d252691..76e4d90a9d43 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -788,20 +788,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
 
 	pl2303_get_line_request(port, buf);
 
-	switch (C_CSIZE(tty)) {
-	case CS5:
-		buf[6] = 5;
-		break;
-	case CS6:
-		buf[6] = 6;
-		break;
-	case CS7:
-		buf[6] = 7;
-		break;
-	default:
-	case CS8:
-		buf[6] = 8;
-	}
+	buf[6] = tty_get_byte_size(C_CSIZE(tty), false);
 	dev_dbg(&port->dev, "data bits = %d\n", buf[6]);
 
 	/* For reference buf[0]:buf[3] baud rate value */
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 5116ed9db3eb..7d4f2c1de4f6 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -625,14 +625,7 @@ static void firm_setup_port(struct tty_struct *tty)
 
 	port_settings.port = port->port_number + 1;
 
-	/* get the byte size */
-	switch (cflag & CSIZE) {
-	case CS5:	port_settings.bits = 5;   break;
-	case CS6:	port_settings.bits = 6;   break;
-	case CS7:	port_settings.bits = 7;   break;
-	default:
-	case CS8:	port_settings.bits = 8;   break;
-	}
+	port_settings.bits = tty_get_byte_size(cflag, false);
 	dev_dbg(dev, "%s - data bits = %d\n", __func__, port_settings.bits);
 
 	/* determine the parity */
-- 
2.31.1


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

* Re: [PATCH 22/35] tty: make tty_operations::write_room return uint
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
@ 2021-05-05  9:25   ` Geert Uytterhoeven
  2021-05-05 10:34   ` Anton Ivanov
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 71+ messages in thread
From: Geert Uytterhoeven @ 2021-05-05  9:25 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Greg KH, open list:SERIAL DRIVERS, linux-kernel,
	Richard Henderson, Ivan Kokshaysky, Matt Turner,
	James E.J. Bottomley, Helge Deller, Jeff Dike,
	Richard Weinberger, Anton Ivanov, Chris Zankel, Max Filippov,
	Arnd Bergmann, Samuel Iglesias Gonsalvez, Jens Taprogge,
	Karsten Keil, Scott Branden, Ulf Hansson, David S. Miller,
	Jakub Kicinski, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, David Lin, Johan Hovold, Alex Elder,
	Laurentiu Tudor, Jiri Kosina, David Sterba, Shawn Guo,
	Sascha Hauer, Oliver Neukum, Felipe Balbi, Mathias Nyman,
	Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz

On Wed, May 5, 2021 at 11:19 AM Jiri Slaby <jslaby@suse.cz> wrote:
> Line disciplines expect a positive value or zero returned from
> tty->ops->write_room (invoked by tty_write_room). So make this
> assumption explicit by using unsigned int as a return value. Both of
> tty->ops->write_room and tty_write_room.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>

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

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

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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

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

* Re: [PATCH 01/35] tty: remove broken r3964 line discipline
  2021-05-05  9:18 ` [PATCH 01/35] tty: remove broken r3964 line discipline Jiri Slaby
@ 2021-05-05  9:26   ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2021-05-05  9:26 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-serial, linux-kernel

On Wed, May 05, 2021 at 11:18:54AM +0200, Jiri Slaby wrote:
> Noone stepped up in the past two years since it was marked as BROKEN by
> commit c7084edc3f6d (tty: mark Siemens R3964 line discipline as BROKEN).
> Remove the line discipline for good.
> 
> Three remarks:
> * we remove also the uapi header (as noone is able to use that interface
>   anyway)
> * we do *not* remove the N_R3964 constant definition from tty.h, so it
>   remains reserved.
> * in_interrupt() check is now removed from vt's con_put_char. Noone else
>   calls tty_operations::put_char from interrupt context.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> ---
>  arch/powerpc/configs/ppc6xx_defconfig |    1 -
>  drivers/char/Kconfig                  |   13 -
>  drivers/tty/Makefile                  |    1 -
>  drivers/tty/n_r3964.c                 | 1283 -------------------------
>  drivers/tty/vt/vt.c                   |    2 -
>  include/linux/n_r3964.h               |  175 ----
>  include/uapi/linux/n_r3964.h          |   99 --
>  7 files changed, 1574 deletions(-)
>  delete mode 100644 drivers/tty/n_r3964.c
>  delete mode 100644 include/linux/n_r3964.h
>  delete mode 100644 include/uapi/linux/n_r3964.h

Oh yes, thank you!  I guess no one really cares about this anymore,
thanks for removing it.

greg k-h

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

* Re: [PATCH 31/35] tty: remove empty tty_operations::set_termios
  2021-05-05  9:19 ` [PATCH 31/35] tty: remove empty tty_operations::set_termios Jiri Slaby
@ 2021-05-05 10:34   ` Anton Ivanov
  0 siblings, 0 replies; 71+ messages in thread
From: Anton Ivanov @ 2021-05-05 10:34 UTC (permalink / raw)
  To: Jiri Slaby, gregkh
  Cc: linux-serial, linux-kernel, Jeff Dike, Richard Weinberger, Karsten Keil



On 05/05/2021 10:19, Jiri Slaby wrote:
> tty_operations::set_termios is optional. If it doesn't exist, nothing is
> called. So remove almost¹ empty set_termios implementations.
> 
> ¹ capi had an useless pr_debug in it.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> ---
>   arch/um/drivers/line.c          | 5 -----
>   arch/um/drivers/line.h          | 1 -
>   arch/um/drivers/ssl.c           | 1 -
>   arch/um/drivers/stdio_console.c | 1 -
>   drivers/isdn/capi/capi.c        | 6 ------
>   5 files changed, 14 deletions(-)
> 
> diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
> index 159434851417..fbc623d2cc07 100644
> --- a/arch/um/drivers/line.c
> +++ b/arch/um/drivers/line.c
> @@ -211,11 +211,6 @@ int line_write(struct tty_struct *tty, const unsigned char *buf, int len)
>   	return ret;
>   }
>   
> -void line_set_termios(struct tty_struct *tty, struct ktermios * old)
> -{
> -	/* nothing */
> -}
> -
>   void line_throttle(struct tty_struct *tty)
>   {
>   	struct line *line = tty->driver_data;
> diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
> index 3325e2bc64e4..bdb16b96e76f 100644
> --- a/arch/um/drivers/line.h
> +++ b/arch/um/drivers/line.h
> @@ -66,7 +66,6 @@ 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 void line_set_termios(struct tty_struct *tty, struct ktermios * old);
>   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/um/drivers/ssl.c b/arch/um/drivers/ssl.c
> index 6476b28d7c5e..41eae2e8fb65 100644
> --- a/arch/um/drivers/ssl.c
> +++ b/arch/um/drivers/ssl.c
> @@ -99,7 +99,6 @@ static const struct tty_operations ssl_ops = {
>   	.chars_in_buffer 	= line_chars_in_buffer,
>   	.flush_buffer 		= line_flush_buffer,
>   	.flush_chars 		= line_flush_chars,
> -	.set_termios 		= line_set_termios,
>   	.throttle 		= line_throttle,
>   	.unthrottle 		= line_unthrottle,
>   	.install		= ssl_install,
> diff --git a/arch/um/drivers/stdio_console.c b/arch/um/drivers/stdio_console.c
> index 37b127941e6f..e8b762f4d8c2 100644
> --- a/arch/um/drivers/stdio_console.c
> +++ b/arch/um/drivers/stdio_console.c
> @@ -106,7 +106,6 @@ static const struct tty_operations console_ops = {
>   	.chars_in_buffer 	= line_chars_in_buffer,
>   	.flush_buffer 		= line_flush_buffer,
>   	.flush_chars 		= line_flush_chars,
> -	.set_termios 		= line_set_termios,
>   	.throttle 		= line_throttle,
>   	.unthrottle 		= line_unthrottle,
>   	.hangup			= line_hangup,
> diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
> index 6d99b93bb09e..693b0bc31395 100644
> --- a/drivers/isdn/capi/capi.c
> +++ b/drivers/isdn/capi/capi.c
> @@ -1197,11 +1197,6 @@ static unsigned int capinc_tty_chars_in_buffer(struct tty_struct *tty)
>   	return mp->outbytes;
>   }
>   
> -static void capinc_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
> -{
> -	pr_debug("capinc_tty_set_termios\n");
> -}
> -
>   static void capinc_tty_throttle(struct tty_struct *tty)
>   {
>   	struct capiminor *mp = tty->driver_data;
> @@ -1267,7 +1262,6 @@ static const struct tty_operations capinc_ops = {
>   	.flush_chars = capinc_tty_flush_chars,
>   	.write_room = capinc_tty_write_room,
>   	.chars_in_buffer = capinc_tty_chars_in_buffer,
> -	.set_termios = capinc_tty_set_termios,
>   	.throttle = capinc_tty_throttle,
>   	.unthrottle = capinc_tty_unthrottle,
>   	.stop = capinc_tty_stop,
> 

Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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

* Re: [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint
  2021-05-05  9:19 ` [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint Jiri Slaby
@ 2021-05-05 10:34   ` Anton Ivanov
  2021-05-05 10:43   ` David Sterba
  1 sibling, 0 replies; 71+ messages in thread
From: Anton Ivanov @ 2021-05-05 10:34 UTC (permalink / raw)
  To: Jiri Slaby, gregkh
  Cc: linux-serial, linux-kernel, Jeff Dike, Richard Weinberger,
	Arnd Bergmann, Samuel Iglesias Gonsalvez, Jens Taprogge,
	Karsten Keil, Ulf Hansson, David S. Miller, Jakub Kicinski,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger, David Lin,
	Johan Hovold, Alex Elder, Jiri Kosina, David Sterba, Shawn Guo,
	Sascha Hauer, Oliver Neukum, Felipe Balbi, Mathias Nyman,
	Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz



On 05/05/2021 10:19, Jiri Slaby wrote:
> tty_operations::chars_in_buffer is another hook which is expected to
> return values >= 0. So make it explicit by the return type too -- use
> unsigned int.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> Cc: Jens Taprogge <jens.taprogge@taprogge.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: David Sterba <dsterba@suse.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> ---
>   arch/um/drivers/line.c                 |  4 ++--
>   arch/um/drivers/line.h                 |  2 +-
>   drivers/char/pcmcia/synclink_cs.c      |  6 +++---
>   drivers/ipack/devices/ipoctal.c        |  2 +-
>   drivers/isdn/capi/capi.c               |  2 +-
>   drivers/mmc/core/sdio_uart.c           |  2 +-
>   drivers/net/usb/hso.c                  |  4 ++--
>   drivers/s390/char/con3215.c            |  2 +-
>   drivers/s390/char/sclp_rw.c            |  4 ++--
>   drivers/s390/char/sclp_rw.h            |  2 +-
>   drivers/s390/char/sclp_tty.c           |  5 ++---
>   drivers/s390/char/sclp_vt220.c         |  5 ++---
>   drivers/staging/fwserial/fwserial.c    |  6 +++---
>   drivers/staging/greybus/uart.c         |  4 ++--
>   drivers/tty/amiserial.c                |  2 +-
>   drivers/tty/goldfish.c                 |  2 +-
>   drivers/tty/hvc/hvc_console.c          |  2 +-
>   drivers/tty/hvc/hvcs.c                 |  2 +-
>   drivers/tty/hvc/hvsi.c                 |  2 +-
>   drivers/tty/ipwireless/tty.c           |  2 +-
>   drivers/tty/mips_ejtag_fdc.c           |  4 ++--
>   drivers/tty/moxa.c                     | 10 +++++-----
>   drivers/tty/mxser.c                    |  2 +-
>   drivers/tty/n_gsm.c                    |  2 +-
>   drivers/tty/nozomi.c                   |  2 +-
>   drivers/tty/serial/serial_core.c       |  4 ++--
>   drivers/tty/synclink_gt.c              |  6 +++---
>   drivers/tty/tty_ioctl.c                |  2 +-
>   drivers/tty/vcc.c                      |  4 ++--
>   drivers/usb/class/cdc-acm.c            |  2 +-
>   drivers/usb/gadget/function/u_serial.c |  6 +++---
>   drivers/usb/host/xhci-dbgtty.c         |  4 ++--
>   drivers/usb/serial/usb-serial.c        |  2 +-
>   include/linux/tty.h                    |  2 +-
>   include/linux/tty_driver.h             |  2 +-
>   net/bluetooth/rfcomm/tty.c             |  2 +-
>   36 files changed, 58 insertions(+), 60 deletions(-)
> 
> diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
> index 2b8810ba5470..159434851417 100644
> --- a/arch/um/drivers/line.c
> +++ b/arch/um/drivers/line.c
> @@ -60,11 +60,11 @@ unsigned int line_write_room(struct tty_struct *tty)
>   	return room;
>   }
>   
> -int line_chars_in_buffer(struct tty_struct *tty)
> +unsigned int line_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct line *line = tty->driver_data;
>   	unsigned long flags;
> -	int ret;
> +	unsigned int ret;
>   
>   	spin_lock_irqsave(&line->lock, flags);
>   	/* write_room subtracts 1 for the needed NULL, so we readd it.*/
> diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
> index 861edf329569..3325e2bc64e4 100644
> --- a/arch/um/drivers/line.h
> +++ b/arch/um/drivers/line.h
> @@ -67,7 +67,7 @@ extern int line_setup(char **conf, unsigned nlines, char **def,
>   extern int line_write(struct tty_struct *tty, const unsigned char *buf,
>   		      int len);
>   extern void line_set_termios(struct tty_struct *tty, struct ktermios * old);
> -extern int line_chars_in_buffer(struct tty_struct *tty);
> +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);
>   extern unsigned int line_write_room(struct tty_struct *tty);
> diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
> index e4b2c68f44f5..9f7420bc5026 100644
> --- a/drivers/char/pcmcia/synclink_cs.c
> +++ b/drivers/char/pcmcia/synclink_cs.c
> @@ -1637,10 +1637,10 @@ static unsigned int mgslpc_write_room(struct tty_struct *tty)
>   
>   /* Return the count of bytes in transmit buffer
>    */
> -static int mgslpc_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int mgslpc_chars_in_buffer(struct tty_struct *tty)
>   {
>   	MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
> -	int rc;
> +	unsigned int rc;
>   
>   	if (debug_level >= DEBUG_LEVEL_INFO)
>   		printk("%s(%d):mgslpc_chars_in_buffer(%s)\n",
> @@ -1655,7 +1655,7 @@ static int mgslpc_chars_in_buffer(struct tty_struct *tty)
>   		rc = info->tx_count;
>   
>   	if (debug_level >= DEBUG_LEVEL_INFO)
> -		printk("%s(%d):mgslpc_chars_in_buffer(%s)=%d\n",
> +		printk("%s(%d):mgslpc_chars_in_buffer(%s)=%u\n",
>   			 __FILE__, __LINE__, info->device_name, rc);
>   
>   	return rc;
> diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
> index ea0f1aeaaa06..0a3b89c17d08 100644
> --- a/drivers/ipack/devices/ipoctal.c
> +++ b/drivers/ipack/devices/ipoctal.c
> @@ -467,7 +467,7 @@ static unsigned int ipoctal_write_room(struct tty_struct *tty)
>   	return PAGE_SIZE - channel->nb_bytes;
>   }
>   
> -static int ipoctal_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int ipoctal_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct ipoctal_channel *channel = tty->driver_data;
>   
> diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
> index c50c454006b3..dae80197ad9c 100644
> --- a/drivers/isdn/capi/capi.c
> +++ b/drivers/isdn/capi/capi.c
> @@ -1186,7 +1186,7 @@ static unsigned int capinc_tty_write_room(struct tty_struct *tty)
>   	return room;
>   }
>   
> -static int capinc_tty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int capinc_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct capiminor *mp = tty->driver_data;
>   
> diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c
> index c8f4eca7aad4..c36242b86b1d 100644
> --- a/drivers/mmc/core/sdio_uart.c
> +++ b/drivers/mmc/core/sdio_uart.c
> @@ -803,7 +803,7 @@ static unsigned int sdio_uart_write_room(struct tty_struct *tty)
>   	return FIFO_SIZE - kfifo_len(&port->xmit_fifo);
>   }
>   
> -static int sdio_uart_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int sdio_uart_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct sdio_uart_port *port = tty->driver_data;
>   	return kfifo_len(&port->xmit_fifo);
> diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
> index bb8bb85308ab..c7563ed3ac31 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c
> @@ -1404,11 +1404,11 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
>   }
>   
>   /* how many characters in the buffer */
> -static int hso_serial_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int hso_serial_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct hso_serial *serial = tty->driver_data;
> -	int chars;
>   	unsigned long flags;
> +	unsigned int chars;
>   
>   	/* sanity check */
>   	if (serial == NULL)
> diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
> index c9fd4a05931a..8821927ef875 100644
> --- a/drivers/s390/char/con3215.c
> +++ b/drivers/s390/char/con3215.c
> @@ -980,7 +980,7 @@ static void tty3215_flush_chars(struct tty_struct *tty)
>   /*
>    * Returns the number of characters in the output buffer
>    */
> -static int tty3215_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int tty3215_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct raw3215_info *raw = tty->driver_data;
>   
> diff --git a/drivers/s390/char/sclp_rw.c b/drivers/s390/char/sclp_rw.c
> index d6c84e354df5..5a1bf6eaa9d9 100644
> --- a/drivers/s390/char/sclp_rw.c
> +++ b/drivers/s390/char/sclp_rw.c
> @@ -325,10 +325,10 @@ sclp_buffer_space(struct sclp_buffer *buffer)
>   /*
>    * Return number of characters in buffer
>    */
> -int
> +unsigned int
>   sclp_chars_in_buffer(struct sclp_buffer *buffer)
>   {
> -	int count;
> +	unsigned int count;
>   
>   	count = buffer->char_sum;
>   	if (buffer->current_line != NULL)
> diff --git a/drivers/s390/char/sclp_rw.h b/drivers/s390/char/sclp_rw.h
> index 93d706e4935c..b4506be79246 100644
> --- a/drivers/s390/char/sclp_rw.h
> +++ b/drivers/s390/char/sclp_rw.h
> @@ -86,7 +86,7 @@ void *sclp_unmake_buffer(struct sclp_buffer *);
>   int sclp_buffer_space(struct sclp_buffer *);
>   int sclp_write(struct sclp_buffer *buffer, const unsigned char *, int);
>   int sclp_emit_buffer(struct sclp_buffer *,void (*)(struct sclp_buffer *,int));
> -int sclp_chars_in_buffer(struct sclp_buffer *);
> +unsigned int sclp_chars_in_buffer(struct sclp_buffer *);
>   
>   #ifdef CONFIG_SCLP_CONSOLE
>   void sclp_console_pm_event(enum sclp_pm_event sclp_pm_event);
> diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
> index ea1e43fd16bc..162127ff7845 100644
> --- a/drivers/s390/char/sclp_tty.c
> +++ b/drivers/s390/char/sclp_tty.c
> @@ -280,16 +280,15 @@ sclp_tty_flush_chars(struct tty_struct *tty)
>    * characters in the write buffer (will not be written as long as there is a
>    * final line feed missing).
>    */
> -static int
> +static unsigned int
>   sclp_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	unsigned long flags;
>   	struct list_head *l;
>   	struct sclp_buffer *t;
> -	int count;
> +	unsigned int count = 0;
>   
>   	spin_lock_irqsave(&sclp_tty_lock, flags);
> -	count = 0;
>   	if (sclp_ttybuf != NULL)
>   		count = sclp_chars_in_buffer(sclp_ttybuf);
>   	list_for_each(l, &sclp_tty_outqueue) {
> diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
> index b621adee35f0..24eb3a0b0a9a 100644
> --- a/drivers/s390/char/sclp_vt220.c
> +++ b/drivers/s390/char/sclp_vt220.c
> @@ -629,16 +629,15 @@ sclp_vt220_write_room(struct tty_struct *tty)
>   /*
>    * Return number of buffered chars.
>    */
> -static int
> +static unsigned int
>   sclp_vt220_chars_in_buffer(struct tty_struct *tty)
>   {
>   	unsigned long flags;
>   	struct list_head *l;
>   	struct sclp_vt220_request *r;
> -	int count;
> +	unsigned int count = 0;
>   
>   	spin_lock_irqsave(&sclp_vt220_lock, flags);
> -	count = 0;
>   	if (sclp_vt220_current_request != NULL)
>   		count = sclp_vt220_chars_stored(sclp_vt220_current_request);
>   	list_for_each(l, &sclp_vt220_outqueue) {
> diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
> index a151cd76d24e..d2b286ea27c5 100644
> --- a/drivers/staging/fwserial/fwserial.c
> +++ b/drivers/staging/fwserial/fwserial.c
> @@ -1127,16 +1127,16 @@ static unsigned int fwtty_write_room(struct tty_struct *tty)
>   	return n;
>   }
>   
> -static int fwtty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int fwtty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct fwtty_port *port = tty->driver_data;
> -	int n;
> +	unsigned int n;
>   
>   	spin_lock_bh(&port->lock);
>   	n = dma_fifo_level(&port->tx_fifo);
>   	spin_unlock_bh(&port->lock);
>   
> -	fwtty_dbg(port, "%d\n", n);
> +	fwtty_dbg(port, "%u\n", n);
>   
>   	return n;
>   }
> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index 529eccb99b6c..ccfaa0f21b9c 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -457,11 +457,11 @@ static unsigned int gb_tty_write_room(struct tty_struct *tty)
>   	return room;
>   }
>   
> -static int gb_tty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int gb_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct gb_tty *gb_tty = tty->driver_data;
>   	unsigned long flags;
> -	int chars;
> +	unsigned int chars;
>   
>   	spin_lock_irqsave(&gb_tty->write_lock, flags);
>   	chars = kfifo_len(&gb_tty->write_fifo);
> diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
> index ee1f4d72cd5e..5ec19c48fb7a 100644
> --- a/drivers/tty/amiserial.c
> +++ b/drivers/tty/amiserial.c
> @@ -834,7 +834,7 @@ static unsigned int rs_write_room(struct tty_struct *tty)
>   	return CIRC_SPACE(info->xmit.head, info->xmit.tail, SERIAL_XMIT_SIZE);
>   }
>   
> -static int rs_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int rs_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct serial_state *info = tty->driver_data;
>   
> diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c
> index e4f9a60dcc18..ccb683a6e6f5 100644
> --- a/drivers/tty/goldfish.c
> +++ b/drivers/tty/goldfish.c
> @@ -198,7 +198,7 @@ static unsigned int goldfish_tty_write_room(struct tty_struct *tty)
>   	return 0x10000;
>   }
>   
> -static int goldfish_tty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int goldfish_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct goldfish_tty *qtty = &goldfish_ttys[tty->index];
>   	void __iomem *base = qtty->base;
> diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
> index a3725eb69cd3..d0f0253fb93e 100644
> --- a/drivers/tty/hvc/hvc_console.c
> +++ b/drivers/tty/hvc/hvc_console.c
> @@ -596,7 +596,7 @@ static unsigned int hvc_write_room(struct tty_struct *tty)
>   	return hp->outbuf_size - hp->n_outbuf;
>   }
>   
> -static int hvc_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int hvc_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct hvc_struct *hp = tty->driver_data;
>   
> diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
> index f43f2f94d8bd..fe5e6b4f43de 100644
> --- a/drivers/tty/hvc/hvcs.c
> +++ b/drivers/tty/hvc/hvcs.c
> @@ -1386,7 +1386,7 @@ static unsigned int hvcs_write_room(struct tty_struct *tty)
>   	return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
>   }
>   
> -static int hvcs_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int hvcs_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct hvcs_struct *hvcsd = tty->driver_data;
>   
> diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
> index 0a56f44e6b12..bfc15279d5bc 100644
> --- a/drivers/tty/hvc/hvsi.c
> +++ b/drivers/tty/hvc/hvsi.c
> @@ -897,7 +897,7 @@ static unsigned int hvsi_write_room(struct tty_struct *tty)
>   	return N_OUTBUF - hp->n_outbuf;
>   }
>   
> -static int hvsi_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int hvsi_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct hvsi_struct *hp = tty->driver_data;
>   
> diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
> index ab562838313b..e01ca68f24f4 100644
> --- a/drivers/tty/ipwireless/tty.c
> +++ b/drivers/tty/ipwireless/tty.c
> @@ -270,7 +270,7 @@ static int ipwireless_set_serial_info(struct tty_struct *linux_tty,
>   	return 0;	/* Keeps the PCMCIA scripts happy. */
>   }
>   
> -static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
> +static unsigned int ipw_chars_in_buffer(struct tty_struct *linux_tty)
>   {
>   	struct ipw_tty *tty = linux_tty->driver_data;
>   
> diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c
> index f427e8e154d7..3b5915b94fac 100644
> --- a/drivers/tty/mips_ejtag_fdc.c
> +++ b/drivers/tty/mips_ejtag_fdc.c
> @@ -854,10 +854,10 @@ static unsigned int mips_ejtag_fdc_tty_write_room(struct tty_struct *tty)
>   	return room;
>   }
>   
> -static int mips_ejtag_fdc_tty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int mips_ejtag_fdc_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct mips_ejtag_fdc_tty_port *dport = tty->driver_data;
> -	int chars;
> +	unsigned int chars;
>   
>   	/* Report the number of bytes in the xmit buffer */
>   	spin_lock(&dport->xmit_lock);
> diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
> index e4fe9315de29..64b18177c790 100644
> --- a/drivers/tty/moxa.c
> +++ b/drivers/tty/moxa.c
> @@ -190,7 +190,7 @@ static void moxa_close(struct tty_struct *, struct file *);
>   static int moxa_write(struct tty_struct *, const unsigned char *, int);
>   static unsigned int moxa_write_room(struct tty_struct *);
>   static void moxa_flush_buffer(struct tty_struct *);
> -static int moxa_chars_in_buffer(struct tty_struct *);
> +static unsigned int moxa_chars_in_buffer(struct tty_struct *);
>   static void moxa_set_termios(struct tty_struct *, struct ktermios *);
>   static void moxa_stop(struct tty_struct *);
>   static void moxa_start(struct tty_struct *);
> @@ -216,7 +216,7 @@ static int MoxaPortLineStatus(struct moxa_port *);
>   static void MoxaPortFlushData(struct moxa_port *, int);
>   static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int);
>   static int MoxaPortReadData(struct moxa_port *);
> -static int MoxaPortTxQueue(struct moxa_port *);
> +static unsigned int MoxaPortTxQueue(struct moxa_port *);
>   static int MoxaPortRxQueue(struct moxa_port *);
>   static unsigned int MoxaPortTxFree(struct moxa_port *);
>   static void MoxaPortTxDisable(struct moxa_port *);
> @@ -1239,10 +1239,10 @@ static void moxa_flush_buffer(struct tty_struct *tty)
>   	tty_wakeup(tty);
>   }
>   
> -static int moxa_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int moxa_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct moxa_port *ch = tty->driver_data;
> -	int chars;
> +	unsigned int chars;
>   
>   	chars = MoxaPortTxQueue(ch);
>   	if (chars)
> @@ -1981,7 +1981,7 @@ static int MoxaPortReadData(struct moxa_port *port)
>   }
>   
>   
> -static int MoxaPortTxQueue(struct moxa_port *port)
> +static unsigned int MoxaPortTxQueue(struct moxa_port *port)
>   {
>   	void __iomem *ofsAddr = port->tableAddr;
>   	u16 rptr, wptr, mask;
> diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
> index 5851a45d828c..a74e6146a748 100644
> --- a/drivers/tty/mxser.c
> +++ b/drivers/tty/mxser.c
> @@ -1192,7 +1192,7 @@ static unsigned int mxser_write_room(struct tty_struct *tty)
>   	return ret < 0 ? 0 : ret;
>   }
>   
> -static int mxser_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int mxser_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct mxser_port *info = tty->driver_data;
>   	return info->xmit_cnt;
> diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
> index 06f0c6d39620..bd24dc0d7e96 100644
> --- a/drivers/tty/n_gsm.c
> +++ b/drivers/tty/n_gsm.c
> @@ -3064,7 +3064,7 @@ static unsigned int gsmtty_write_room(struct tty_struct *tty)
>   	return TX_SIZE - kfifo_len(&dlci->fifo);
>   }
>   
> -static int gsmtty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int gsmtty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct gsm_dlci *dlci = tty->driver_data;
>   	if (dlci->state == DLCI_CLOSED)
> diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
> index c55475a9a184..62c16731ccd8 100644
> --- a/drivers/tty/nozomi.c
> +++ b/drivers/tty/nozomi.c
> @@ -1776,7 +1776,7 @@ static void ntty_throttle(struct tty_struct *tty)
>   }
>   
>   /* Returns number of chars in buffer, called by tty layer */
> -static s32 ntty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int ntty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct port *port = tty->driver_data;
>   	struct nozomi *dc = get_dc_by_tty(tty);
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index cb46a65a5dd8..d29329eb52f4 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -629,12 +629,12 @@ static unsigned int uart_write_room(struct tty_struct *tty)
>   	return ret;
>   }
>   
> -static int uart_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int uart_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct uart_state *state = tty->driver_data;
>   	struct uart_port *port;
>   	unsigned long flags;
> -	int ret;
> +	unsigned int ret;
>   
>   	port = uart_port_lock(state, flags);
>   	ret = uart_circ_chars_pending(&state->xmit);
> diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
> index 583aa8342112..cf87dc66087b 100644
> --- a/drivers/tty/synclink_gt.c
> +++ b/drivers/tty/synclink_gt.c
> @@ -1254,14 +1254,14 @@ static int synclink_gt_proc_show(struct seq_file *m, void *v)
>   /*
>    * return count of bytes in transmit buffer
>    */
> -static int chars_in_buffer(struct tty_struct *tty)
> +static unsigned int chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct slgt_info *info = tty->driver_data;
> -	int count;
> +	unsigned int count;
>   	if (sanity_check(info, tty->name, "chars_in_buffer"))
>   		return 0;
>   	count = tbuf_bytes(info);
> -	DBGINFO(("%s chars_in_buffer()=%d\n", info->device_name, count));
> +	DBGINFO(("%s chars_in_buffer()=%u\n", info->device_name, count));
>   	return count;
>   }
>   
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index d8834784b586..aa9ecc8be990 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -54,7 +54,7 @@
>    *	to be no queue on the device.
>    */
>   
> -int tty_chars_in_buffer(struct tty_struct *tty)
> +unsigned int tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	if (tty->ops->chars_in_buffer)
>   		return tty->ops->chars_in_buffer(tty);
> diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
> index d82ce3bb82c3..e883b8f12099 100644
> --- a/drivers/tty/vcc.c
> +++ b/drivers/tty/vcc.c
> @@ -888,10 +888,10 @@ static unsigned int vcc_write_room(struct tty_struct *tty)
>   	return num;
>   }
>   
> -static int vcc_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int vcc_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct vcc_port *port;
> -	u64 num;
> +	unsigned int num;
>   
>   	port = vcc_get_ne(tty->index);
>   	if (unlikely(!port)) {
> diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
> index 76b7fd234238..81199efe0312 100644
> --- a/drivers/usb/class/cdc-acm.c
> +++ b/drivers/usb/class/cdc-acm.c
> @@ -848,7 +848,7 @@ static unsigned int acm_tty_write_room(struct tty_struct *tty)
>   	return acm_wb_is_avail(acm) ? acm->writesize : 0;
>   }
>   
> -static int acm_tty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int acm_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct acm *acm = tty->driver_data;
>   	/*
> diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
> index 676a920d9d6b..bffef8e47dac 100644
> --- a/drivers/usb/gadget/function/u_serial.c
> +++ b/drivers/usb/gadget/function/u_serial.c
> @@ -791,17 +791,17 @@ static unsigned int gs_write_room(struct tty_struct *tty)
>   	return room;
>   }
>   
> -static int gs_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int gs_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct gs_port	*port = tty->driver_data;
>   	unsigned long	flags;
> -	int		chars = 0;
> +	unsigned int	chars;
>   
>   	spin_lock_irqsave(&port->port_lock, flags);
>   	chars = kfifo_len(&port->port_write_buf);
>   	spin_unlock_irqrestore(&port->port_lock, flags);
>   
> -	pr_vdebug("gs_chars_in_buffer: (%d,%p) chars=%d\n",
> +	pr_vdebug("gs_chars_in_buffer: (%d,%p) chars=%u\n",
>   		port->port_num, tty, chars);
>   
>   	return chars;
> diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
> index cd3ab35dd689..bef104511352 100644
> --- a/drivers/usb/host/xhci-dbgtty.c
> +++ b/drivers/usb/host/xhci-dbgtty.c
> @@ -253,11 +253,11 @@ static unsigned int dbc_tty_write_room(struct tty_struct *tty)
>   	return room;
>   }
>   
> -static int dbc_tty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int dbc_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct dbc_port		*port = tty->driver_data;
>   	unsigned long		flags;
> -	int			chars = 0;
> +	unsigned int		chars;
>   
>   	spin_lock_irqsave(&port->port_lock, flags);
>   	chars = kfifo_len(&port->write_fifo);
> diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
> index 055096831daf..eeb441c77207 100644
> --- a/drivers/usb/serial/usb-serial.c
> +++ b/drivers/usb/serial/usb-serial.c
> @@ -385,7 +385,7 @@ static unsigned int serial_write_room(struct tty_struct *tty)
>   	return port->serial->type->write_room(tty);
>   }
>   
> -static int serial_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int serial_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct usb_serial_port *port = tty->driver_data;
>   	struct usb_serial *serial = port->serial;
> diff --git a/include/linux/tty.h b/include/linux/tty.h
> index d18fc34d3054..5cf6b2e7331b 100644
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -458,7 +458,7 @@ extern void tty_unregister_device(struct tty_driver *driver, unsigned index);
>   extern void tty_write_message(struct tty_struct *tty, char *msg);
>   extern int tty_send_xchar(struct tty_struct *tty, char ch);
>   extern int tty_put_char(struct tty_struct *tty, unsigned char c);
> -extern int tty_chars_in_buffer(struct tty_struct *tty);
> +extern unsigned int tty_chars_in_buffer(struct tty_struct *tty);
>   extern unsigned int tty_write_room(struct tty_struct *tty);
>   extern void tty_driver_flush_buffer(struct tty_struct *tty);
>   extern void tty_throttle(struct tty_struct *tty);
> diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
> index ea5b15c72764..a4694bb125cc 100644
> --- a/include/linux/tty_driver.h
> +++ b/include/linux/tty_driver.h
> @@ -257,7 +257,7 @@ struct tty_operations {
>   	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);
> -	int  (*chars_in_buffer)(struct tty_struct *tty);
> +	unsigned int (*chars_in_buffer)(struct tty_struct *tty);
>   	int  (*ioctl)(struct tty_struct *tty,
>   		    unsigned int cmd, unsigned long arg);
>   	long (*compat_ioctl)(struct tty_struct *tty,
> diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
> index a5e3d957f20f..c76dcc0f679b 100644
> --- a/net/bluetooth/rfcomm/tty.c
> +++ b/net/bluetooth/rfcomm/tty.c
> @@ -1010,7 +1010,7 @@ static void rfcomm_tty_unthrottle(struct tty_struct *tty)
>   	rfcomm_dlc_unthrottle(dev->dlc);
>   }
>   
> -static int rfcomm_tty_chars_in_buffer(struct tty_struct *tty)
> +static unsigned int rfcomm_tty_chars_in_buffer(struct tty_struct *tty)
>   {
>   	struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
>   
> 

Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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

* Re: [PATCH 22/35] tty: make tty_operations::write_room return uint
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
  2021-05-05  9:25   ` Geert Uytterhoeven
@ 2021-05-05 10:34   ` Anton Ivanov
  2021-05-05 10:43   ` David Sterba
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 71+ messages in thread
From: Anton Ivanov @ 2021-05-05 10:34 UTC (permalink / raw)
  To: Jiri Slaby, gregkh
  Cc: linux-serial, linux-kernel, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, Geert Uytterhoeven, James E.J. Bottomley,
	Helge Deller, Jeff Dike, Richard Weinberger, Chris Zankel,
	Max Filippov, Arnd Bergmann, Samuel Iglesias Gonsalvez,
	Jens Taprogge, Karsten Keil, Scott Branden, Ulf Hansson,
	David S. Miller, Jakub Kicinski, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, David Lin, Johan Hovold, Alex Elder,
	Laurentiu Tudor, Jiri Kosina, David Sterba, Shawn Guo,
	Sascha Hauer, Oliver Neukum, Felipe Balbi, Mathias Nyman,
	Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz



On 05/05/2021 10:19, Jiri Slaby wrote:
> Line disciplines expect a positive value or zero returned from
> tty->ops->write_room (invoked by tty_write_room). So make this
> assumption explicit by using unsigned int as a return value. Both of
> tty->ops->write_room and tty_write_room.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> Cc: Jens Taprogge <jens.taprogge@taprogge.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Scott Branden <scott.branden@broadcom.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: David Sterba <dsterba@suse.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> ---
>   arch/alpha/kernel/srmcons.c            | 2 +-
>   arch/m68k/emu/nfcon.c                  | 2 +-
>   arch/parisc/kernel/pdc_cons.c          | 2 +-
>   arch/um/drivers/line.c                 | 6 +++---
>   arch/um/drivers/line.h                 | 2 +-
>   arch/xtensa/platforms/iss/console.c    | 2 +-
>   drivers/char/pcmcia/synclink_cs.c      | 2 +-
>   drivers/char/ttyprintk.c               | 2 +-
>   drivers/ipack/devices/ipoctal.c        | 2 +-
>   drivers/isdn/capi/capi.c               | 6 +++---
>   drivers/misc/bcm-vk/bcm_vk_tty.c       | 2 +-
>   drivers/mmc/core/sdio_uart.c           | 2 +-
>   drivers/net/usb/hso.c                  | 4 ++--
>   drivers/s390/char/con3215.c            | 2 +-
>   drivers/s390/char/sclp_tty.c           | 4 ++--
>   drivers/s390/char/sclp_vt220.c         | 4 ++--
>   drivers/s390/char/tty3270.c            | 2 +-
>   drivers/staging/fwserial/fwserial.c    | 6 +++---
>   drivers/staging/gdm724x/gdm_tty.c      | 2 +-
>   drivers/staging/greybus/uart.c         | 2 +-
>   drivers/tty/amiserial.c                | 2 +-
>   drivers/tty/ehv_bytechan.c             | 4 ++--
>   drivers/tty/goldfish.c                 | 2 +-
>   drivers/tty/hvc/hvc_console.c          | 2 +-
>   drivers/tty/hvc/hvcs.c                 | 2 +-
>   drivers/tty/hvc/hvsi.c                 | 4 ++--
>   drivers/tty/ipwireless/tty.c           | 2 +-
>   drivers/tty/mips_ejtag_fdc.c           | 4 ++--
>   drivers/tty/moxa.c                     | 8 ++++----
>   drivers/tty/mxser.c                    | 2 +-
>   drivers/tty/n_gsm.c                    | 2 +-
>   drivers/tty/nozomi.c                   | 4 ++--
>   drivers/tty/pty.c                      | 2 +-
>   drivers/tty/serial/kgdb_nmi.c          | 2 +-
>   drivers/tty/serial/serial_core.c       | 4 ++--
>   drivers/tty/synclink_gt.c              | 6 +++---
>   drivers/tty/tty_ioctl.c                | 2 +-
>   drivers/tty/ttynull.c                  | 2 +-
>   drivers/tty/vcc.c                      | 4 ++--
>   drivers/tty/vt/vt.c                    | 2 +-
>   drivers/usb/class/cdc-acm.c            | 2 +-
>   drivers/usb/gadget/function/u_serial.c | 6 +++---
>   drivers/usb/host/xhci-dbgtty.c         | 4 ++--
>   drivers/usb/serial/usb-serial.c        | 2 +-
>   include/linux/tty.h                    | 2 +-
>   include/linux/tty_driver.h             | 4 ++--
>   net/bluetooth/rfcomm/tty.c             | 2 +-
>   47 files changed, 71 insertions(+), 71 deletions(-)
> 
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index 438b10c44d73..2110b7e7f988 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -142,7 +142,7 @@ srmcons_write(struct tty_struct *tty,
>   	return count;
>   }
>   
> -static int
> +static unsigned int
>   srmcons_write_room(struct tty_struct *tty)
>   {
>   	return 512;
> diff --git a/arch/m68k/emu/nfcon.c b/arch/m68k/emu/nfcon.c
> index 57e8c8fb5eba..92636c89d65b 100644
> --- a/arch/m68k/emu/nfcon.c
> +++ b/arch/m68k/emu/nfcon.c
> @@ -85,7 +85,7 @@ static int nfcon_tty_put_char(struct tty_struct *tty, unsigned char ch)
>   	return 1;
>   }
>   
> -static int nfcon_tty_write_room(struct tty_struct *tty)
> +static unsigned int nfcon_tty_write_room(struct tty_struct *tty)
>   {
>   	return 64;
>   }
> diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c
> index 7ed404c60a9e..fe2ed0bbd07e 100644
> --- a/arch/parisc/kernel/pdc_cons.c
> +++ b/arch/parisc/kernel/pdc_cons.c
> @@ -103,7 +103,7 @@ static int pdc_console_tty_write(struct tty_struct *tty, const unsigned char *bu
>   	return count;
>   }
>   
> -static int pdc_console_tty_write_room(struct tty_struct *tty)
> +static unsigned int pdc_console_tty_write_room(struct tty_struct *tty)
>   {
>   	return 32768; /* no limit, no buffer used */
>   }
> diff --git a/arch/um/drivers/line.c b/arch/um/drivers/line.c
> index 1c70a31e7c5b..2b8810ba5470 100644
> --- a/arch/um/drivers/line.c
> +++ b/arch/um/drivers/line.c
> @@ -32,7 +32,7 @@ static irqreturn_t line_interrupt(int irq, void *data)
>    *
>    * Should be called while holding line->lock (this does not modify data).
>    */
> -static int write_room(struct line *line)
> +static unsigned int write_room(struct line *line)
>   {
>   	int n;
>   
> @@ -47,11 +47,11 @@ static int write_room(struct line *line)
>   	return n - 1;
>   }
>   
> -int line_write_room(struct tty_struct *tty)
> +unsigned int line_write_room(struct tty_struct *tty)
>   {
>   	struct line *line = tty->driver_data;
>   	unsigned long flags;
> -	int room;
> +	unsigned int room;
>   
>   	spin_lock_irqsave(&line->lock, flags);
>   	room = write_room(line);
> diff --git a/arch/um/drivers/line.h b/arch/um/drivers/line.h
> index 01d21e76144f..861edf329569 100644
> --- a/arch/um/drivers/line.h
> +++ b/arch/um/drivers/line.h
> @@ -70,7 +70,7 @@ extern void line_set_termios(struct tty_struct *tty, struct ktermios * old);
>   extern 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);
> -extern int line_write_room(struct tty_struct *tty);
> +extern unsigned int line_write_room(struct tty_struct *tty);
>   extern void line_throttle(struct tty_struct *tty);
>   extern void line_unthrottle(struct tty_struct *tty);
>   
> diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
> index a3dda25a4e45..98ac3a7fdb0a 100644
> --- a/arch/xtensa/platforms/iss/console.c
> +++ b/arch/xtensa/platforms/iss/console.c
> @@ -100,7 +100,7 @@ static void rs_flush_chars(struct tty_struct *tty)
>   {
>   }
>   
> -static int rs_write_room(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;
> diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
> index b4707bc3aee8..e4b2c68f44f5 100644
> --- a/drivers/char/pcmcia/synclink_cs.c
> +++ b/drivers/char/pcmcia/synclink_cs.c
> @@ -1609,7 +1609,7 @@ static int mgslpc_write(struct tty_struct * tty,
>   
>   /* Return the count of free bytes in transmit buffer
>    */
> -static int mgslpc_write_room(struct tty_struct *tty)
> +static unsigned int mgslpc_write_room(struct tty_struct *tty)
>   {
>   	MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
>   	int ret;
> diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
> index 93f5d11c830b..e93b0af92339 100644
> --- a/drivers/char/ttyprintk.c
> +++ b/drivers/char/ttyprintk.c
> @@ -132,7 +132,7 @@ static int tpk_write(struct tty_struct *tty,
>   /*
>    * TTY operations write_room function.
>    */
> -static int tpk_write_room(struct tty_struct *tty)
> +static unsigned int tpk_write_room(struct tty_struct *tty)
>   {
>   	return TPK_MAX_ROOM;
>   }
> diff --git a/drivers/ipack/devices/ipoctal.c b/drivers/ipack/devices/ipoctal.c
> index 3940714e4397..ea0f1aeaaa06 100644
> --- a/drivers/ipack/devices/ipoctal.c
> +++ b/drivers/ipack/devices/ipoctal.c
> @@ -460,7 +460,7 @@ static int ipoctal_write_tty(struct tty_struct *tty,
>   	return char_copied;
>   }
>   
> -static int ipoctal_write_room(struct tty_struct *tty)
> +static unsigned int ipoctal_write_room(struct tty_struct *tty)
>   {
>   	struct ipoctal_channel *channel = tty->driver_data;
>   
> diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
> index fdf87acccd06..c50c454006b3 100644
> --- a/drivers/isdn/capi/capi.c
> +++ b/drivers/isdn/capi/capi.c
> @@ -1175,14 +1175,14 @@ static void capinc_tty_flush_chars(struct tty_struct *tty)
>   	handle_minor_recv(mp);
>   }
>   
> -static int capinc_tty_write_room(struct tty_struct *tty)
> +static unsigned int capinc_tty_write_room(struct tty_struct *tty)
>   {
>   	struct capiminor *mp = tty->driver_data;
> -	int room;
> +	unsigned int room;
>   
>   	room = CAPINC_MAX_SENDQUEUE-skb_queue_len(&mp->outqueue);
>   	room *= CAPI_MAX_BLKSIZE;
> -	pr_debug("capinc_tty_write_room = %d\n", room);
> +	pr_debug("capinc_tty_write_room = %u\n", room);
>   	return room;
>   }
>   
> diff --git a/drivers/misc/bcm-vk/bcm_vk_tty.c b/drivers/misc/bcm-vk/bcm_vk_tty.c
> index 4d02692ecfc7..dae9eeed84a2 100644
> --- a/drivers/misc/bcm-vk/bcm_vk_tty.c
> +++ b/drivers/misc/bcm-vk/bcm_vk_tty.c
> @@ -214,7 +214,7 @@ static int bcm_vk_tty_write(struct tty_struct *tty,
>   	return count;
>   }
>   
> -static int bcm_vk_tty_write_room(struct tty_struct *tty)
> +static unsigned int bcm_vk_tty_write_room(struct tty_struct *tty)
>   {
>   	struct bcm_vk *vk = dev_get_drvdata(tty->dev);
>   
> diff --git a/drivers/mmc/core/sdio_uart.c b/drivers/mmc/core/sdio_uart.c
> index dbcac2b7f2fe..c8f4eca7aad4 100644
> --- a/drivers/mmc/core/sdio_uart.c
> +++ b/drivers/mmc/core/sdio_uart.c
> @@ -797,7 +797,7 @@ static int sdio_uart_write(struct tty_struct *tty, const unsigned char *buf,
>   	return ret;
>   }
>   
> -static int sdio_uart_write_room(struct tty_struct *tty)
> +static unsigned int sdio_uart_write_room(struct tty_struct *tty)
>   {
>   	struct sdio_uart_port *port = tty->driver_data;
>   	return FIFO_SIZE - kfifo_len(&port->xmit_fifo);
> diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
> index 3ef4b2841402..bb8bb85308ab 100644
> --- a/drivers/net/usb/hso.c
> +++ b/drivers/net/usb/hso.c
> @@ -1357,10 +1357,10 @@ static int hso_serial_write(struct tty_struct *tty, const unsigned char *buf,
>   }
>   
>   /* how much room is there for writing */
> -static int hso_serial_write_room(struct tty_struct *tty)
> +static unsigned int hso_serial_write_room(struct tty_struct *tty)
>   {
>   	struct hso_serial *serial = tty->driver_data;
> -	int room;
> +	unsigned int room;
>   	unsigned long flags;
>   
>   	spin_lock_irqsave(&serial->serial_lock, flags);
> diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c
> index 1fd5bca9fa20..c9fd4a05931a 100644
> --- a/drivers/s390/char/con3215.c
> +++ b/drivers/s390/char/con3215.c
> @@ -924,7 +924,7 @@ static void tty3215_close(struct tty_struct *tty, struct file * filp)
>   /*
>    * Returns the amount of free space in the output buffer.
>    */
> -static int tty3215_write_room(struct tty_struct *tty)
> +static unsigned int tty3215_write_room(struct tty_struct *tty)
>   {
>   	struct raw3215_info *raw = tty->driver_data;
>   
> diff --git a/drivers/s390/char/sclp_tty.c b/drivers/s390/char/sclp_tty.c
> index 4456ceb23bd2..ea1e43fd16bc 100644
> --- a/drivers/s390/char/sclp_tty.c
> +++ b/drivers/s390/char/sclp_tty.c
> @@ -86,12 +86,12 @@ sclp_tty_close(struct tty_struct *tty, struct file *filp)
>    * a string of newlines. Every newline creates a new message which
>    * needs 82 bytes.
>    */
> -static int
> +static unsigned int
>   sclp_tty_write_room (struct tty_struct *tty)
>   {
>   	unsigned long flags;
>   	struct list_head *l;
> -	int count;
> +	unsigned int count;
>   
>   	spin_lock_irqsave(&sclp_tty_lock, flags);
>   	count = 0;
> diff --git a/drivers/s390/char/sclp_vt220.c b/drivers/s390/char/sclp_vt220.c
> index 7f4445b0f819..b621adee35f0 100644
> --- a/drivers/s390/char/sclp_vt220.c
> +++ b/drivers/s390/char/sclp_vt220.c
> @@ -609,12 +609,12 @@ sclp_vt220_flush_chars(struct tty_struct *tty)
>    * to change as output buffers get emptied, or if the output flow
>    * control is acted.
>    */
> -static int
> +static unsigned int
>   sclp_vt220_write_room(struct tty_struct *tty)
>   {
>   	unsigned long flags;
>   	struct list_head *l;
> -	int count;
> +	unsigned int count;
>   
>   	spin_lock_irqsave(&sclp_vt220_lock, flags);
>   	count = 0;
> diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
> index 1b68564799fa..82d4c961ed06 100644
> --- a/drivers/s390/char/tty3270.c
> +++ b/drivers/s390/char/tty3270.c
> @@ -1071,7 +1071,7 @@ static void tty3270_cleanup(struct tty_struct *tty)
>   /*
>    * We always have room.
>    */
> -static int
> +static unsigned int
>   tty3270_write_room(struct tty_struct *tty)
>   {
>   	return INT_MAX;
> diff --git a/drivers/staging/fwserial/fwserial.c b/drivers/staging/fwserial/fwserial.c
> index 4245532d2fe0..a151cd76d24e 100644
> --- a/drivers/staging/fwserial/fwserial.c
> +++ b/drivers/staging/fwserial/fwserial.c
> @@ -1113,16 +1113,16 @@ static int fwtty_write(struct tty_struct *tty, const unsigned char *buf, int c)
>   	return (n < 0) ? 0 : n;
>   }
>   
> -static int fwtty_write_room(struct tty_struct *tty)
> +static unsigned int fwtty_write_room(struct tty_struct *tty)
>   {
>   	struct fwtty_port *port = tty->driver_data;
> -	int n;
> +	unsigned int n;
>   
>   	spin_lock_bh(&port->lock);
>   	n = dma_fifo_avail(&port->tx_fifo);
>   	spin_unlock_bh(&port->lock);
>   
> -	fwtty_dbg(port, "%d\n", n);
> +	fwtty_dbg(port, "%u\n", n);
>   
>   	return n;
>   }
> diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
> index 0ccc8c24e754..279de2cd9c4a 100644
> --- a/drivers/staging/gdm724x/gdm_tty.c
> +++ b/drivers/staging/gdm724x/gdm_tty.c
> @@ -183,7 +183,7 @@ static int gdm_tty_write(struct tty_struct *tty, const unsigned char *buf,
>   	return len;
>   }
>   
> -static int gdm_tty_write_room(struct tty_struct *tty)
> +static unsigned int gdm_tty_write_room(struct tty_struct *tty)
>   {
>   	struct gdm *gdm = tty->driver_data;
>   
> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index b1e63f7798b0..529eccb99b6c 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -440,7 +440,7 @@ static int gb_tty_write(struct tty_struct *tty, const unsigned char *buf,
>   	return count;
>   }
>   
> -static int gb_tty_write_room(struct tty_struct *tty)
> +static unsigned int gb_tty_write_room(struct tty_struct *tty)
>   {
>   	struct gb_tty *gb_tty = tty->driver_data;
>   	unsigned long flags;
> diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c
> index a4b8876091d2..ee1f4d72cd5e 100644
> --- a/drivers/tty/amiserial.c
> +++ b/drivers/tty/amiserial.c
> @@ -827,7 +827,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
>   	return ret;
>   }
>   
> -static int rs_write_room(struct tty_struct *tty)
> +static unsigned int rs_write_room(struct tty_struct *tty)
>   {
>   	struct serial_state *info = tty->driver_data;
>   
> diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c
> index 3c6dd06ec5fb..445e5ff9b36d 100644
> --- a/drivers/tty/ehv_bytechan.c
> +++ b/drivers/tty/ehv_bytechan.c
> @@ -536,11 +536,11 @@ static void ehv_bc_tty_close(struct tty_struct *ttys, struct file *filp)
>    * how much write room the driver can guarantee will be sent OR BUFFERED.  This
>    * driver MUST honor the return value.
>    */
> -static int ehv_bc_tty_write_room(struct tty_struct *ttys)
> +static unsigned int ehv_bc_tty_write_room(struct tty_struct *ttys)
>   {
>   	struct ehv_bc_data *bc = ttys->driver_data;
>   	unsigned long flags;
> -	int count;
> +	unsigned int count;
>   
>   	spin_lock_irqsave(&bc->lock, flags);
>   	count = CIRC_SPACE(bc->head, bc->tail, BUF_SIZE);
> diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c
> index cd23a4b05c8f..e4f9a60dcc18 100644
> --- a/drivers/tty/goldfish.c
> +++ b/drivers/tty/goldfish.c
> @@ -193,7 +193,7 @@ static int goldfish_tty_write(struct tty_struct *tty, const unsigned char *buf,
>   	return count;
>   }
>   
> -static int goldfish_tty_write_room(struct tty_struct *tty)
> +static unsigned int goldfish_tty_write_room(struct tty_struct *tty)
>   {
>   	return 0x10000;
>   }
> diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
> index cdcc64ea2554..a3725eb69cd3 100644
> --- a/drivers/tty/hvc/hvc_console.c
> +++ b/drivers/tty/hvc/hvc_console.c
> @@ -586,7 +586,7 @@ static void hvc_set_winsz(struct work_struct *work)
>    * how much write room the driver can guarantee will be sent OR BUFFERED.  This
>    * driver MUST honor the return value.
>    */
> -static int hvc_write_room(struct tty_struct *tty)
> +static unsigned int hvc_write_room(struct tty_struct *tty)
>   {
>   	struct hvc_struct *hp = tty->driver_data;
>   
> diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
> index 197988c55e0c..f43f2f94d8bd 100644
> --- a/drivers/tty/hvc/hvcs.c
> +++ b/drivers/tty/hvc/hvcs.c
> @@ -1376,7 +1376,7 @@ static int hvcs_write(struct tty_struct *tty,
>    * absolutely WILL BUFFER if we can't send it.  This driver MUST honor the
>    * return value, hence the reason for hvcs_struct buffering.
>    */
> -static int hvcs_write_room(struct tty_struct *tty)
> +static unsigned int hvcs_write_room(struct tty_struct *tty)
>   {
>   	struct hvcs_struct *hvcsd = tty->driver_data;
>   
> diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
> index e8c58f9bd263..0a56f44e6b12 100644
> --- a/drivers/tty/hvc/hvsi.c
> +++ b/drivers/tty/hvc/hvsi.c
> @@ -890,7 +890,7 @@ static void hvsi_write_worker(struct work_struct *work)
>   	spin_unlock_irqrestore(&hp->lock, flags);
>   }
>   
> -static int hvsi_write_room(struct tty_struct *tty)
> +static unsigned int hvsi_write_room(struct tty_struct *tty)
>   {
>   	struct hvsi_struct *hp = tty->driver_data;
>   
> @@ -929,7 +929,7 @@ static int hvsi_write(struct tty_struct *tty,
>   	 * will see there is no room in outbuf and return.
>   	 */
>   	while ((count > 0) && (hvsi_write_room(tty) > 0)) {
> -		int chunksize = min(count, hvsi_write_room(tty));
> +		int chunksize = min_t(int, count, hvsi_write_room(tty));
>   
>   		BUG_ON(hp->n_outbuf < 0);
>   		memcpy(hp->outbuf + hp->n_outbuf, source, chunksize);
> diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
> index 99bb2f149ff5..ab562838313b 100644
> --- a/drivers/tty/ipwireless/tty.c
> +++ b/drivers/tty/ipwireless/tty.c
> @@ -228,7 +228,7 @@ static int ipw_write(struct tty_struct *linux_tty,
>   	return count;
>   }
>   
> -static int ipw_write_room(struct tty_struct *linux_tty)
> +static unsigned int ipw_write_room(struct tty_struct *linux_tty)
>   {
>   	struct ipw_tty *tty = linux_tty->driver_data;
>   	int room;
> diff --git a/drivers/tty/mips_ejtag_fdc.c b/drivers/tty/mips_ejtag_fdc.c
> index a8e19b4833bf..f427e8e154d7 100644
> --- a/drivers/tty/mips_ejtag_fdc.c
> +++ b/drivers/tty/mips_ejtag_fdc.c
> @@ -840,11 +840,11 @@ static int mips_ejtag_fdc_tty_write(struct tty_struct *tty,
>   	return total;
>   }
>   
> -static int mips_ejtag_fdc_tty_write_room(struct tty_struct *tty)
> +static unsigned int mips_ejtag_fdc_tty_write_room(struct tty_struct *tty)
>   {
>   	struct mips_ejtag_fdc_tty_port *dport = tty->driver_data;
>   	struct mips_ejtag_fdc_tty *priv = dport->driver;
> -	int room;
> +	unsigned int room;
>   
>   	/* Report the space in the xmit buffer */
>   	spin_lock(&dport->xmit_lock);
> diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
> index 847ad3dac107..e4fe9315de29 100644
> --- a/drivers/tty/moxa.c
> +++ b/drivers/tty/moxa.c
> @@ -188,7 +188,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_room(struct tty_struct *);
> +static unsigned int moxa_write_room(struct tty_struct *);
>   static void moxa_flush_buffer(struct tty_struct *);
>   static int moxa_chars_in_buffer(struct tty_struct *);
>   static void moxa_set_termios(struct tty_struct *, struct ktermios *);
> @@ -218,7 +218,7 @@ static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int);
>   static int MoxaPortReadData(struct moxa_port *);
>   static int MoxaPortTxQueue(struct moxa_port *);
>   static int MoxaPortRxQueue(struct moxa_port *);
> -static int MoxaPortTxFree(struct moxa_port *);
> +static unsigned int MoxaPortTxFree(struct moxa_port *);
>   static void MoxaPortTxDisable(struct moxa_port *);
>   static void MoxaPortTxEnable(struct moxa_port *);
>   static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *);
> @@ -1217,7 +1217,7 @@ static int moxa_write(struct tty_struct *tty,
>   	return len;
>   }
>   
> -static int moxa_write_room(struct tty_struct *tty)
> +static unsigned int moxa_write_room(struct tty_struct *tty)
>   {
>   	struct moxa_port *ch;
>   
> @@ -1992,7 +1992,7 @@ static int MoxaPortTxQueue(struct moxa_port *port)
>   	return (wptr - rptr) & mask;
>   }
>   
> -static int MoxaPortTxFree(struct moxa_port *port)
> +static unsigned int MoxaPortTxFree(struct moxa_port *port)
>   {
>   	void __iomem *ofsAddr = port->tableAddr;
>   	u16 rptr, wptr, mask;
> diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
> index 85271e109014..5851a45d828c 100644
> --- a/drivers/tty/mxser.c
> +++ b/drivers/tty/mxser.c
> @@ -1183,7 +1183,7 @@ static void mxser_flush_chars(struct tty_struct *tty)
>   	spin_unlock_irqrestore(&info->slock, flags);
>   }
>   
> -static int mxser_write_room(struct tty_struct *tty)
> +static unsigned int mxser_write_room(struct tty_struct *tty)
>   {
>   	struct mxser_port *info = tty->driver_data;
>   	int ret;
> diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
> index 157b26ef6259..06f0c6d39620 100644
> --- a/drivers/tty/n_gsm.c
> +++ b/drivers/tty/n_gsm.c
> @@ -3056,7 +3056,7 @@ static int gsmtty_write(struct tty_struct *tty, const unsigned char *buf,
>   	return sent;
>   }
>   
> -static int gsmtty_write_room(struct tty_struct *tty)
> +static unsigned int gsmtty_write_room(struct tty_struct *tty)
>   {
>   	struct gsm_dlci *dlci = tty->driver_data;
>   	if (dlci->state == DLCI_CLOSED)
> diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c
> index 9a2d78ace49b..c55475a9a184 100644
> --- a/drivers/tty/nozomi.c
> +++ b/drivers/tty/nozomi.c
> @@ -1636,10 +1636,10 @@ static int ntty_write(struct tty_struct *tty, const unsigned char *buffer,
>    * If the port is unplugged report lots of room and let the bits
>    * dribble away so we don't block anything.
>    */
> -static int ntty_write_room(struct tty_struct *tty)
> +static unsigned int ntty_write_room(struct tty_struct *tty)
>   {
>   	struct port *port = tty->driver_data;
> -	int room = 4096;
> +	unsigned int room = 4096;
>   	const struct nozomi *dc = get_dc_by_tty(tty);
>   
>   	if (dc)
> diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
> index 3e7b5c811f9b..eb8556b19592 100644
> --- a/drivers/tty/pty.c
> +++ b/drivers/tty/pty.c
> @@ -136,7 +136,7 @@ static int pty_write(struct tty_struct *tty, const unsigned char *buf, int c)
>    *	the other device.
>    */
>   
> -static int pty_write_room(struct tty_struct *tty)
> +static unsigned int pty_write_room(struct tty_struct *tty)
>   {
>   	if (tty->flow.stopped)
>   		return 0;
> diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
> index db059b66438e..b193bbc666d4 100644
> --- a/drivers/tty/serial/kgdb_nmi.c
> +++ b/drivers/tty/serial/kgdb_nmi.c
> @@ -298,7 +298,7 @@ static void kgdb_nmi_tty_hangup(struct tty_struct *tty)
>   	tty_port_hangup(&priv->port);
>   }
>   
> -static int kgdb_nmi_tty_write_room(struct tty_struct *tty)
> +static unsigned int kgdb_nmi_tty_write_room(struct tty_struct *tty)
>   {
>   	/* Actually, we can handle any amount as we use polled writes. */
>   	return 2048;
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index 87f7127b57e6..cb46a65a5dd8 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -616,12 +616,12 @@ static int uart_write(struct tty_struct *tty,
>   	return ret;
>   }
>   
> -static int uart_write_room(struct tty_struct *tty)
> +static unsigned int uart_write_room(struct tty_struct *tty)
>   {
>   	struct uart_state *state = tty->driver_data;
>   	struct uart_port *port;
>   	unsigned long flags;
> -	int ret;
> +	unsigned int ret;
>   
>   	port = uart_port_lock(state, flags);
>   	ret = uart_circ_chars_free(&state->xmit);
> diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
> index 1555dccc28af..583aa8342112 100644
> --- a/drivers/tty/synclink_gt.c
> +++ b/drivers/tty/synclink_gt.c
> @@ -868,15 +868,15 @@ static void wait_until_sent(struct tty_struct *tty, int timeout)
>   	DBGINFO(("%s wait_until_sent exit\n", info->device_name));
>   }
>   
> -static int write_room(struct tty_struct *tty)
> +static unsigned int write_room(struct tty_struct *tty)
>   {
>   	struct slgt_info *info = tty->driver_data;
> -	int ret;
> +	unsigned int ret;
>   
>   	if (sanity_check(info, tty->name, "write_room"))
>   		return 0;
>   	ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
> -	DBGINFO(("%s write_room=%d\n", info->device_name, ret));
> +	DBGINFO(("%s write_room=%u\n", info->device_name, ret));
>   	return ret;
>   }
>   
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index 07c88ccfb17a..d8834784b586 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -73,7 +73,7 @@ EXPORT_SYMBOL(tty_chars_in_buffer);
>    *	returned and data may be lost as there will be no flow control.
>    */
>    
> -int tty_write_room(struct tty_struct *tty)
> +unsigned int tty_write_room(struct tty_struct *tty)
>   {
>   	if (tty->ops->write_room)
>   		return tty->ops->write_room(tty);
> diff --git a/drivers/tty/ttynull.c b/drivers/tty/ttynull.c
> index 17f05b7eb6d3..af3311a24917 100644
> --- a/drivers/tty/ttynull.c
> +++ b/drivers/tty/ttynull.c
> @@ -35,7 +35,7 @@ static int ttynull_write(struct tty_struct *tty, const unsigned char *buf,
>   	return count;
>   }
>   
> -static int ttynull_write_room(struct tty_struct *tty)
> +static unsigned int ttynull_write_room(struct tty_struct *tty)
>   {
>   	return 65536;
>   }
> diff --git a/drivers/tty/vcc.c b/drivers/tty/vcc.c
> index 0a3a71e14df4..d82ce3bb82c3 100644
> --- a/drivers/tty/vcc.c
> +++ b/drivers/tty/vcc.c
> @@ -870,10 +870,10 @@ static int vcc_write(struct tty_struct *tty, const unsigned char *buf,
>   	return total_sent ? total_sent : rv;
>   }
>   
> -static int vcc_write_room(struct tty_struct *tty)
> +static unsigned int vcc_write_room(struct tty_struct *tty)
>   {
>   	struct vcc_port *port;
> -	u64 num;
> +	unsigned int num;
>   
>   	port = vcc_get_ne(tty->index);
>   	if (unlikely(!port)) {
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index 706f066eb711..96c130714930 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -3263,7 +3263,7 @@ static int con_put_char(struct tty_struct *tty, unsigned char ch)
>   	return do_con_write(tty, &ch, 1);
>   }
>   
> -static int con_write_room(struct tty_struct *tty)
> +static unsigned int con_write_room(struct tty_struct *tty)
>   {
>   	if (tty->flow.stopped)
>   		return 0;
> diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
> index ca7a61190dd9..76b7fd234238 100644
> --- a/drivers/usb/class/cdc-acm.c
> +++ b/drivers/usb/class/cdc-acm.c
> @@ -838,7 +838,7 @@ static int acm_tty_write(struct tty_struct *tty,
>   	return count;
>   }
>   
> -static int acm_tty_write_room(struct tty_struct *tty)
> +static unsigned int acm_tty_write_room(struct tty_struct *tty)
>   {
>   	struct acm *acm = tty->driver_data;
>   	/*
> diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
> index 1e59204ec7aa..676a920d9d6b 100644
> --- a/drivers/usb/gadget/function/u_serial.c
> +++ b/drivers/usb/gadget/function/u_serial.c
> @@ -774,18 +774,18 @@ static void gs_flush_chars(struct tty_struct *tty)
>   	spin_unlock_irqrestore(&port->port_lock, flags);
>   }
>   
> -static int gs_write_room(struct tty_struct *tty)
> +static unsigned int gs_write_room(struct tty_struct *tty)
>   {
>   	struct gs_port	*port = tty->driver_data;
>   	unsigned long	flags;
> -	int		room = 0;
> +	unsigned int room = 0;
>   
>   	spin_lock_irqsave(&port->port_lock, flags);
>   	if (port->port_usb)
>   		room = kfifo_avail(&port->port_write_buf);
>   	spin_unlock_irqrestore(&port->port_lock, flags);
>   
> -	pr_vdebug("gs_write_room: (%d,%p) room=%d\n",
> +	pr_vdebug("gs_write_room: (%d,%p) room=%u\n",
>   		port->port_num, tty, room);
>   
>   	return room;
> diff --git a/drivers/usb/host/xhci-dbgtty.c b/drivers/usb/host/xhci-dbgtty.c
> index ae4e4ab638b5..cd3ab35dd689 100644
> --- a/drivers/usb/host/xhci-dbgtty.c
> +++ b/drivers/usb/host/xhci-dbgtty.c
> @@ -240,11 +240,11 @@ static void dbc_tty_flush_chars(struct tty_struct *tty)
>   	spin_unlock_irqrestore(&port->port_lock, flags);
>   }
>   
> -static int dbc_tty_write_room(struct tty_struct *tty)
> +static unsigned int dbc_tty_write_room(struct tty_struct *tty)
>   {
>   	struct dbc_port		*port = tty->driver_data;
>   	unsigned long		flags;
> -	int			room = 0;
> +	unsigned int		room;
>   
>   	spin_lock_irqsave(&port->port_lock, flags);
>   	room = kfifo_avail(&port->write_fifo);
> diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
> index 98b33b1b5357..055096831daf 100644
> --- a/drivers/usb/serial/usb-serial.c
> +++ b/drivers/usb/serial/usb-serial.c
> @@ -376,7 +376,7 @@ static int serial_write(struct tty_struct *tty, const unsigned char *buf,
>   	return retval;
>   }
>   
> -static int serial_write_room(struct tty_struct *tty)
> +static unsigned int serial_write_room(struct tty_struct *tty)
>   {
>   	struct usb_serial_port *port = tty->driver_data;
>   
> diff --git a/include/linux/tty.h b/include/linux/tty.h
> index e18a4f1ac39d..d18fc34d3054 100644
> --- a/include/linux/tty.h
> +++ b/include/linux/tty.h
> @@ -459,7 +459,7 @@ extern void tty_write_message(struct tty_struct *tty, char *msg);
>   extern int tty_send_xchar(struct tty_struct *tty, char ch);
>   extern int tty_put_char(struct tty_struct *tty, unsigned char c);
>   extern int tty_chars_in_buffer(struct tty_struct *tty);
> -extern int tty_write_room(struct tty_struct *tty);
> +extern unsigned int tty_write_room(struct tty_struct *tty);
>   extern void tty_driver_flush_buffer(struct tty_struct *tty);
>   extern void tty_throttle(struct tty_struct *tty);
>   extern void tty_unthrottle(struct tty_struct *tty);
> diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
> index 653fa5af3a22..ea5b15c72764 100644
> --- a/include/linux/tty_driver.h
> +++ b/include/linux/tty_driver.h
> @@ -89,7 +89,7 @@
>    *
>    *	Note: Do not call this function directly, call tty_driver_flush_chars
>    *
> - * int  (*write_room)(struct tty_struct *tty);
> + * unsigned int  (*write_room)(struct tty_struct *tty);
>    *
>    * 	This routine returns the numbers of characters the tty driver
>    * 	will accept for queuing to be written.  This number is subject
> @@ -256,7 +256,7 @@ struct tty_operations {
>   		      const unsigned char *buf, int count);
>   	int  (*put_char)(struct tty_struct *tty, unsigned char ch);
>   	void (*flush_chars)(struct tty_struct *tty);
> -	int  (*write_room)(struct tty_struct *tty);
> +	unsigned int (*write_room)(struct tty_struct *tty);
>   	int  (*chars_in_buffer)(struct tty_struct *tty);
>   	int  (*ioctl)(struct tty_struct *tty,
>   		    unsigned int cmd, unsigned long arg);
> diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
> index a58584949a95..a5e3d957f20f 100644
> --- a/net/bluetooth/rfcomm/tty.c
> +++ b/net/bluetooth/rfcomm/tty.c
> @@ -807,7 +807,7 @@ static int rfcomm_tty_write(struct tty_struct *tty, const unsigned char *buf, in
>   	return sent;
>   }
>   
> -static int rfcomm_tty_write_room(struct tty_struct *tty)
> +static unsigned int rfcomm_tty_write_room(struct tty_struct *tty)
>   {
>   	struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
>   	int room = 0;
> 

Acked-By: Anton Ivanov <anton.ivanov@cambridgegreys.com>

-- 
Anton R. Ivanov
Cambridgegreys Limited. Registered in England. Company Number 10273661
https://www.cambridgegreys.com/

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

* Re: [PATCH 22/35] tty: make tty_operations::write_room return uint
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
  2021-05-05  9:25   ` Geert Uytterhoeven
  2021-05-05 10:34   ` Anton Ivanov
@ 2021-05-05 10:43   ` David Sterba
  2021-05-05 11:53   ` Max Filippov
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 71+ messages in thread
From: David Sterba @ 2021-05-05 10:43 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: gregkh, linux-serial, linux-kernel, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, Geert Uytterhoeven,
	James E.J. Bottomley, Helge Deller, Jeff Dike,
	Richard Weinberger, Anton Ivanov, Chris Zankel, Max Filippov,
	Arnd Bergmann, Samuel Iglesias Gonsalvez, Jens Taprogge,
	Karsten Keil, Scott Branden, Ulf Hansson, David S. Miller,
	Jakub Kicinski, Heiko Carstens, Vasily Gorbik,
	Christian Borntraeger, David Lin, Johan Hovold, Alex Elder,
	Laurentiu Tudor, Jiri Kosina, David Sterba, Shawn Guo,
	Sascha Hauer, Oliver Neukum, Felipe Balbi, Mathias Nyman,
	Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz

On Wed, May 05, 2021 at 11:19:15AM +0200, Jiri Slaby wrote:
> Line disciplines expect a positive value or zero returned from
> tty->ops->write_room (invoked by tty_write_room). So make this
> assumption explicit by using unsigned int as a return value. Both of
> tty->ops->write_room and tty_write_room.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> Cc: Jens Taprogge <jens.taprogge@taprogge.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Scott Branden <scott.branden@broadcom.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: David Sterba <dsterba@suse.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> ---
>  drivers/tty/ipwireless/tty.c           | 2 +-

Acked-by: David Sterba <dsterba@suse.com>

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

* Re: [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint
  2021-05-05  9:19 ` [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint Jiri Slaby
  2021-05-05 10:34   ` Anton Ivanov
@ 2021-05-05 10:43   ` David Sterba
  1 sibling, 0 replies; 71+ messages in thread
From: David Sterba @ 2021-05-05 10:43 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: gregkh, linux-serial, linux-kernel, Jeff Dike,
	Richard Weinberger, Anton Ivanov, Arnd Bergmann,
	Samuel Iglesias Gonsalvez, Jens Taprogge, Karsten Keil,
	Ulf Hansson, David S. Miller, Jakub Kicinski, Heiko Carstens,
	Vasily Gorbik, Christian Borntraeger, David Lin, Johan Hovold,
	Alex Elder, Jiri Kosina, David Sterba, Shawn Guo, Sascha Hauer,
	Oliver Neukum, Felipe Balbi, Mathias Nyman, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz

On Wed, May 05, 2021 at 11:19:19AM +0200, Jiri Slaby wrote:
> tty_operations::chars_in_buffer is another hook which is expected to
> return values >= 0. So make it explicit by the return type too -- use
> unsigned int.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> Cc: Jens Taprogge <jens.taprogge@taprogge.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: David Sterba <dsterba@suse.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> ---
>  drivers/tty/ipwireless/tty.c           |  2 +-

Acked-by: David Sterba <dsterba@suse.com>

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

* Re: [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering
  2021-05-05  9:19 ` [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering Jiri Slaby
@ 2021-05-05 11:51   ` Max Filippov
  2021-05-06  5:47   ` Jiri Slaby
  1 sibling, 0 replies; 71+ messages in thread
From: Max Filippov @ 2021-05-05 11:51 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Ivan Kokshaysky,
	Matt Turner, James E.J. Bottomley, Helge Deller, Chris Zankel,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger

On Wed, May 5, 2021 at 2:19 AM Jiri Slaby <jslaby@suse.cz> wrote:
>
> The only user of tty_ops::chars_in_buffer is tty_chars_in_buffer. And it
> considers tty_ops::chars_in_buffer optional. In case it's NULL, zero is
> returned. So remove all those chars_in_buffer from tty_ops which return
> zero. (Zero means such driver doesn't buffer.)
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> c: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>  arch/alpha/kernel/srmcons.c         |  7 -------
>  arch/parisc/kernel/pdc_cons.c       |  6 ------
>  arch/xtensa/platforms/iss/console.c |  7 -------
>  drivers/s390/char/tty3270.c         | 12 ------------
>  drivers/tty/pty.c                   | 17 -----------------
>  drivers/tty/vt/vt.c                 |  6 ------
>  6 files changed, 55 deletions(-)

Acked-by: Max Filippov <jcmvbkbc@gmail.com> # xtensa

-- 
Thanks.
-- Max

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

* Re: [PATCH 22/35] tty: make tty_operations::write_room return uint
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
                     ` (2 preceding siblings ...)
  2021-05-05 10:43   ` David Sterba
@ 2021-05-05 11:53   ` Max Filippov
  2021-05-05 12:15   ` Alex Elder
  2021-05-10 11:27   ` Laurentiu Tudor
  5 siblings, 0 replies; 71+ messages in thread
From: Max Filippov @ 2021-05-05 11:53 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: Greg Kroah-Hartman, linux-serial, LKML, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, Geert Uytterhoeven,
	James E.J. Bottomley, Helge Deller, Jeff Dike,
	Richard Weinberger, Anton Ivanov, Chris Zankel, Arnd Bergmann,
	Samuel Iglesias Gonsalvez, Jens Taprogge, Karsten Keil,
	Scott Branden, Ulf Hansson, David S. Miller, Jakub Kicinski,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger, David Lin,
	Johan Hovold, Alex Elder, Laurentiu Tudor, Jiri Kosina,
	David Sterba, Shawn Guo, Sascha Hauer, Oliver Neukum,
	Felipe Balbi, Mathias Nyman, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz

On Wed, May 5, 2021 at 2:19 AM Jiri Slaby <jslaby@suse.cz> wrote:
>
> Line disciplines expect a positive value or zero returned from
> tty->ops->write_room (invoked by tty_write_room). So make this
> assumption explicit by using unsigned int as a return value. Both of
> tty->ops->write_room and tty_write_room.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> Cc: Jens Taprogge <jens.taprogge@taprogge.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Scott Branden <scott.branden@broadcom.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: David Sterba <dsterba@suse.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> ---
>  arch/alpha/kernel/srmcons.c            | 2 +-
>  arch/m68k/emu/nfcon.c                  | 2 +-
>  arch/parisc/kernel/pdc_cons.c          | 2 +-
>  arch/um/drivers/line.c                 | 6 +++---
>  arch/um/drivers/line.h                 | 2 +-
>  arch/xtensa/platforms/iss/console.c    | 2 +-
>  drivers/char/pcmcia/synclink_cs.c      | 2 +-
>  drivers/char/ttyprintk.c               | 2 +-
>  drivers/ipack/devices/ipoctal.c        | 2 +-
>  drivers/isdn/capi/capi.c               | 6 +++---
>  drivers/misc/bcm-vk/bcm_vk_tty.c       | 2 +-
>  drivers/mmc/core/sdio_uart.c           | 2 +-
>  drivers/net/usb/hso.c                  | 4 ++--
>  drivers/s390/char/con3215.c            | 2 +-
>  drivers/s390/char/sclp_tty.c           | 4 ++--
>  drivers/s390/char/sclp_vt220.c         | 4 ++--
>  drivers/s390/char/tty3270.c            | 2 +-
>  drivers/staging/fwserial/fwserial.c    | 6 +++---
>  drivers/staging/gdm724x/gdm_tty.c      | 2 +-
>  drivers/staging/greybus/uart.c         | 2 +-
>  drivers/tty/amiserial.c                | 2 +-
>  drivers/tty/ehv_bytechan.c             | 4 ++--
>  drivers/tty/goldfish.c                 | 2 +-
>  drivers/tty/hvc/hvc_console.c          | 2 +-
>  drivers/tty/hvc/hvcs.c                 | 2 +-
>  drivers/tty/hvc/hvsi.c                 | 4 ++--
>  drivers/tty/ipwireless/tty.c           | 2 +-
>  drivers/tty/mips_ejtag_fdc.c           | 4 ++--
>  drivers/tty/moxa.c                     | 8 ++++----
>  drivers/tty/mxser.c                    | 2 +-
>  drivers/tty/n_gsm.c                    | 2 +-
>  drivers/tty/nozomi.c                   | 4 ++--
>  drivers/tty/pty.c                      | 2 +-
>  drivers/tty/serial/kgdb_nmi.c          | 2 +-
>  drivers/tty/serial/serial_core.c       | 4 ++--
>  drivers/tty/synclink_gt.c              | 6 +++---
>  drivers/tty/tty_ioctl.c                | 2 +-
>  drivers/tty/ttynull.c                  | 2 +-
>  drivers/tty/vcc.c                      | 4 ++--
>  drivers/tty/vt/vt.c                    | 2 +-
>  drivers/usb/class/cdc-acm.c            | 2 +-
>  drivers/usb/gadget/function/u_serial.c | 6 +++---
>  drivers/usb/host/xhci-dbgtty.c         | 4 ++--
>  drivers/usb/serial/usb-serial.c        | 2 +-
>  include/linux/tty.h                    | 2 +-
>  include/linux/tty_driver.h             | 4 ++--
>  net/bluetooth/rfcomm/tty.c             | 2 +-
>  47 files changed, 71 insertions(+), 71 deletions(-)

Acked-by: Max Filippov <jcmvbkbc@gmail.com> # xtensa

-- 
Thanks.
-- Max

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

* Re: [PATCH 22/35] tty: make tty_operations::write_room return uint
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
                     ` (3 preceding siblings ...)
  2021-05-05 11:53   ` Max Filippov
@ 2021-05-05 12:15   ` Alex Elder
  2021-05-10 11:27   ` Laurentiu Tudor
  5 siblings, 0 replies; 71+ messages in thread
From: Alex Elder @ 2021-05-05 12:15 UTC (permalink / raw)
  To: Jiri Slaby, gregkh
  Cc: linux-serial, linux-kernel, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, Geert Uytterhoeven, James E.J. Bottomley,
	Helge Deller, Jeff Dike, Richard Weinberger, Anton Ivanov,
	Chris Zankel, Max Filippov, Arnd Bergmann,
	Samuel Iglesias Gonsalvez, Jens Taprogge, Karsten Keil,
	Scott Branden, Ulf Hansson, David S. Miller, Jakub Kicinski,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger, David Lin,
	Johan Hovold, Alex Elder, Laurentiu Tudor, Jiri Kosina,
	David Sterba, Shawn Guo, Sascha Hauer, Oliver Neukum,
	Felipe Balbi, Mathias Nyman, Marcel Holtmann, Johan Hedberg,
	Luiz Augusto von Dentz

On 5/5/21 4:19 AM, Jiri Slaby wrote:
> Line disciplines expect a positive value or zero returned from
> tty->ops->write_room (invoked by tty_write_room). So make this
> assumption explicit by using unsigned int as a return value. Both of
> tty->ops->write_room and tty_write_room.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Richard Henderson <rth@twiddle.net>
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> Cc: Jens Taprogge <jens.taprogge@taprogge.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Scott Branden <scott.branden@broadcom.com>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: David Sterba <dsterba@suse.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Mathias Nyman <mathias.nyman@intel.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> ---
>   arch/alpha/kernel/srmcons.c            | 2 +-
>   arch/m68k/emu/nfcon.c                  | 2 +-
>   arch/parisc/kernel/pdc_cons.c          | 2 +-
>   arch/um/drivers/line.c                 | 6 +++---
>   arch/um/drivers/line.h                 | 2 +-
>   arch/xtensa/platforms/iss/console.c    | 2 +-
>   drivers/char/pcmcia/synclink_cs.c      | 2 +-
>   drivers/char/ttyprintk.c               | 2 +-
>   drivers/ipack/devices/ipoctal.c        | 2 +-
>   drivers/isdn/capi/capi.c               | 6 +++---
>   drivers/misc/bcm-vk/bcm_vk_tty.c       | 2 +-
>   drivers/mmc/core/sdio_uart.c           | 2 +-
>   drivers/net/usb/hso.c                  | 4 ++--
>   drivers/s390/char/con3215.c            | 2 +-
>   drivers/s390/char/sclp_tty.c           | 4 ++--
>   drivers/s390/char/sclp_vt220.c         | 4 ++--
>   drivers/s390/char/tty3270.c            | 2 +-
>   drivers/staging/fwserial/fwserial.c    | 6 +++---
>   drivers/staging/gdm724x/gdm_tty.c      | 2 +-
>   drivers/staging/greybus/uart.c         | 2 +-
>   drivers/tty/amiserial.c                | 2 +-
>   drivers/tty/ehv_bytechan.c             | 4 ++--
>   drivers/tty/goldfish.c                 | 2 +-
>   drivers/tty/hvc/hvc_console.c          | 2 +-
>   drivers/tty/hvc/hvcs.c                 | 2 +-
>   drivers/tty/hvc/hvsi.c                 | 4 ++--
>   drivers/tty/ipwireless/tty.c           | 2 +-
>   drivers/tty/mips_ejtag_fdc.c           | 4 ++--
>   drivers/tty/moxa.c                     | 8 ++++----
>   drivers/tty/mxser.c                    | 2 +-
>   drivers/tty/n_gsm.c                    | 2 +-
>   drivers/tty/nozomi.c                   | 4 ++--
>   drivers/tty/pty.c                      | 2 +-
>   drivers/tty/serial/kgdb_nmi.c          | 2 +-
>   drivers/tty/serial/serial_core.c       | 4 ++--
>   drivers/tty/synclink_gt.c              | 6 +++---
>   drivers/tty/tty_ioctl.c                | 2 +-
>   drivers/tty/ttynull.c                  | 2 +-
>   drivers/tty/vcc.c                      | 4 ++--
>   drivers/tty/vt/vt.c                    | 2 +-
>   drivers/usb/class/cdc-acm.c            | 2 +-
>   drivers/usb/gadget/function/u_serial.c | 6 +++---
>   drivers/usb/host/xhci-dbgtty.c         | 4 ++--
>   drivers/usb/serial/usb-serial.c        | 2 +-
>   include/linux/tty.h                    | 2 +-
>   include/linux/tty_driver.h             | 4 ++--
>   net/bluetooth/rfcomm/tty.c             | 2 +-
>   47 files changed, 71 insertions(+), 71 deletions(-)

. . .

Looks good.

Acked-by: Alex Elder <elder@linaro.org.

> diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
> index b1e63f7798b0..529eccb99b6c 100644
> --- a/drivers/staging/greybus/uart.c
> +++ b/drivers/staging/greybus/uart.c
> @@ -440,7 +440,7 @@ static int gb_tty_write(struct tty_struct *tty, const unsigned char *buf,
>   	return count;
>   }
>   
> -static int gb_tty_write_room(struct tty_struct *tty)
> +static unsigned int gb_tty_write_room(struct tty_struct *tty)
>   {
>   	struct gb_tty *gb_tty = tty->driver_data;
>   	unsigned long flags;

. . .


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

* Re: [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering
  2021-05-05  9:19 ` [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering Jiri Slaby
  2021-05-05 11:51   ` Max Filippov
@ 2021-05-06  5:47   ` Jiri Slaby
  2021-05-06  5:56     ` Greg KH
  1 sibling, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-06  5:47 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Ivan Kokshaysky, Matt Turner,
	James E.J. Bottomley, Helge Deller, Chris Zankel, Max Filippov,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Richard Henderson

On 05. 05. 21, 11:19, Jiri Slaby wrote:
> The only user of tty_ops::chars_in_buffer is tty_chars_in_buffer. And it
> considers tty_ops::chars_in_buffer optional. In case it's NULL, zero is
> returned. So remove all those chars_in_buffer from tty_ops which return
> zero. (Zero means such driver doesn't buffer.)
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>


> c: Richard Henderson <rth@twiddle.net>

Uh, "C" is a fugitive. Wanted dead or alive.

So should I send a v2 with:
Cc: Richard Henderson <rth@twiddle.net>
?

> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> ---
>   arch/alpha/kernel/srmcons.c         |  7 -------
>   arch/parisc/kernel/pdc_cons.c       |  6 ------
>   arch/xtensa/platforms/iss/console.c |  7 -------
>   drivers/s390/char/tty3270.c         | 12 ------------
>   drivers/tty/pty.c                   | 17 -----------------
>   drivers/tty/vt/vt.c                 |  6 ------
>   6 files changed, 55 deletions(-)
> 
> diff --git a/arch/alpha/kernel/srmcons.c b/arch/alpha/kernel/srmcons.c
> index 2110b7e7f988..fc03471a0b0f 100644
> --- a/arch/alpha/kernel/srmcons.c
> +++ b/arch/alpha/kernel/srmcons.c
> @@ -148,12 +148,6 @@ srmcons_write_room(struct tty_struct *tty)
>   	return 512;
>   }
>   
> -static int
> -srmcons_chars_in_buffer(struct tty_struct *tty)
> -{
> -	return 0;
> -}
> -
>   static int
>   srmcons_open(struct tty_struct *tty, struct file *filp)
>   {
> @@ -200,7 +194,6 @@ static const struct tty_operations srmcons_ops = {
>   	.close		= srmcons_close,
>   	.write		= srmcons_write,
>   	.write_room	= srmcons_write_room,
> -	.chars_in_buffer= srmcons_chars_in_buffer,
>   };
>   
>   static int __init
> diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c
> index fe2ed0bbd07e..39ccad063533 100644
> --- a/arch/parisc/kernel/pdc_cons.c
> +++ b/arch/parisc/kernel/pdc_cons.c
> @@ -108,17 +108,11 @@ static unsigned int pdc_console_tty_write_room(struct tty_struct *tty)
>   	return 32768; /* no limit, no buffer used */
>   }
>   
> -static int pdc_console_tty_chars_in_buffer(struct tty_struct *tty)
> -{
> -	return 0; /* no buffer */
> -}
> -
>   static const struct tty_operations pdc_console_tty_ops = {
>   	.open = pdc_console_tty_open,
>   	.close = pdc_console_tty_close,
>   	.write = pdc_console_tty_write,
>   	.write_room = pdc_console_tty_write_room,
> -	.chars_in_buffer = pdc_console_tty_chars_in_buffer,
>   };
>   
>   static void pdc_console_poll(struct timer_list *unused)
> diff --git a/arch/xtensa/platforms/iss/console.c b/arch/xtensa/platforms/iss/console.c
> index 98ac3a7fdb0a..21184488c277 100644
> --- a/arch/xtensa/platforms/iss/console.c
> +++ b/arch/xtensa/platforms/iss/console.c
> @@ -106,12 +106,6 @@ static unsigned int rs_write_room(struct tty_struct *tty)
>   	return 2 * 1024;
>   }
>   
> -static int rs_chars_in_buffer(struct tty_struct *tty)
> -{
> -	/* the iss doesn't buffer characters */
> -	return 0;
> -}
> -
>   static void rs_hangup(struct tty_struct *tty)
>   {
>   	/* Stub, once again.. */
> @@ -135,7 +129,6 @@ static const struct tty_operations serial_ops = {
>   	.put_char = rs_put_char,
>   	.flush_chars = rs_flush_chars,
>   	.write_room = rs_write_room,
> -	.chars_in_buffer = rs_chars_in_buffer,
>   	.hangup = rs_hangup,
>   	.wait_until_sent = rs_wait_until_sent,
>   	.proc_show = rs_proc_show,
> diff --git a/drivers/s390/char/tty3270.c b/drivers/s390/char/tty3270.c
> index 82d4c961ed06..ba1fbce63fee 100644
> --- a/drivers/s390/char/tty3270.c
> +++ b/drivers/s390/char/tty3270.c
> @@ -1756,17 +1756,6 @@ tty3270_flush_chars(struct tty_struct *tty)
>   	}
>   }
>   
> -/*
> - * Returns the number of characters in the output buffer. This is
> - * used in tty_wait_until_sent to wait until all characters have
> - * appeared on the screen.
> - */
> -static int
> -tty3270_chars_in_buffer(struct tty_struct *tty)
> -{
> -	return 0;
> -}
> -
>   static void
>   tty3270_flush_buffer(struct tty_struct *tty)
>   {
> @@ -1892,7 +1881,6 @@ static const struct tty_operations tty3270_ops = {
>   	.put_char = tty3270_put_char,
>   	.flush_chars = tty3270_flush_chars,
>   	.write_room = tty3270_write_room,
> -	.chars_in_buffer = tty3270_chars_in_buffer,
>   	.flush_buffer = tty3270_flush_buffer,
>   	.throttle = tty3270_throttle,
>   	.unthrottle = tty3270_unthrottle,
> diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
> index eb8556b19592..5ada7e9381eb 100644
> --- a/drivers/tty/pty.c
> +++ b/drivers/tty/pty.c
> @@ -143,19 +143,6 @@ static unsigned int pty_write_room(struct tty_struct *tty)
>   	return tty_buffer_space_avail(tty->link->port);
>   }
>   
> -/**
> - *	pty_chars_in_buffer	-	characters currently in our tx queue
> - *	@tty: our tty
> - *
> - *	Report how much we have in the transmit queue. As everything is
> - *	instantly at the other end this is easy to implement.
> - */
> -
> -static int pty_chars_in_buffer(struct tty_struct *tty)
> -{
> -	return 0;
> -}
> -
>   /* Set the lock flag on a pty */
>   static int pty_set_lock(struct tty_struct *tty, int __user *arg)
>   {
> @@ -525,7 +512,6 @@ static const struct tty_operations master_pty_ops_bsd = {
>   	.write = pty_write,
>   	.write_room = pty_write_room,
>   	.flush_buffer = pty_flush_buffer,
> -	.chars_in_buffer = pty_chars_in_buffer,
>   	.unthrottle = pty_unthrottle,
>   	.ioctl = pty_bsd_ioctl,
>   	.compat_ioctl = pty_bsd_compat_ioctl,
> @@ -541,7 +527,6 @@ static const struct tty_operations slave_pty_ops_bsd = {
>   	.write = pty_write,
>   	.write_room = pty_write_room,
>   	.flush_buffer = pty_flush_buffer,
> -	.chars_in_buffer = pty_chars_in_buffer,
>   	.unthrottle = pty_unthrottle,
>   	.set_termios = pty_set_termios,
>   	.cleanup = pty_cleanup,
> @@ -776,7 +761,6 @@ static const struct tty_operations ptm_unix98_ops = {
>   	.write = pty_write,
>   	.write_room = pty_write_room,
>   	.flush_buffer = pty_flush_buffer,
> -	.chars_in_buffer = pty_chars_in_buffer,
>   	.unthrottle = pty_unthrottle,
>   	.ioctl = pty_unix98_ioctl,
>   	.compat_ioctl = pty_unix98_compat_ioctl,
> @@ -794,7 +778,6 @@ static const struct tty_operations pty_unix98_ops = {
>   	.write = pty_write,
>   	.write_room = pty_write_room,
>   	.flush_buffer = pty_flush_buffer,
> -	.chars_in_buffer = pty_chars_in_buffer,
>   	.unthrottle = pty_unthrottle,
>   	.set_termios = pty_set_termios,
>   	.start = pty_start,
> diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
> index 96c130714930..b838f656f4cd 100644
> --- a/drivers/tty/vt/vt.c
> +++ b/drivers/tty/vt/vt.c
> @@ -3270,11 +3270,6 @@ static unsigned int con_write_room(struct tty_struct *tty)
>   	return 32768;		/* No limit, really; we're not buffering */
>   }
>   
> -static int con_chars_in_buffer(struct tty_struct *tty)
> -{
> -	return 0;		/* we're not buffering */
> -}
> -
>   /*
>    * con_throttle and con_unthrottle are only used for
>    * paste_selection(), which has to stuff in a large number of
> @@ -3521,7 +3516,6 @@ static const struct tty_operations con_ops = {
>   	.write_room = con_write_room,
>   	.put_char = con_put_char,
>   	.flush_chars = con_flush_chars,
> -	.chars_in_buffer = con_chars_in_buffer,
>   	.ioctl = vt_ioctl,
>   #ifdef CONFIG_COMPAT
>   	.compat_ioctl = vt_compat_ioctl,
> 


-- 
js
suse labs

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

* Re: [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering
  2021-05-06  5:47   ` Jiri Slaby
@ 2021-05-06  5:56     ` Greg KH
  0 siblings, 0 replies; 71+ messages in thread
From: Greg KH @ 2021-05-06  5:56 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: linux-serial, linux-kernel, Ivan Kokshaysky, Matt Turner,
	James E.J. Bottomley, Helge Deller, Chris Zankel, Max Filippov,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Richard Henderson

On Thu, May 06, 2021 at 07:47:04AM +0200, Jiri Slaby wrote:
> On 05. 05. 21, 11:19, Jiri Slaby wrote:
> > The only user of tty_ops::chars_in_buffer is tty_chars_in_buffer. And it
> > considers tty_ops::chars_in_buffer optional. In case it's NULL, zero is
> > returned. So remove all those chars_in_buffer from tty_ops which return
> > zero. (Zero means such driver doesn't buffer.)
> > 
> > Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> 
> 
> > c: Richard Henderson <rth@twiddle.net>
> 
> Uh, "C" is a fugitive. Wanted dead or alive.
> 
> So should I send a v2 with:
> Cc: Richard Henderson <rth@twiddle.net>
> ?

Nah, it should be fine, I can fix it up.

thanks,

greg k-h

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

* Re: [PATCH 34/35] tty: make tty_get_byte_size available
  2021-05-05  9:19 ` [PATCH 34/35] tty: make tty_get_byte_size available Jiri Slaby
@ 2021-05-06  7:16   ` Joe Perches
  2021-05-06  7:19     ` Jiri Slaby
       [not found]     ` <CAHp75Vfq6ABW7ukwaKmZOF2DszmuHD28S=wcLcFowvRdXTnWmg@mail.gmail.com>
  2021-05-10  7:00   ` [PATCH v2 " Jiri Slaby
  1 sibling, 2 replies; 71+ messages in thread
From: Joe Perches @ 2021-05-06  7:16 UTC (permalink / raw)
  To: Jiri Slaby, gregkh; +Cc: linux-serial, linux-kernel

On Wed, 2021-05-05 at 11:19 +0200, Jiri Slaby wrote:
> Many tty drivers contain code to compute bits count depending on termios
> cflags. So extract this code from serial core to a separate tty helper
> function called tty_get_byte_size.
[]
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
[]
> +/**
> + *	tty_get_byte_size	-	get size of a byte
> + *	@cflag: termios cflag value
> + *	@account_flags: account for start and stop bits, second stop bit (if
> + *			set), and parity (if set)
> + *
> + *	Get the size of a byte in bits depending on @cflag. Depending on
> + *	@account_flags parameter, the result also accounts start and stop bits,
> + *	the second stop bit, and parity bit.
> + */
> +unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
> +{
> +	unsigned char bits = account_flags ? 2 : 0;
> +
> +	/* byte size and parity */
> +	switch (cflag & CSIZE) {
> +	case CS5:
> +		bits += 5;
> +		break;
> +	case CS6:
> +		bits += 6;
> +		break;
> +	case CS7:
> +		bits += 7;
> +		break;
> +	case CS8:
> +	default:
> +		bits += 8;
> +		break;
> +	}
> +
> +	if (account_flags && (cflag & CSTOPB))
> +		bits++;
> +
> +	if (account_flags && (cflag & PARENB))
> +		bits++;
> +
> +	return bits;
> +}
> +EXPORT_SYMBOL_GPL(tty_get_byte_size);

Perhaps clearer not testing account_flags multiple times.

unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
{
	unsigned char bits;

	/* byte size and parity */
	switch (cflag & CSIZE) {
	case CS5:
		bits = 5;
		break;
	case CS6:
		bits = 6;
		break;
	case CS7:
		bits = 7;
		break;
	case CS8:
	default:
		bits = 8;
		break;
	}

	if (account_flags) {
		bits += 2;	/* start/stop bits */

		if (cflag & CSTOPB)
			bits++;

		if (cflag & PARENB)
			bits++;
	}

	return bits;
}



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

* Re: [PATCH 34/35] tty: make tty_get_byte_size available
  2021-05-06  7:16   ` Joe Perches
@ 2021-05-06  7:19     ` Jiri Slaby
       [not found]     ` <CAHp75Vfq6ABW7ukwaKmZOF2DszmuHD28S=wcLcFowvRdXTnWmg@mail.gmail.com>
  1 sibling, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-05-06  7:19 UTC (permalink / raw)
  To: Joe Perches, gregkh; +Cc: linux-serial, linux-kernel

On 06. 05. 21, 9:16, Joe Perches wrote:
> On Wed, 2021-05-05 at 11:19 +0200, Jiri Slaby wrote:
>> Many tty drivers contain code to compute bits count depending on termios
>> cflags. So extract this code from serial core to a separate tty helper
>> function called tty_get_byte_size.
> []
>> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> []
>> +/**
>> + *	tty_get_byte_size	-	get size of a byte
>> + *	@cflag: termios cflag value
>> + *	@account_flags: account for start and stop bits, second stop bit (if
>> + *			set), and parity (if set)
>> + *
>> + *	Get the size of a byte in bits depending on @cflag. Depending on
>> + *	@account_flags parameter, the result also accounts start and stop bits,
>> + *	the second stop bit, and parity bit.
>> + */
>> +unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
>> +{
>> +	unsigned char bits = account_flags ? 2 : 0;
>> +
>> +	/* byte size and parity */
>> +	switch (cflag & CSIZE) {
>> +	case CS5:
>> +		bits += 5;
>> +		break;
>> +	case CS6:
>> +		bits += 6;
>> +		break;
>> +	case CS7:
>> +		bits += 7;
>> +		break;
>> +	case CS8:
>> +	default:
>> +		bits += 8;
>> +		break;
>> +	}
>> +
>> +	if (account_flags && (cflag & CSTOPB))
>> +		bits++;
>> +
>> +	if (account_flags && (cflag & PARENB))
>> +		bits++;
>> +
>> +	return bits;
>> +}
>> +EXPORT_SYMBOL_GPL(tty_get_byte_size);
> 
> Perhaps clearer not testing account_flags multiple times.

Right. Originally, I had account_start_stop, account_stop, and 
account_parity parameters. But they were either all false or all true. 
So I unified them to account_flags, but the code remained overly complex.

> unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
> {
> 	unsigned char bits;
> 
> 	/* byte size and parity */
> 	switch (cflag & CSIZE) {
> 	case CS5:
> 		bits = 5;
> 		break;
> 	case CS6:
> 		bits = 6;
> 		break;
> 	case CS7:
> 		bits = 7;
> 		break;
> 	case CS8:
> 	default:
> 		bits = 8;
> 		break;
> 	}
> 
> 	if (account_flags) {
> 		bits += 2;	/* start/stop bits */
> 
> 		if (cflag & CSTOPB)
> 			bits++;
> 
> 		if (cflag & PARENB)
> 			bits++;
> 	}
> 
> 	return bits;
> }
> 
> 

thanks,
-- 
js
suse labs

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

* Re: [PATCH 34/35] tty: make tty_get_byte_size available
       [not found]     ` <CAHp75Vfq6ABW7ukwaKmZOF2DszmuHD28S=wcLcFowvRdXTnWmg@mail.gmail.com>
@ 2021-05-06  8:31       ` Jiri Slaby
  2021-05-06  9:33         ` Andy Shevchenko
  2021-05-06  8:35       ` Joe Perches
  1 sibling, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-06  8:31 UTC (permalink / raw)
  To: Andy Shevchenko, Joe Perches; +Cc: gregkh, linux-serial, linux-kernel

On 06. 05. 21, 10:24, Andy Shevchenko wrote:
> if (!account_flags)
>    return bits;
> 
> ?

So I have:

unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
{
         unsigned char bits;

         switch (cflag & CSIZE) {
         case CS5:
                 bits = 5;
                 break;
         case CS6:
                 bits = 6;
                 break;
         case CS7:
                 bits = 7;
                 break;
         case CS8:
         default:
                 bits = 8;
                 break;
         }

         if (!account_flags)
                 return bits;

         if (cflag & CSTOPB)
                 bits++;
         if (cflag & PARENB)
                 bits++;

         return bits + 2;
}

thanks,
-- 
js
suse labs

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

* Re: [PATCH 34/35] tty: make tty_get_byte_size available
       [not found]     ` <CAHp75Vfq6ABW7ukwaKmZOF2DszmuHD28S=wcLcFowvRdXTnWmg@mail.gmail.com>
  2021-05-06  8:31       ` Jiri Slaby
@ 2021-05-06  8:35       ` Joe Perches
  1 sibling, 0 replies; 71+ messages in thread
From: Joe Perches @ 2021-05-06  8:35 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Jiri Slaby, gregkh, linux-serial, linux-kernel

On Thu, 2021-05-06 at 11:24 +0300, Andy Shevchenko wrote:
> On Thursday, May 6, 2021, Joe Perches <joe@perches.com> wrote:
[]
> > Perhaps clearer not testing account_flags multiple times.
> > 
> > unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
> > {
> >         unsigned char bits;
> > 
> >         /* byte size and parity */

nit:  byte size, the parity bit is tested later.

> >         switch (cflag & CSIZE) {
> >         case CS5:
> >                 bits = 5;
> >                 break;
> >         case CS6:
> >                 bits = 6;
> >                 break;
> >         case CS7:
> >                 bits = 7;
> >                 break;
> >         case CS8:
> >         default:
> >                 bits = 8;
> >                 break;
> >         }
> > 
> >         if (account_flags) {
> 
> 
> 
> if (!account_flags)
>   return bits;
> 
> ?

<shrug> six vs half dozen: 2 level indentation vs early return.

I don't think 2 level indentation is too many.

> >                 bits += 2;      /* start/stop bits */
> > 
> >                 if (cflag & CSTOPB)
> >                         bits++;
> > 
> >                 if (cflag & PARENB)
> >                         bits++;
> >         }

Maybe comment each test as CSTOPB and PARENB aren't completely obvious.


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

* Re: [PATCH 34/35] tty: make tty_get_byte_size available
  2021-05-06  8:31       ` Jiri Slaby
@ 2021-05-06  9:33         ` Andy Shevchenko
  0 siblings, 0 replies; 71+ messages in thread
From: Andy Shevchenko @ 2021-05-06  9:33 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Joe Perches, gregkh, linux-serial, linux-kernel

On Thu, May 6, 2021 at 11:31 AM Jiri Slaby <jirislaby@kernel.org> wrote:
>
> On 06. 05. 21, 10:24, Andy Shevchenko wrote:
> > if (!account_flags)
> >    return bits;
> >
> > ?
>
> So I have:


Good to me, feel free to add
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
to this variant.

> unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
> {
>          unsigned char bits;
>
>          switch (cflag & CSIZE) {
>          case CS5:
>                  bits = 5;
>                  break;
>          case CS6:
>                  bits = 6;
>                  break;
>          case CS7:
>                  bits = 7;
>                  break;
>          case CS8:
>          default:
>                  bits = 8;
>                  break;
>          }
>
>          if (!account_flags)
>                  return bits;
>
>          if (cflag & CSTOPB)
>                  bits++;
>          if (cflag & PARENB)
>                  bits++;
>
>          return bits + 2;
> }
>
> thanks,
> --
> js
> suse labs



-- 
With Best Regards,
Andy Shevchenko

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

* [PATCH v2 34/35] tty: make tty_get_byte_size available
  2021-05-05  9:19 ` [PATCH 34/35] tty: make tty_get_byte_size available Jiri Slaby
  2021-05-06  7:16   ` Joe Perches
@ 2021-05-10  7:00   ` Jiri Slaby
  2021-05-10  9:47     ` Johan Hovold
  1 sibling, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-10  7:00 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Andy Shevchenko, Joe Perches

Many tty drivers contain code to compute bits count depending on termios
cflags. So extract this code from serial core to a separate tty helper
function called tty_get_byte_size.

In the next patch, call to this new function will replace many copies of
this code.

[v2] simplified the code flow as suggested by Joe and Andy

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Joe Perches <joe@perches.com>
---
 drivers/tty/serial/serial_core.c | 30 +++--------------------
 drivers/tty/tty_ioctl.c          | 42 ++++++++++++++++++++++++++++++++
 include/linux/tty.h              |  2 ++
 3 files changed, 47 insertions(+), 27 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index d29329eb52f4..b3fc2b02a705 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -334,39 +334,15 @@ void
 uart_update_timeout(struct uart_port *port, unsigned int cflag,
 		    unsigned int baud)
 {
-	unsigned int bits;
+	unsigned int size;
 
-	/* byte size and parity */
-	switch (cflag & CSIZE) {
-	case CS5:
-		bits = 7;
-		break;
-	case CS6:
-		bits = 8;
-		break;
-	case CS7:
-		bits = 9;
-		break;
-	default:
-		bits = 10;
-		break; /* CS8 */
-	}
-
-	if (cflag & CSTOPB)
-		bits++;
-	if (cflag & PARENB)
-		bits++;
-
-	/*
-	 * The total number of bits to be transmitted in the fifo.
-	 */
-	bits = bits * port->fifosize;
+	size = tty_get_byte_size(cflag, true) * port->fifosize;
 
 	/*
 	 * Figure the timeout to send the above number of bits.
 	 * Add .02 seconds of slop
 	 */
-	port->timeout = (HZ * bits) / baud + HZ/50;
+	port->timeout = (HZ * size) / baud + HZ/50;
 }
 
 EXPORT_SYMBOL(uart_update_timeout);
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index aa9ecc8be990..13acc3decd87 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -300,6 +300,48 @@ int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
 }
 EXPORT_SYMBOL(tty_termios_hw_change);
 
+/**
+ *	tty_get_byte_size	-	get size of a byte
+ *	@cflag: termios cflag value
+ *	@account_flags: account for start and stop bits, second stop bit (if
+ *			set), and parity (if set)
+ *
+ *	Get the size of a byte in bits depending on @cflag. Depending on
+ *	@account_flags parameter, the result also accounts start and stop bits,
+ *	the second stop bit, and parity bit.
+ */
+unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
+{
+	unsigned char bits;
+
+	switch (cflag & CSIZE) {
+	case CS5:
+		bits = 5;
+		break;
+	case CS6:
+		bits = 6;
+		break;
+	case CS7:
+		bits = 7;
+		break;
+	case CS8:
+	default:
+		bits = 8;
+		break;
+	}
+
+	if (!account_flags)
+		return bits;
+
+	if (cflag & CSTOPB)
+		bits++;
+	if (cflag & PARENB)
+		bits++;
+
+	return bits + 2;
+}
+EXPORT_SYMBOL_GPL(tty_get_byte_size);
+
 /**
  *	tty_set_termios		-	update termios values
  *	@tty: tty to update
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 5cf6b2e7331b..a14b4588368c 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -496,6 +496,8 @@ static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
 	return tty_termios_baud_rate(&tty->termios);
 }
 
+unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags);
+
 extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
 extern int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
 extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
-- 
2.31.1


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

* Re: [PATCH v2 34/35] tty: make tty_get_byte_size available
  2021-05-10  7:00   ` [PATCH v2 " Jiri Slaby
@ 2021-05-10  9:47     ` Johan Hovold
  2021-05-13  7:24       ` Jiri Slaby
  0 siblings, 1 reply; 71+ messages in thread
From: Johan Hovold @ 2021-05-10  9:47 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: gregkh, linux-serial, linux-kernel, Andy Shevchenko, Joe Perches

On Mon, May 10, 2021 at 09:00:54AM +0200, Jiri Slaby wrote:
> Many tty drivers contain code to compute bits count depending on termios
> cflags. So extract this code from serial core to a separate tty helper
> function called tty_get_byte_size.
> 
> In the next patch, call to this new function will replace many copies of
> this code.
> 
> [v2] simplified the code flow as suggested by Joe and Andy
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Cc: Joe Perches <joe@perches.com>
> ---
>  drivers/tty/serial/serial_core.c | 30 +++--------------------
>  drivers/tty/tty_ioctl.c          | 42 ++++++++++++++++++++++++++++++++
>  include/linux/tty.h              |  2 ++
>  3 files changed, 47 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
> index d29329eb52f4..b3fc2b02a705 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -334,39 +334,15 @@ void
>  uart_update_timeout(struct uart_port *port, unsigned int cflag,
>  		    unsigned int baud)
>  {
> -	unsigned int bits;
> +	unsigned int size;
>  
> -	/* byte size and parity */
> -	switch (cflag & CSIZE) {
> -	case CS5:
> -		bits = 7;
> -		break;
> -	case CS6:
> -		bits = 8;
> -		break;
> -	case CS7:
> -		bits = 9;
> -		break;
> -	default:
> -		bits = 10;
> -		break; /* CS8 */
> -	}
> -
> -	if (cflag & CSTOPB)
> -		bits++;
> -	if (cflag & PARENB)
> -		bits++;
> -
> -	/*
> -	 * The total number of bits to be transmitted in the fifo.
> -	 */
> -	bits = bits * port->fifosize;
> +	size = tty_get_byte_size(cflag, true) * port->fifosize;
>
>  	/*
>  	 * Figure the timeout to send the above number of bits.
>  	 * Add .02 seconds of slop
>  	 */
> -	port->timeout = (HZ * bits) / baud + HZ/50;
> +	port->timeout = (HZ * size) / baud + HZ/50;
>  }
>  
>  EXPORT_SYMBOL(uart_update_timeout);
> diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
> index aa9ecc8be990..13acc3decd87 100644
> --- a/drivers/tty/tty_ioctl.c
> +++ b/drivers/tty/tty_ioctl.c
> @@ -300,6 +300,48 @@ int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
>  }
>  EXPORT_SYMBOL(tty_termios_hw_change);
>  
> +/**
> + *	tty_get_byte_size	-	get size of a byte
> + *	@cflag: termios cflag value
> + *	@account_flags: account for start and stop bits, second stop bit (if
> + *			set), and parity (if set)
> + *
> + *	Get the size of a byte in bits depending on @cflag. Depending on
> + *	@account_flags parameter, the result also accounts start and stop bits,
> + *	the second stop bit, and parity bit.
> + */
> +unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
> +{
> +	unsigned char bits;
> +
> +	switch (cflag & CSIZE) {
> +	case CS5:
> +		bits = 5;
> +		break;
> +	case CS6:
> +		bits = 6;
> +		break;
> +	case CS7:
> +		bits = 7;
> +		break;
> +	case CS8:
> +	default:
> +		bits = 8;
> +		break;
> +	}
> +
> +	if (!account_flags)
> +		return bits;
> +
> +	if (cflag & CSTOPB)
> +		bits++;
> +	if (cflag & PARENB)
> +		bits++;
> +
> +	return bits + 2;
> +}
> +EXPORT_SYMBOL_GPL(tty_get_byte_size);

This should really be two functions rather than passing a bool argument.

I think naming them

	tty_get_word_size()

and

	tty_get_frame_size()

would be much more clear than than "byte size" + flag.

I realise that the serial-driver interface only uses a cflag argument,
but I think we should consider passing a pointer to the termios
structure instead.

Johan

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

* Re: [PATCH 35/35] tty: make use of tty_get_byte_size
  2021-05-05  9:19 ` [PATCH 35/35] tty: make use of tty_get_byte_size Jiri Slaby
@ 2021-05-10  9:59   ` Johan Hovold
  0 siblings, 0 replies; 71+ messages in thread
From: Johan Hovold @ 2021-05-10  9:59 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: gregkh, linux-serial, linux-kernel, Arnd Bergmann, David Lin,
	Alex Elder, Shawn Guo, Sascha Hauer, Andy Gross, Bjorn Andersson,
	Maxime Coquelin, Alexandre Torgue, Oliver Neukum

On Wed, May 05, 2021 at 11:19:28AM +0200, Jiri Slaby wrote:
> In the previous patch, we introduced tty_get_byte_size for computing
> byte size. Here, we make use of it in various tty drivers.
> 
> The stats look nice: 16 insertions, 203 deletions.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Andy Gross <agross@kernel.org>
> Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
> Cc: Oliver Neukum <oneukum@suse.com>
> ---
>  drivers/char/pcmcia/synclink_cs.c           |  8 +-----
>  drivers/staging/greybus/uart.c              | 16 +----------
>  drivers/tty/serial/cpm_uart/cpm_uart_core.c | 19 +-----------
>  drivers/tty/serial/mxs-auart.c              | 18 +-----------
>  drivers/tty/serial/qcom_geni_serial.c       | 16 +----------
>  drivers/tty/serial/sh-sci.c                 | 20 +------------
>  drivers/tty/serial/stm32-usart.c            | 32 +--------------------
>  drivers/tty/synclink_gt.c                   |  9 +-----
>  drivers/usb/class/cdc-acm.c                 | 17 ++---------
>  drivers/usb/serial/belkin_sa.c              | 21 ++------------
>  drivers/usb/serial/cypress_m8.c             | 19 ++----------
>  drivers/usb/serial/pl2303.c                 | 15 +---------
>  drivers/usb/serial/whiteheat.c              |  9 +-----
>  13 files changed, 16 insertions(+), 203 deletions(-)

> diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
> index f414d6acad69..a5cbd7324268 100644
> --- a/drivers/tty/serial/mxs-auart.c
> +++ b/drivers/tty/serial/mxs-auart.c
> @@ -971,23 +971,7 @@ static void mxs_auart_settermios(struct uart_port *u,
>  	ctrl2 = mxs_read(s, REG_CTRL2);
>  
>  	/* byte size */
> -	switch (cflag & CSIZE) {
> -	case CS5:
> -		bm = 0;
> -		break;
> -	case CS6:
> -		bm = 1;
> -		break;
> -	case CS7:
> -		bm = 2;
> -		break;
> -	case CS8:
> -		bm = 3;
> -		break;
> -	default:
> -		return;
> -	}
> -
> +	bm = tty_get_byte_size(cflag, false) - 5;

This looks weird. The 0..3 constants are really "magic constants"
representing the different word sizes. Subtracting an offset obfuscates
this. Perhaps better left unchanged or add an appropriately names define
for the offset to make it clear what is going on here.

> diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
> index 1dca04e1519d..b135ed1ee512 100644
> --- a/drivers/usb/serial/cypress_m8.c
> +++ b/drivers/usb/serial/cypress_m8.c
> @@ -887,23 +887,8 @@ static void cypress_set_termios(struct tty_struct *tty,
>  	} else
>  		parity_enable = parity_type = 0;
>  
> -	switch (cflag & CSIZE) {
> -	case CS5:
> -		data_bits = 0;
> -		break;
> -	case CS6:
> -		data_bits = 1;
> -		break;
> -	case CS7:
> -		data_bits = 2;
> -		break;
> -	case CS8:
> -		data_bits = 3;
> -		break;
> -	default:
> -		dev_err(dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__);
> -		data_bits = 3;
> -	}
> +	data_bits = tty_get_byte_size(cflag, false) - 5;
> +

Same here.

>  	spin_lock_irqsave(&priv->lock, flags);
>  	oldlines = priv->line_control;
>  	if ((cflag & CBAUD) == B0) {
> diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
> index fd773d252691..76e4d90a9d43 100644
> --- a/drivers/usb/serial/pl2303.c
> +++ b/drivers/usb/serial/pl2303.c
> @@ -788,20 +788,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
>  
>  	pl2303_get_line_request(port, buf);
>  
> -	switch (C_CSIZE(tty)) {
> -	case CS5:
> -		buf[6] = 5;
> -		break;
> -	case CS6:
> -		buf[6] = 6;
> -		break;
> -	case CS7:
> -		buf[6] = 7;
> -		break;
> -	default:
> -	case CS8:
> -		buf[6] = 8;
> -	}
> +	buf[6] = tty_get_byte_size(C_CSIZE(tty), false);

Passing tty->termios would be better, but either way no need to mask off
the non CSIZE bits here.

Johan

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

* Re: [PATCH 22/35] tty: make tty_operations::write_room return uint
  2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
                     ` (4 preceding siblings ...)
  2021-05-05 12:15   ` Alex Elder
@ 2021-05-10 11:27   ` Laurentiu Tudor
  5 siblings, 0 replies; 71+ messages in thread
From: Laurentiu Tudor @ 2021-05-10 11:27 UTC (permalink / raw)
  To: Jiri Slaby, gregkh
  Cc: linux-serial, linux-kernel, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, Geert Uytterhoeven, James E.J. Bottomley,
	Helge Deller, Jeff Dike, Richard Weinberger, Anton Ivanov,
	Chris Zankel, Max Filippov, Arnd Bergmann,
	Samuel Iglesias Gonsalvez, Jens Taprogge, Karsten Keil,
	Scott Branden, Ulf Hansson, David S. Miller, Jakub Kicinski,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger, David Lin,
	Johan Hovold, Alex Elder, Jiri Kosina, David Sterba, Shawn Guo,
	Sascha Hauer, Oliver Neukum, Felipe Balbi, Mathias Nyman,
	Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz



On 5/5/2021 12:19 PM, Jiri Slaby wrote:
> Line disciplines expect a positive value or zero returned from
> tty->ops->write_room (invoked by tty_write_room). So make this
> assumption explicit by using unsigned int as a return value. Both of
> tty->ops->write_room and tty_write_room.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>

>  drivers/tty/ehv_bytechan.c             | 4 ++--

Acked-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>

---
Best Regards, Laurentiu

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

* Re: [PATCH v2 34/35] tty: make tty_get_byte_size available
  2021-05-10  9:47     ` Johan Hovold
@ 2021-05-13  7:24       ` Jiri Slaby
  2021-05-13  9:41         ` Johan Hovold
  0 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-05-13  7:24 UTC (permalink / raw)
  To: Johan Hovold
  Cc: gregkh, linux-serial, linux-kernel, Andy Shevchenko, Joe Perches

On 10. 05. 21, 11:47, Johan Hovold wrote:
>> --- a/drivers/tty/tty_ioctl.c
>> +++ b/drivers/tty/tty_ioctl.c
>> @@ -300,6 +300,48 @@ int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
...
>> +unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
>> +{
>> +	unsigned char bits;
>> +
>> +	switch (cflag & CSIZE) {
>> +	case CS5:
>> +		bits = 5;
>> +		break;
>> +	case CS6:
>> +		bits = 6;
>> +		break;
>> +	case CS7:
>> +		bits = 7;
>> +		break;
>> +	case CS8:
>> +	default:
>> +		bits = 8;
>> +		break;
>> +	}
>> +
>> +	if (!account_flags)
>> +		return bits;
>> +
>> +	if (cflag & CSTOPB)
>> +		bits++;
>> +	if (cflag & PARENB)
>> +		bits++;
>> +
>> +	return bits + 2;
>> +}
>> +EXPORT_SYMBOL_GPL(tty_get_byte_size);
> 
> This should really be two functions rather than passing a bool argument.
> 
> I think naming them
> 
> 	tty_get_word_size()
> 
> and
> 
> 	tty_get_frame_size()
> 
> would be much more clear than than "byte size" + flag.

Maybe I am screwed, but word means exactly 2B here. So instead, I would 
go for:
s/word/char/ -- might be confused with C's char, 1B, or maybe not -- or
s/word/data/ -- more generic and generally used in serial terminology.

> I realise that the serial-driver interface only uses a cflag argument,
> but I think we should consider passing a pointer to the termios
> structure instead.

That's impossible as termios is not always at hand. Examples are:
pch_uart_startup -> uart_update_timeout
sunsab_console_setup -> sunsab_convert_to_sab -> uart_update_timeout
sunsu_kbd_ms_init -> sunsu_change_speed -> uart_update_timeout

Let me document that in the commit.

thanks,
-- 
js
suse labs

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

* Re: [PATCH v2 34/35] tty: make tty_get_byte_size available
  2021-05-13  7:24       ` Jiri Slaby
@ 2021-05-13  9:41         ` Johan Hovold
  0 siblings, 0 replies; 71+ messages in thread
From: Johan Hovold @ 2021-05-13  9:41 UTC (permalink / raw)
  To: Jiri Slaby
  Cc: gregkh, linux-serial, linux-kernel, Andy Shevchenko, Joe Perches

On Thu, May 13, 2021 at 09:24:03AM +0200, Jiri Slaby wrote:
> On 10. 05. 21, 11:47, Johan Hovold wrote:
> >> --- a/drivers/tty/tty_ioctl.c
> >> +++ b/drivers/tty/tty_ioctl.c
> >> @@ -300,6 +300,48 @@ int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
> ...
> >> +unsigned char tty_get_byte_size(unsigned int cflag, bool account_flags)
> >> +{
> >> +	unsigned char bits;
> >> +
> >> +	switch (cflag & CSIZE) {
> >> +	case CS5:
> >> +		bits = 5;
> >> +		break;
> >> +	case CS6:
> >> +		bits = 6;
> >> +		break;
> >> +	case CS7:
> >> +		bits = 7;
> >> +		break;
> >> +	case CS8:
> >> +	default:
> >> +		bits = 8;
> >> +		break;
> >> +	}
> >> +
> >> +	if (!account_flags)
> >> +		return bits;
> >> +
> >> +	if (cflag & CSTOPB)
> >> +		bits++;
> >> +	if (cflag & PARENB)
> >> +		bits++;
> >> +
> >> +	return bits + 2;
> >> +}
> >> +EXPORT_SYMBOL_GPL(tty_get_byte_size);
> > 
> > This should really be two functions rather than passing a bool argument.
> > 
> > I think naming them
> > 
> > 	tty_get_word_size()
> > 
> > and
> > 
> > 	tty_get_frame_size()
> > 
> > would be much more clear than than "byte size" + flag.
> 
> Maybe I am screwed, but word means exactly 2B here.

No, not in this context.

Some UART datasheets use "word" and "word length", while others use
"character length" or "data bits" (and variations thereof).

> So instead, I would 
> go for:
> s/word/char/ -- might be confused with C's char, 1B, or maybe not -- or
> s/word/data/ -- more generic and generally used in serial terminology.

But "data size" it not very precise.

I'd go for either

	tty_get_word_size() or tty_get_char_size(), and
	tty_get_frame_size()

or possibly

	tty_get_data_bits(), and
	tty_get_frame_bits()

Since posix and the termios interface use "CSIZE" (even if that "C" is
ambiguous) and our man pages use "character size" perhaps we should
stick with that and use:

	tty_get_char_size(), and
	tty_get_frame_size()

That should be clear enough for everyone.

> > I realise that the serial-driver interface only uses a cflag argument,
> > but I think we should consider passing a pointer to the termios
> > structure instead.
> 
> That's impossible as termios is not always at hand. Examples are:
> pch_uart_startup -> uart_update_timeout
> sunsab_console_setup -> sunsab_convert_to_sab -> uart_update_timeout
> sunsu_kbd_ms_init -> sunsu_change_speed -> uart_update_timeout
> 
> Let me document that in the commit.

Sounds good.

Johan

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

* Re: [PATCH 00/35] tty cleanup for 5.14
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (34 preceding siblings ...)
  2021-05-05  9:19 ` [PATCH 35/35] tty: make use of tty_get_byte_size Jiri Slaby
@ 2021-05-13 15:04 ` Greg KH
  2021-05-13 16:20   ` Johan Hovold
  2021-06-10  9:02 ` [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available Jiri Slaby
  36 siblings, 1 reply; 71+ messages in thread
From: Greg KH @ 2021-05-13 15:04 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: linux-serial, linux-kernel

On Wed, May 05, 2021 at 11:18:53AM +0200, Jiri Slaby wrote:
> Hi,
> 
> this is again a series of various TTY cleanups. The stats say: 116 files
> changed, 661 insertions, 2602 deletions. The major part of the removal
> is a drop of BROKEN r3964 ldisc. The rest is mostly removal of dead
> code, or adaption to the current tty core state.

I've applied the first 33 patches in this series.  Can you resend the
last two after you have revised them based on the review?

thanks,

greg k-h

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

* Re: [PATCH 00/35] tty cleanup for 5.14
  2021-05-13 15:04 ` [PATCH 00/35] tty cleanup for 5.14 Greg KH
@ 2021-05-13 16:20   ` Johan Hovold
  2021-05-13 16:29     ` Greg KH
  0 siblings, 1 reply; 71+ messages in thread
From: Johan Hovold @ 2021-05-13 16:20 UTC (permalink / raw)
  To: Greg KH; +Cc: Jiri Slaby, linux-serial, linux-kernel

On Thu, May 13, 2021 at 05:04:41PM +0200, Greg Kroah-Hartman wrote:
> On Wed, May 05, 2021 at 11:18:53AM +0200, Jiri Slaby wrote:
> > Hi,
> > 
> > this is again a series of various TTY cleanups. The stats say: 116 files
> > changed, 661 insertions, 2602 deletions. The major part of the removal
> > is a drop of BROKEN r3964 ldisc. The rest is mostly removal of dead
> > code, or adaption to the current tty core state.
> 
> I've applied the first 33 patches in this series.  Can you resend the
> last two after you have revised them based on the review?

Greg, could you consider dropping the three USB-serial patches from
tty-testing? They don't have any dependency on the tty changes and we
can avoid unnecessary merge conflicts if I take them through through my
tree instead.

	USB: serial: make usb_serial_driver::write_room return uint
	serial: make usb_serial_driver::chars_in_buffer return uint
	USB: serial: digi_acceleport, simplify digi_chars_in_buffer

Johan

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

* Re: [PATCH 00/35] tty cleanup for 5.14
  2021-05-13 16:20   ` Johan Hovold
@ 2021-05-13 16:29     ` Greg KH
  2021-05-14  8:11       ` Johan Hovold
  0 siblings, 1 reply; 71+ messages in thread
From: Greg KH @ 2021-05-13 16:29 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Jiri Slaby, linux-serial, linux-kernel

On Thu, May 13, 2021 at 06:20:26PM +0200, Johan Hovold wrote:
> On Thu, May 13, 2021 at 05:04:41PM +0200, Greg Kroah-Hartman wrote:
> > On Wed, May 05, 2021 at 11:18:53AM +0200, Jiri Slaby wrote:
> > > Hi,
> > > 
> > > this is again a series of various TTY cleanups. The stats say: 116 files
> > > changed, 661 insertions, 2602 deletions. The major part of the removal
> > > is a drop of BROKEN r3964 ldisc. The rest is mostly removal of dead
> > > code, or adaption to the current tty core state.
> > 
> > I've applied the first 33 patches in this series.  Can you resend the
> > last two after you have revised them based on the review?
> 
> Greg, could you consider dropping the three USB-serial patches from
> tty-testing? They don't have any dependency on the tty changes and we
> can avoid unnecessary merge conflicts if I take them through through my
> tree instead.
> 
> 	USB: serial: make usb_serial_driver::write_room return uint
> 	serial: make usb_serial_driver::chars_in_buffer return uint
> 	USB: serial: digi_acceleport, simplify digi_chars_in_buffer

Sure, I've dropped them from my tree now and pushed out a rebased branch
for 0-day to run on.

thanks,

greg k-h

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

* Re: [PATCH 00/35] tty cleanup for 5.14
  2021-05-13 16:29     ` Greg KH
@ 2021-05-14  8:11       ` Johan Hovold
  0 siblings, 0 replies; 71+ messages in thread
From: Johan Hovold @ 2021-05-14  8:11 UTC (permalink / raw)
  To: Greg KH; +Cc: Jiri Slaby, linux-serial, linux-kernel

On Thu, May 13, 2021 at 06:29:51PM +0200, Greg Kroah-Hartman wrote:
> On Thu, May 13, 2021 at 06:20:26PM +0200, Johan Hovold wrote:

> > Greg, could you consider dropping the three USB-serial patches from
> > tty-testing? They don't have any dependency on the tty changes and we
> > can avoid unnecessary merge conflicts if I take them through through my
> > tree instead.
> > 
> > 	USB: serial: make usb_serial_driver::write_room return uint
> > 	serial: make usb_serial_driver::chars_in_buffer return uint
> > 	USB: serial: digi_acceleport, simplify digi_chars_in_buffer
> 
> Sure, I've dropped them from my tree now and pushed out a rebased branch
> for 0-day to run on.

Thanks, I'll queue them up next week.

Johan

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

* Re: [PATCH 23/35] USB: serial: make usb_serial_driver::write_room return uint
  2021-05-05  9:19 ` [PATCH 23/35] USB: serial: make usb_serial_driver::write_room " Jiri Slaby
@ 2021-05-19  9:07   ` Johan Hovold
  0 siblings, 0 replies; 71+ messages in thread
From: Johan Hovold @ 2021-05-19  9:07 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: gregkh, linux-serial, linux-kernel, linux-usb

On Wed, May 05, 2021 at 11:19:16AM +0200, Jiri Slaby wrote:
> Line disciplines expect a positive value or zero returned from
> tty->ops->write_room (invoked by tty_write_room). Both of them were
> switched in the previous patch. So now, switch also
> usb_serial_driver::write_room and all its users.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: linux-usb@vger.kernel.org
> ---
>  drivers/usb/serial/cyberjack.c        | 4 ++--
>  drivers/usb/serial/cypress_m8.c       | 8 ++++----
>  drivers/usb/serial/digi_acceleport.c  | 8 ++++----
>  drivers/usb/serial/garmin_gps.c       | 2 +-
>  drivers/usb/serial/generic.c          | 6 +++---
>  drivers/usb/serial/io_edgeport.c      | 6 +++---
>  drivers/usb/serial/io_ti.c            | 6 +++---
>  drivers/usb/serial/ir-usb.c           | 6 +++---
>  drivers/usb/serial/keyspan.c          | 4 ++--
>  drivers/usb/serial/kobil_sct.c        | 4 ++--
>  drivers/usb/serial/mos7720.c          | 6 +++---
>  drivers/usb/serial/mos7840.c          | 7 +++----
>  drivers/usb/serial/opticon.c          | 2 +-
>  drivers/usb/serial/oti6858.c          | 6 +++---
>  drivers/usb/serial/quatech2.c         | 4 ++--
>  drivers/usb/serial/sierra.c           | 2 +-
>  drivers/usb/serial/ti_usb_3410_5052.c | 8 ++++----
>  drivers/usb/serial/usb-wwan.h         | 2 +-
>  drivers/usb/serial/usb_wwan.c         | 6 +++---
>  include/linux/usb/serial.h            | 4 ++--
>  20 files changed, 50 insertions(+), 51 deletions(-)
 
> diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
> index 6ee83886e2c9..d9cc7f840d48 100644
> --- a/drivers/usb/serial/mos7720.c
> +++ b/drivers/usb/serial/mos7720.c
> @@ -1033,11 +1033,11 @@ static void mos7720_break(struct tty_struct *tty, int break_state)
>   *	If successful, we return the amount of room that we have for this port
>   *	Otherwise we return a negative error number.
>   */
> -static int mos7720_write_room(struct tty_struct *tty)
> +static unsigned int mos7720_write_room(struct tty_struct *tty)
>  {
>  	struct usb_serial_port *port = tty->driver_data;
>  	struct moschip_port *mos7720_port;
> -	int room = 0;
> +	unsigned int room = 0;
>  	int i;
>  
>  	mos7720_port = usb_get_serial_port_data(port);
> @@ -1051,7 +1051,7 @@ static int mos7720_write_room(struct tty_struct *tty)
>  			room += URB_TRANSFER_BUFFER_SIZE;
>  	}
>  
> -	dev_dbg(&port->dev, "%s - returns %d\n", __func__, room);
> +	dev_dbg(&port->dev, "%s - returns %u\n", __func__, room);
>  	return room;
>  }
>  
> diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
> index 28e4093794e0..f25d4ba43b9a 100644
> --- a/drivers/usb/serial/mos7840.c
> +++ b/drivers/usb/serial/mos7840.c
> @@ -815,15 +815,14 @@ static void mos7840_break(struct tty_struct *tty, int break_state)
>   *	this function is called by the tty driver when it wants to know how many
>   *	bytes of data we can accept for a specific port.
>   *	If successful, we return the amount of room that we have for this port
> - *	Otherwise we return a negative error number.

This is arguably an unrelated change, and you're not removing these
outdated comments consistently (e.g. mos7720 above) so I've dropped this
bit for now.

Will send a follow up patch to clean it up all these instances instead.

>   *****************************************************************************/
>  
> -static int mos7840_write_room(struct tty_struct *tty)
> +static unsigned int mos7840_write_room(struct tty_struct *tty)
>  {
>  	struct usb_serial_port *port = tty->driver_data;
>  	struct moschip_port *mos7840_port = usb_get_serial_port_data(port);
>  	int i;
> -	int room = 0;
> +	unsigned int room = 0;
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&mos7840_port->pool_lock, flags);

Now applied with an amended commit message.

Johan

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

* Re: [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer return uint
  2021-05-05  9:19 ` [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer " Jiri Slaby
@ 2021-05-19  9:09   ` Johan Hovold
  0 siblings, 0 replies; 71+ messages in thread
From: Johan Hovold @ 2021-05-19  9:09 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: gregkh, linux-serial, linux-kernel, linux-usb

On Wed, May 05, 2021 at 11:19:20AM +0200, Jiri Slaby wrote:
> tty_operations::chars_in_buffer was switched to uint in the previous
> patch. So do the same for usb_serial_driver's chars_in_buffer too.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>

Applied with an amended commit message (e.g. fixed subject prefix).
Thanks.

Johan

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

* Re: [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer
  2021-05-05  9:19 ` [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer Jiri Slaby
@ 2021-05-19  9:11   ` Johan Hovold
  0 siblings, 0 replies; 71+ messages in thread
From: Johan Hovold @ 2021-05-19  9:11 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: gregkh, linux-serial, linux-kernel, linux-usb

On Wed, May 05, 2021 at 11:19:22AM +0200, Jiri Slaby wrote:
> "if"'s true branch in digi_chars_in_buffer returns. So there is no need
> for "else" and indented code. Remove this else and shift the code to the
> left.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: linux-usb@vger.kernel.org
> ---
>  drivers/usb/serial/digi_acceleport.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
> index 19ee8191647c..0c4d611621c2 100644
> --- a/drivers/usb/serial/digi_acceleport.c
> +++ b/drivers/usb/serial/digi_acceleport.c
> @@ -1050,12 +1050,11 @@ static unsigned int digi_chars_in_buffer(struct tty_struct *tty)
>  			priv->dp_port_num, port->bulk_out_size - 2);
>  		/* return(port->bulk_out_size - 2); */
>  		return 256;
> -	} else {
> -		dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
> -			priv->dp_port_num, priv->dp_out_buf_len);
> -		return priv->dp_out_buf_len;
>  	}
>  
> +	dev_dbg(&port->dev, "digi_chars_in_buffer: port=%d, chars=%d\n",
> +		priv->dp_port_num, priv->dp_out_buf_len);
> +	return priv->dp_out_buf_len;
>  }

This doesn't look like much of an improvement so I'm dropping this one.

If we want to clean this up we should use a common exit path for both
branches. I'll send a couple of patches to address this and a related
issue.

Johan

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

* [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available
  2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
                   ` (35 preceding siblings ...)
  2021-05-13 15:04 ` [PATCH 00/35] tty cleanup for 5.14 Greg KH
@ 2021-06-10  9:02 ` Jiri Slaby
  2021-06-10  9:02   ` [PATCH v3 2/4] mxs-auart: redefine AUART_LINECTRL_WLEN to accept bits count Jiri Slaby
                     ` (2 more replies)
  36 siblings, 3 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-06-10  9:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Andy Shevchenko,
	Joe Perches, Johan Hovold

Many tty drivers contain code to compute bits count depending on termios
cflags. So extract this code from serial core to two separate tty helper
functions:
* tty_get_char_size -- only size of a character, without flags,
* tty_get_frame_size -- complete size of a frame including flags.

In the next patch, calls to these new functions replace many copies of
this code.

Note that we accept only cflag as a parameter. That's because some
callers like pch_uart_startup or sunsab_console_setup don't have at hand
termios which we could pass around.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Joe Perches <joe@perches.com>
Cc: Johan Hovold <johan@kernel.org>
---
[v2] simplified the code flow as suggested by Joe and Andy
[v3] redesign to have 2 functions as suggested by Johan.

 drivers/tty/serial/serial_core.c | 30 +++------------------
 drivers/tty/tty_ioctl.c          | 45 ++++++++++++++++++++++++++++++++
 include/linux/tty.h              |  3 +++
 3 files changed, 51 insertions(+), 27 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 642e24d6c475..69092deba11f 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -334,39 +334,15 @@ void
 uart_update_timeout(struct uart_port *port, unsigned int cflag,
 		    unsigned int baud)
 {
-	unsigned int bits;
+	unsigned int size;
 
-	/* byte size and parity */
-	switch (cflag & CSIZE) {
-	case CS5:
-		bits = 7;
-		break;
-	case CS6:
-		bits = 8;
-		break;
-	case CS7:
-		bits = 9;
-		break;
-	default:
-		bits = 10;
-		break; /* CS8 */
-	}
-
-	if (cflag & CSTOPB)
-		bits++;
-	if (cflag & PARENB)
-		bits++;
-
-	/*
-	 * The total number of bits to be transmitted in the fifo.
-	 */
-	bits = bits * port->fifosize;
+	size = tty_get_frame_size(cflag) * port->fifosize;
 
 	/*
 	 * Figure the timeout to send the above number of bits.
 	 * Add .02 seconds of slop
 	 */
-	port->timeout = (HZ * bits) / baud + HZ/50;
+	port->timeout = (HZ * size) / baud + HZ/50;
 }
 
 EXPORT_SYMBOL(uart_update_timeout);
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index 75885d502749..507a25d692bb 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -279,6 +279,51 @@ int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b)
 }
 EXPORT_SYMBOL(tty_termios_hw_change);
 
+/**
+ *	tty_get_char_size	-	get size of a character
+ *	@cflag: termios cflag value
+ *
+ *	Get the size (in bits) of a character depending on @cflag's %CSIZE
+ *	setting.
+ */
+unsigned char tty_get_char_size(unsigned int cflag)
+{
+	switch (cflag & CSIZE) {
+	case CS5:
+		return 5;
+	case CS6:
+		return 6;
+	case CS7:
+		return 7;
+	case CS8:
+	default:
+		return 8;
+	}
+}
+EXPORT_SYMBOL_GPL(tty_get_char_size);
+
+/**
+ *	tty_get_frame_size	-	get size of a frame
+ *	@cflag: termios cflag value
+ *
+ *	Get the size (in bits) of a frame depending on @cflag's %CSIZE, %CSTOPB,
+ *	and %PARENB setting. The result is a sum of character size, start and
+ *	stop bits -- one bit each -- second stop bit (if set), and parity bit
+ *	(if set).
+ */
+unsigned char tty_get_frame_size(unsigned int cflag)
+{
+	unsigned char bits = 2 + tty_get_char_size(cflag);
+
+	if (cflag & CSTOPB)
+		bits++;
+	if (cflag & PARENB)
+		bits++;
+
+	return bits;
+}
+EXPORT_SYMBOL_GPL(tty_get_frame_size);
+
 /**
  *	tty_set_termios		-	update termios values
  *	@tty: tty to update
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 4c0c7ca1d9a4..19dc1097e09c 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -495,6 +495,9 @@ static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
 	return tty_termios_baud_rate(&tty->termios);
 }
 
+unsigned char tty_get_char_size(unsigned int cflag);
+unsigned char tty_get_frame_size(unsigned int cflag);
+
 extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
 extern int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
 extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
-- 
2.32.0


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

* [PATCH v3 2/4] mxs-auart: redefine AUART_LINECTRL_WLEN to accept bits count
  2021-06-10  9:02 ` [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available Jiri Slaby
@ 2021-06-10  9:02   ` Jiri Slaby
  2021-06-10  9:02   ` [PATCH v3 3/4] cypress_m8: switch data_bits to real character bits Jiri Slaby
  2021-06-10  9:02   ` [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size Jiri Slaby
  2 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-06-10  9:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

It's a bit illogical to take magic constants in AUART_LINECTRL_WLEN.
Like in auart_console_get_options(), 2 means 7 bits. Switch
AUART_LINECTRL_WLEN to accept bit length, i.e. let it subtract 5 from
the parameter before doing the logic.

This will ease conversion from CSIZE to bits in mxs_auart_settermios()
in the next patch.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/serial/mxs-auart.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index f414d6acad69..7b4b6bb75424 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -87,7 +87,7 @@
 #define AUART_LINECTRL_BAUD_DIVFRAC(v)		(((v) & 0x3f) << 8)
 #define AUART_LINECTRL_SPS			(1 << 7)
 #define AUART_LINECTRL_WLEN_MASK		0x00000060
-#define AUART_LINECTRL_WLEN(v)			(((v) & 0x3) << 5)
+#define AUART_LINECTRL_WLEN(v)			((((v) - 5) & 0x3) << 5)
 #define AUART_LINECTRL_FEN			(1 << 4)
 #define AUART_LINECTRL_STP2			(1 << 3)
 #define AUART_LINECTRL_EPS			(1 << 2)
@@ -973,16 +973,16 @@ static void mxs_auart_settermios(struct uart_port *u,
 	/* byte size */
 	switch (cflag & CSIZE) {
 	case CS5:
-		bm = 0;
+		bm = 5;
 		break;
 	case CS6:
-		bm = 1;
+		bm = 6;
 		break;
 	case CS7:
-		bm = 2;
+		bm = 7;
 		break;
 	case CS8:
-		bm = 3;
+		bm = 8;
 		break;
 	default:
 		return;
@@ -1403,7 +1403,7 @@ auart_console_get_options(struct mxs_auart_port *s, int *baud,
 			*parity = 'o';
 	}
 
-	if ((lcr_h & AUART_LINECTRL_WLEN_MASK) == AUART_LINECTRL_WLEN(2))
+	if ((lcr_h & AUART_LINECTRL_WLEN_MASK) == AUART_LINECTRL_WLEN(7))
 		*bits = 7;
 	else
 		*bits = 8;
-- 
2.32.0


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

* [PATCH v3 3/4] cypress_m8: switch data_bits to real character bits
  2021-06-10  9:02 ` [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available Jiri Slaby
  2021-06-10  9:02   ` [PATCH v3 2/4] mxs-auart: redefine AUART_LINECTRL_WLEN to accept bits count Jiri Slaby
@ 2021-06-10  9:02   ` Jiri Slaby
  2021-06-10  9:02   ` [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size Jiri Slaby
  2 siblings, 0 replies; 71+ messages in thread
From: Jiri Slaby @ 2021-06-10  9:02 UTC (permalink / raw)
  To: gregkh; +Cc: linux-serial, linux-kernel, Jiri Slaby

Make data_bits what it really is. Assign proper bit counts to data_bits
instead of magic 0..3. There are two reasons:
1) it's clear what we store there, and
2) it will make the transition to tty_tty_get_char_size() in the next
   patch easier.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/usb/serial/cypress_m8.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 1dca04e1519d..ad8ed5361677 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -326,7 +326,7 @@ static int cypress_serial_control(struct tty_struct *tty,
 
 		/* fill the feature_buffer with new configuration */
 		put_unaligned_le32(new_baudrate, feature_buffer);
-		feature_buffer[4] |= data_bits;   /* assign data bits in 2 bit space ( max 3 ) */
+		feature_buffer[4] |= data_bits - 5;   /* assign data bits in 2 bit space ( max 3 ) */
 		/* 1 bit gap */
 		feature_buffer[4] |= (stop_bits << 3);   /* assign stop bits in 1 bit space */
 		feature_buffer[4] |= (parity_enable << 4);   /* assign parity flag in 1 bit space */
@@ -889,20 +889,20 @@ static void cypress_set_termios(struct tty_struct *tty,
 
 	switch (cflag & CSIZE) {
 	case CS5:
-		data_bits = 0;
+		data_bits = 5;
 		break;
 	case CS6:
-		data_bits = 1;
+		data_bits = 6;
 		break;
 	case CS7:
-		data_bits = 2;
+		data_bits = 7;
 		break;
 	case CS8:
-		data_bits = 3;
+		data_bits = 8;
 		break;
 	default:
 		dev_err(dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__);
-		data_bits = 3;
+		data_bits = 8;
 	}
 	spin_lock_irqsave(&priv->lock, flags);
 	oldlines = priv->line_control;
-- 
2.32.0


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

* [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size
  2021-06-10  9:02 ` [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available Jiri Slaby
  2021-06-10  9:02   ` [PATCH v3 2/4] mxs-auart: redefine AUART_LINECTRL_WLEN to accept bits count Jiri Slaby
  2021-06-10  9:02   ` [PATCH v3 3/4] cypress_m8: switch data_bits to real character bits Jiri Slaby
@ 2021-06-10  9:02   ` Jiri Slaby
  2021-06-10 15:15     ` Alex Elder
  2 siblings, 1 reply; 71+ messages in thread
From: Jiri Slaby @ 2021-06-10  9:02 UTC (permalink / raw)
  To: gregkh
  Cc: linux-serial, linux-kernel, Jiri Slaby, Arnd Bergmann, David Lin,
	Johan Hovold, Alex Elder, Shawn Guo, Sascha Hauer, Andy Gross,
	Bjorn Andersson, Maxime Coquelin, Alexandre Torgue,
	Oliver Neukum

In the previous patch, we introduced tty_get_char_size() and
tty_get_frame_size() for computing character and frame sizes,
respectively. Here, we make use of them in various tty drivers where
applicable.

The stats look nice: 12 insertions, 169 deletions.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Andy Gross <agross@kernel.org>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Oliver Neukum <oneukum@suse.com>
---
[v2] rebase mxs-auart and cypress_m8; drop C_CSIZE from pl2303

 drivers/char/pcmcia/synclink_cs.c           |  8 +-----
 drivers/staging/greybus/uart.c              | 16 +----------
 drivers/tty/serial/cpm_uart/cpm_uart_core.c | 19 +-----------
 drivers/tty/serial/mxs-auart.c              | 22 ++------------
 drivers/tty/serial/qcom_geni_serial.c       | 16 +----------
 drivers/tty/serial/sh-sci.c                 | 20 +------------
 drivers/tty/serial/stm32-usart.c            | 32 +--------------------
 drivers/tty/synclink_gt.c                   |  9 +-----
 drivers/usb/class/cdc-acm.c                 | 17 ++---------
 drivers/usb/serial/belkin_sa.c              | 20 +------------
 drivers/usb/serial/cypress_m8.c             | 19 ++----------
 drivers/usb/serial/pl2303.c                 | 15 +---------
 drivers/usb/serial/whiteheat.c              |  9 +-----
 13 files changed, 16 insertions(+), 206 deletions(-)

diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 9f7420bc5026..6eaefea0520e 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -1419,13 +1419,7 @@ static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty)
 
 	/* byte size and parity */
 
-	switch (cflag & CSIZE) {
-	case CS5: info->params.data_bits = 5; break;
-	case CS6: info->params.data_bits = 6; break;
-	case CS7: info->params.data_bits = 7; break;
-	case CS8: info->params.data_bits = 8; break;
-	default:  info->params.data_bits = 7; break;
-	}
+	info->params.data_bits = tty_get_char_size(cflag);
 
 	if (cflag & CSTOPB)
 		info->params.stop_bits = 2;
diff --git a/drivers/staging/greybus/uart.c b/drivers/staging/greybus/uart.c
index ccfaa0f21b9c..73f01ed1e5b7 100644
--- a/drivers/staging/greybus/uart.c
+++ b/drivers/staging/greybus/uart.c
@@ -494,21 +494,7 @@ static void gb_tty_set_termios(struct tty_struct *tty,
 				(termios->c_cflag & PARODD ? 1 : 2) +
 				(termios->c_cflag & CMSPAR ? 2 : 0) : 0;
 
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		newline.data_bits = 5;
-		break;
-	case CS6:
-		newline.data_bits = 6;
-		break;
-	case CS7:
-		newline.data_bits = 7;
-		break;
-	case CS8:
-	default:
-		newline.data_bits = 8;
-		break;
-	}
+	newline.data_bits = tty_get_char_size(termios->c_cflag);
 
 	/* FIXME: needs to clear unsupported bits in the termios */
 	gb_tty->clocal = ((termios->c_cflag & CLOCAL) != 0);
diff --git a/drivers/tty/serial/cpm_uart/cpm_uart_core.c b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
index 58aaa533203b..c719aa2b1832 100644
--- a/drivers/tty/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/tty/serial/cpm_uart/cpm_uart_core.c
@@ -524,24 +524,7 @@ static void cpm_uart_set_termios(struct uart_port *port,
 	scval = 0;
 
 	/* byte size */
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		bits = 5;
-		break;
-	case CS6:
-		bits = 6;
-		break;
-	case CS7:
-		bits = 7;
-		break;
-	case CS8:
-		bits = 8;
-		break;
-		/* Never happens, but GCC is too dumb to figure it out */
-	default:
-		bits = 8;
-		break;
-	}
+	bits = tty_get_char_size(termios->c_cflag);
 	sbits = bits - 5;
 
 	if (termios->c_cflag & CSTOPB) {
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index 7b4b6bb75424..ac45f3386e97 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -962,7 +962,7 @@ static void mxs_auart_settermios(struct uart_port *u,
 				 struct ktermios *old)
 {
 	struct mxs_auart_port *s = to_auart_port(u);
-	u32 bm, ctrl, ctrl2, div;
+	u32 ctrl, ctrl2, div;
 	unsigned int cflag, baud, baud_min, baud_max;
 
 	cflag = termios->c_cflag;
@@ -970,25 +970,7 @@ static void mxs_auart_settermios(struct uart_port *u,
 	ctrl = AUART_LINECTRL_FEN;
 	ctrl2 = mxs_read(s, REG_CTRL2);
 
-	/* byte size */
-	switch (cflag & CSIZE) {
-	case CS5:
-		bm = 5;
-		break;
-	case CS6:
-		bm = 6;
-		break;
-	case CS7:
-		bm = 7;
-		break;
-	case CS8:
-		bm = 8;
-		break;
-	default:
-		return;
-	}
-
-	ctrl |= AUART_LINECTRL_WLEN(bm);
+	ctrl |= AUART_LINECTRL_WLEN(tty_get_char_size(cflag));
 
 	/* parity */
 	if (cflag & PARENB) {
diff --git a/drivers/tty/serial/qcom_geni_serial.c b/drivers/tty/serial/qcom_geni_serial.c
index 463f84a66f6e..379ab15daa85 100644
--- a/drivers/tty/serial/qcom_geni_serial.c
+++ b/drivers/tty/serial/qcom_geni_serial.c
@@ -1050,21 +1050,7 @@ static void qcom_geni_serial_set_termios(struct uart_port *uport,
 	}
 
 	/* bits per char */
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		bits_per_char = 5;
-		break;
-	case CS6:
-		bits_per_char = 6;
-		break;
-	case CS7:
-		bits_per_char = 7;
-		break;
-	case CS8:
-	default:
-		bits_per_char = 8;
-		break;
-	}
+	bits_per_char = tty_get_char_size(termios->c_cflag);
 
 	/* stop bits */
 	if (termios->c_cflag & CSTOPB)
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 92c92df24f5d..3a9379bbcd57 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -2495,25 +2495,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios,
 	uart_update_timeout(port, termios->c_cflag, baud);
 
 	/* byte size and parity */
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		bits = 7;
-		break;
-	case CS6:
-		bits = 8;
-		break;
-	case CS7:
-		bits = 9;
-		break;
-	default:
-		bits = 10;
-		break;
-	}
-
-	if (termios->c_cflag & CSTOPB)
-		bits++;
-	if (termios->c_cflag & PARENB)
-		bits++;
+	bits = tty_get_frame_size(termios->c_cflag);
 
 	if (sci_getreg(port, SEMR)->size)
 		serial_port_out(port, SEMR, 0);
diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
index bf188bdf9717..f88e6bc4fd91 100644
--- a/drivers/tty/serial/stm32-usart.c
+++ b/drivers/tty/serial/stm32-usart.c
@@ -718,36 +718,6 @@ static void stm32_usart_shutdown(struct uart_port *port)
 	free_irq(port->irq, port);
 }
 
-static unsigned int stm32_usart_get_databits(struct ktermios *termios)
-{
-	unsigned int bits;
-
-	tcflag_t cflag = termios->c_cflag;
-
-	switch (cflag & CSIZE) {
-	/*
-	 * CSIZE settings are not necessarily supported in hardware.
-	 * CSIZE unsupported configurations are handled here to set word length
-	 * to 8 bits word as default configuration and to print debug message.
-	 */
-	case CS5:
-		bits = 5;
-		break;
-	case CS6:
-		bits = 6;
-		break;
-	case CS7:
-		bits = 7;
-		break;
-	/* default including CS8 */
-	default:
-		bits = 8;
-		break;
-	}
-
-	return bits;
-}
-
 static void stm32_usart_set_termios(struct uart_port *port,
 				    struct ktermios *termios,
 				    struct ktermios *old)
@@ -805,7 +775,7 @@ static void stm32_usart_set_termios(struct uart_port *port,
 	if (cflag & CSTOPB)
 		cr2 |= USART_CR2_STOP_2B;
 
-	bits = stm32_usart_get_databits(termios);
+	bits = tty_get_char_size(cflag);
 	stm32_port->rdr_mask = (BIT(bits) - 1);
 
 	if (cflag & PARENB) {
diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
index cf87dc66087b..5bb928b7873e 100644
--- a/drivers/tty/synclink_gt.c
+++ b/drivers/tty/synclink_gt.c
@@ -2465,14 +2465,7 @@ static void change_params(struct slgt_info *info)
 
 	/* byte size and parity */
 
-	switch (cflag & CSIZE) {
-	case CS5: info->params.data_bits = 5; break;
-	case CS6: info->params.data_bits = 6; break;
-	case CS7: info->params.data_bits = 7; break;
-	case CS8: info->params.data_bits = 8; break;
-	default:  info->params.data_bits = 7; break;
-	}
-
+	info->params.data_bits = tty_get_char_size(cflag);
 	info->params.stop_bits = (cflag & CSTOPB) ? 2 : 1;
 
 	if (cflag & PARENB)
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 81199efe0312..c9954eb56e00 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1056,21 +1056,8 @@ static void acm_tty_set_termios(struct tty_struct *tty,
 	newline.bParityType = termios->c_cflag & PARENB ?
 				(termios->c_cflag & PARODD ? 1 : 2) +
 				(termios->c_cflag & CMSPAR ? 2 : 0) : 0;
-	switch (termios->c_cflag & CSIZE) {
-	case CS5:
-		newline.bDataBits = 5;
-		break;
-	case CS6:
-		newline.bDataBits = 6;
-		break;
-	case CS7:
-		newline.bDataBits = 7;
-		break;
-	case CS8:
-	default:
-		newline.bDataBits = 8;
-		break;
-	}
+	newline.bDataBits = tty_get_char_size(termios->c_cflag);
+
 	/* FIXME: Needs to clear unsupported bits in the termios */
 	acm->clocal = ((termios->c_cflag & CLOCAL) != 0);
 
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index ed9193f3bb1a..8107e4b5b03b 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -356,25 +356,7 @@ static void belkin_sa_set_termios(struct tty_struct *tty,
 
 	/* set the number of data bits */
 	if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
-		switch (cflag & CSIZE) {
-		case CS5:
-			urb_value = BELKIN_SA_DATA_BITS(5);
-			break;
-		case CS6:
-			urb_value = BELKIN_SA_DATA_BITS(6);
-			break;
-		case CS7:
-			urb_value = BELKIN_SA_DATA_BITS(7);
-			break;
-		case CS8:
-			urb_value = BELKIN_SA_DATA_BITS(8);
-			break;
-		default:
-			dev_dbg(&port->dev,
-				"CSIZE was not CS5-CS8, using default of 8\n");
-			urb_value = BELKIN_SA_DATA_BITS(8);
-			break;
-		}
+		urb_value = BELKIN_SA_DATA_BITS(tty_get_char_size(cflag));
 		if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0)
 			dev_err(&port->dev, "Set data bits error\n");
 	}
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index ad8ed5361677..6b18990258c3 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -887,23 +887,8 @@ static void cypress_set_termios(struct tty_struct *tty,
 	} else
 		parity_enable = parity_type = 0;
 
-	switch (cflag & CSIZE) {
-	case CS5:
-		data_bits = 5;
-		break;
-	case CS6:
-		data_bits = 6;
-		break;
-	case CS7:
-		data_bits = 7;
-		break;
-	case CS8:
-		data_bits = 8;
-		break;
-	default:
-		dev_err(dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__);
-		data_bits = 8;
-	}
+	data_bits = tty_get_char_size(cflag);
+
 	spin_lock_irqsave(&priv->lock, flags);
 	oldlines = priv->line_control;
 	if ((cflag & CBAUD) == B0) {
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 940050c31482..2f2f5047452b 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -789,20 +789,7 @@ static void pl2303_set_termios(struct tty_struct *tty,
 
 	pl2303_get_line_request(port, buf);
 
-	switch (C_CSIZE(tty)) {
-	case CS5:
-		buf[6] = 5;
-		break;
-	case CS6:
-		buf[6] = 6;
-		break;
-	case CS7:
-		buf[6] = 7;
-		break;
-	default:
-	case CS8:
-		buf[6] = 8;
-	}
+	buf[6] = tty_get_char_size(tty->termios.c_cflag);
 	dev_dbg(&port->dev, "data bits = %d\n", buf[6]);
 
 	/* For reference buf[0]:buf[3] baud rate value */
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 5116ed9db3eb..da65d14c9ed5 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -625,14 +625,7 @@ static void firm_setup_port(struct tty_struct *tty)
 
 	port_settings.port = port->port_number + 1;
 
-	/* get the byte size */
-	switch (cflag & CSIZE) {
-	case CS5:	port_settings.bits = 5;   break;
-	case CS6:	port_settings.bits = 6;   break;
-	case CS7:	port_settings.bits = 7;   break;
-	default:
-	case CS8:	port_settings.bits = 8;   break;
-	}
+	port_settings.bits = tty_get_char_size(cflag);
 	dev_dbg(dev, "%s - data bits = %d\n", __func__, port_settings.bits);
 
 	/* determine the parity */
-- 
2.32.0


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

* Re: [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size
  2021-06-10  9:02   ` [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size Jiri Slaby
@ 2021-06-10 15:15     ` Alex Elder
  0 siblings, 0 replies; 71+ messages in thread
From: Alex Elder @ 2021-06-10 15:15 UTC (permalink / raw)
  To: Jiri Slaby, gregkh
  Cc: linux-serial, linux-kernel, Arnd Bergmann, David Lin,
	Johan Hovold, Alex Elder, Shawn Guo, Sascha Hauer, Andy Gross,
	Bjorn Andersson, Maxime Coquelin, Alexandre Torgue,
	Oliver Neukum

On 6/10/21 4:02 AM, Jiri Slaby wrote:
> In the previous patch, we introduced tty_get_char_size() and
> tty_get_frame_size() for computing character and frame sizes,
> respectively. Here, we make use of them in various tty drivers where
> applicable.
> 
> The stats look nice: 12 insertions, 169 deletions.

Agreed.  Looks good to me (for drivers/staging/greybus/uart.c).

Acked-by: Alex Elder <elder@kernel.org>

> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: David Lin <dtwlin@gmail.com>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Alex Elder <elder@kernel.org>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Andy Gross <agross@kernel.org>
> Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
> Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
> Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
> Cc: Oliver Neukum <oneukum@suse.com>

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

end of thread, other threads:[~2021-06-10 15:16 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05  9:18 [PATCH 00/35] tty cleanup for 5.14 Jiri Slaby
2021-05-05  9:18 ` [PATCH 01/35] tty: remove broken r3964 line discipline Jiri Slaby
2021-05-05  9:26   ` Greg KH
2021-05-05  9:18 ` [PATCH 02/35] n_tty: remove n_tty_receive_char wrapper Jiri Slaby
2021-05-05  9:18 ` [PATCH 03/35] n_tty: remove n_tty_receive_char_fast Jiri Slaby
2021-05-05  9:18 ` [PATCH 04/35] n_tty: drop n_tty_receive_buf_fast Jiri Slaby
2021-05-05  9:18 ` [PATCH 05/35] n_tty: drop parmrk_dbl from n_tty_receive_char Jiri Slaby
2021-05-05  9:18 ` [PATCH 06/35] n_tty: move lnext handling Jiri Slaby
2021-05-05  9:19 ` [PATCH 07/35] n_tty: make n_tty_receive_char_special return void Jiri Slaby
2021-05-05  9:19 ` [PATCH 08/35] n_tty: do only one cp dereference in n_tty_receive_buf_standard Jiri Slaby
2021-05-05  9:19 ` [PATCH 09/35] n_tty: invert TTY_NORMAL condition " Jiri Slaby
2021-05-05  9:19 ` [PATCH 10/35] n_tty: remove superfluous return from n_tty_receive_signal_char Jiri Slaby
2021-05-05  9:19 ` [PATCH 11/35] tty: make fp of tty_ldisc_ops::receive_buf{,2} const Jiri Slaby
2021-05-05  9:19 ` [PATCH 12/35] tty: cumulate and document tty_struct::flow* members Jiri Slaby
2021-05-05  9:19 ` [PATCH 13/35] tty: cumulate and document tty_struct::ctrl* members Jiri Slaby
2021-05-05  9:19 ` [PATCH 14/35] tty: set tty_ldisc_ops::num statically Jiri Slaby
2021-05-05  9:19 ` [PATCH 15/35] n_gsm: use goto-failpaths in gsm_init Jiri Slaby
2021-05-05  9:19 ` [PATCH 16/35] tty: make tty_ldisc_ops a param in tty_unregister_ldisc Jiri Slaby
2021-05-05  9:19 ` [PATCH 17/35] tty: drop tty_ldisc_ops::refcount Jiri Slaby
2021-05-05  9:19 ` [PATCH 18/35] tty: no checking of tty_unregister_ldisc Jiri Slaby
2021-05-05  9:19 ` [PATCH 19/35] tty: return void from tty_unregister_ldisc Jiri Slaby
2021-05-05  9:19 ` [PATCH 20/35] ti-st: use goto-failpath in st_core_init Jiri Slaby
2021-05-05  9:19 ` [PATCH 21/35] ti-st: use tty_write_room Jiri Slaby
2021-05-05  9:19 ` [PATCH 22/35] tty: make tty_operations::write_room return uint Jiri Slaby
2021-05-05  9:25   ` Geert Uytterhoeven
2021-05-05 10:34   ` Anton Ivanov
2021-05-05 10:43   ` David Sterba
2021-05-05 11:53   ` Max Filippov
2021-05-05 12:15   ` Alex Elder
2021-05-10 11:27   ` Laurentiu Tudor
2021-05-05  9:19 ` [PATCH 23/35] USB: serial: make usb_serial_driver::write_room " Jiri Slaby
2021-05-19  9:07   ` Johan Hovold
2021-05-05  9:19 ` [PATCH 24/35] tty: make tty_buffer_space_avail " Jiri Slaby
2021-05-05  9:19 ` [PATCH 25/35] tty: remove tty_operations::chars_in_buffer for non-buffering Jiri Slaby
2021-05-05 11:51   ` Max Filippov
2021-05-06  5:47   ` Jiri Slaby
2021-05-06  5:56     ` Greg KH
2021-05-05  9:19 ` [PATCH 26/35] tty: make tty_operations::chars_in_buffer return uint Jiri Slaby
2021-05-05 10:34   ` Anton Ivanov
2021-05-05 10:43   ` David Sterba
2021-05-05  9:19 ` [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer " Jiri Slaby
2021-05-19  9:09   ` Johan Hovold
2021-05-05  9:19 ` [PATCH 28/35] nozomi: simplify ntty_chars_in_buffer Jiri Slaby
2021-05-05  9:19 ` [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer Jiri Slaby
2021-05-19  9:11   ` Johan Hovold
2021-05-05  9:19 ` [PATCH 30/35] tty: remove empty tty_operations::flush_buffer Jiri Slaby
2021-05-05  9:19 ` [PATCH 31/35] tty: remove empty tty_operations::set_termios Jiri Slaby
2021-05-05 10:34   ` Anton Ivanov
2021-05-05  9:19 ` [PATCH 32/35] isdn: capi, remove optional tty ops Jiri Slaby
2021-05-05  9:19 ` [PATCH 33/35] isdn: capi, drop useless pr_debugs Jiri Slaby
2021-05-05  9:19 ` [PATCH 34/35] tty: make tty_get_byte_size available Jiri Slaby
2021-05-06  7:16   ` Joe Perches
2021-05-06  7:19     ` Jiri Slaby
     [not found]     ` <CAHp75Vfq6ABW7ukwaKmZOF2DszmuHD28S=wcLcFowvRdXTnWmg@mail.gmail.com>
2021-05-06  8:31       ` Jiri Slaby
2021-05-06  9:33         ` Andy Shevchenko
2021-05-06  8:35       ` Joe Perches
2021-05-10  7:00   ` [PATCH v2 " Jiri Slaby
2021-05-10  9:47     ` Johan Hovold
2021-05-13  7:24       ` Jiri Slaby
2021-05-13  9:41         ` Johan Hovold
2021-05-05  9:19 ` [PATCH 35/35] tty: make use of tty_get_byte_size Jiri Slaby
2021-05-10  9:59   ` Johan Hovold
2021-05-13 15:04 ` [PATCH 00/35] tty cleanup for 5.14 Greg KH
2021-05-13 16:20   ` Johan Hovold
2021-05-13 16:29     ` Greg KH
2021-05-14  8:11       ` Johan Hovold
2021-06-10  9:02 ` [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available Jiri Slaby
2021-06-10  9:02   ` [PATCH v3 2/4] mxs-auart: redefine AUART_LINECTRL_WLEN to accept bits count Jiri Slaby
2021-06-10  9:02   ` [PATCH v3 3/4] cypress_m8: switch data_bits to real character bits Jiri Slaby
2021-06-10  9:02   ` [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size Jiri Slaby
2021-06-10 15:15     ` Alex Elder

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