2021-05-05 10:21:17

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 00/35] tty cleanup for 5.14

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


2021-05-05 10:22:02

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 05/35] n_tty: drop parmrk_dbl from n_tty_receive_char

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

2021-05-05 10:24:59

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 10/35] n_tty: remove superfluous return from n_tty_receive_signal_char

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

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

2021-05-05 10:26:23

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 15/35] n_gsm: use goto-failpaths in gsm_init

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

2021-05-05 10:28:06

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 17/35] tty: drop tty_ldisc_ops::refcount

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

2021-05-05 10:28:53

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 19/35] tty: return void from tty_unregister_ldisc

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

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

2021-05-05 10:36:02

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 24/35] tty: make tty_buffer_space_avail return uint

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

Signed-off-by: Jiri Slaby <[email protected]>
Cc: Joel Stanley <[email protected]>
---
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

2021-05-05 10:36:03

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 23/35] USB: serial: make usb_serial_driver::write_room return uint

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

2021-05-05 10:37:07

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 32/35] isdn: capi, remove optional tty ops

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

2021-05-05 10:37:38

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer

"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 <[email protected]>
Cc: Johan Hovold <[email protected]>
Cc: [email protected]
---
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

2021-05-05 10:37:39

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 33/35] isdn: capi, drop useless pr_debugs

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

2021-05-05 10:39:09

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 30/35] tty: remove empty tty_operations::flush_buffer

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 <[email protected]>
Cc: Karsten Keil <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Cc: Christian Borntraeger <[email protected]>
---
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

2021-05-05 11:54:18

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer return uint

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

2021-05-05 11:54:22

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 31/35] tty: remove empty tty_operations::set_termios

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 <[email protected]>
Cc: Jeff Dike <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Anton Ivanov <[email protected]>
Cc: Karsten Keil <[email protected]>
---
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

2021-05-05 11:54:58

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH 35/35] tty: make use of tty_get_byte_size

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 <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: David Lin <[email protected]>
Cc: Johan Hovold <[email protected]>
Cc: Alex Elder <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Andy Gross <[email protected]>
Cc: Bjorn Andersson <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: Oliver Neukum <[email protected]>
---
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

2021-05-05 12:05:08

by Anton Ivanov

[permalink] [raw]
Subject: Re: [PATCH 31/35] tty: remove empty tty_operations::set_termios



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 <[email protected]>
> Cc: Jeff Dike <[email protected]>
> Cc: Richard Weinberger <[email protected]>
> Cc: Anton Ivanov <[email protected]>
> Cc: Karsten Keil <[email protected]>
> ---
> 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 <[email protected]>

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

2021-05-10 10:02:34

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 35/35] tty: make use of tty_get_byte_size

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 <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: David Lin <[email protected]>
> Cc: Johan Hovold <[email protected]>
> Cc: Alex Elder <[email protected]>
> Cc: Shawn Guo <[email protected]>
> Cc: Sascha Hauer <[email protected]>
> Cc: Andy Gross <[email protected]>
> Cc: Bjorn Andersson <[email protected]>
> Cc: Maxime Coquelin <[email protected]>
> Cc: Alexandre Torgue <[email protected]>
> Cc: Oliver Neukum <[email protected]>
> ---
> 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

2021-05-13 22:33:50

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 00/35] tty cleanup for 5.14

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

2021-05-14 04:09:07

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 00/35] tty cleanup for 5.14

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

2021-05-14 04:09:39

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 00/35] tty cleanup for 5.14

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

2021-05-14 14:17:38

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 00/35] tty cleanup for 5.14

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

2021-05-19 19:24:33

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 27/35] serial: make usb_serial_driver::chars_in_buffer return uint

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

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

Johan

2021-05-19 19:24:37

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 23/35] USB: serial: make usb_serial_driver::write_room return uint

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

2021-05-19 19:25:11

by Johan Hovold

[permalink] [raw]
Subject: Re: [PATCH 29/35] USB: serial: digi_acceleport, simplify digi_chars_in_buffer

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

2021-06-10 09:04:52

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH v3 1/4] tty: make tty_get_{char,frame}_size available

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 <[email protected]>
Reviewed-by: Andy Shevchenko <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Johan Hovold <[email protected]>
---
[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

2021-06-10 09:05:26

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size

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 <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: David Lin <[email protected]>
Cc: Johan Hovold <[email protected]>
Cc: Alex Elder <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Andy Gross <[email protected]>
Cc: Bjorn Andersson <[email protected]>
Cc: Maxime Coquelin <[email protected]>
Cc: Alexandre Torgue <[email protected]>
Cc: Oliver Neukum <[email protected]>
---
[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

2021-06-10 09:06:29

by Jiri Slaby

[permalink] [raw]
Subject: [PATCH v3 2/4] mxs-auart: redefine AUART_LINECTRL_WLEN to accept bits count

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

2021-06-10 15:18:47

by Alex Elder

[permalink] [raw]
Subject: Re: [PATCH v3 4/4] tty: make use of tty_get_{char,frame}_size

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

> Signed-off-by: Jiri Slaby <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: David Lin <[email protected]>
> Cc: Johan Hovold <[email protected]>
> Cc: Alex Elder <[email protected]>
> Cc: Shawn Guo <[email protected]>
> Cc: Sascha Hauer <[email protected]>
> Cc: Andy Gross <[email protected]>
> Cc: Bjorn Andersson <[email protected]>
> Cc: Maxime Coquelin <[email protected]>
> Cc: Alexandre Torgue <[email protected]>
> Cc: Oliver Neukum <[email protected]>