From ed5aecd3da2eabd8a6c9f5593df2c4f00985fca2 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:18:54 +0200 Subject: tty: remove broken r3964 line discipline Noone stepped up in the past two years since it was marked as BROKEN by commit c7084edc3f6d (tty: mark Siemens R3964 line discipline as BROKEN). Remove the line discipline for good. Three remarks: * we remove also the uapi header (as noone is able to use that interface anyway) * we do *not* remove the N_R3964 constant definition from tty.h, so it remains reserved. * in_interrupt() check is now removed from vt's con_put_char. Noone else calls tty_operations::put_char from interrupt context. Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20210505091928.22010-2-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/char/Kconfig | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index b151e0fcdeb5..52d0dd49a683 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig @@ -218,19 +218,6 @@ config XILINX_HWICAP If unsure, say N. -config R3964 - tristate "Siemens R3964 line discipline" - depends on TTY && BROKEN - help - This driver allows synchronous communication with devices using the - Siemens R3964 packet protocol. Unless you are dealing with special - hardware like PLCs, you are unlikely to need this. - - To compile this driver as a module, choose M here: the - module will be called n_r3964. - - If unsure, say N. - config APPLICOM tristate "Applicom intelligent fieldbus card support" depends on PCI -- cgit From 6e94dbc7a4e49a028b81302d755bba1a518f973b Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:05 +0200 Subject: tty: cumulate and document tty_struct::flow* members Group the flow flags under a single struct called flow. The new struct contains 'stopped' and 'tco_stopped' bools which used to be bits in a bitfield. The struct also contains the lock protecting them to potentially share the same cache line. Note that commit c545b66c6922b (tty: Serialize tcflow() with other tty flow control changes) added a padding to the original bitfield. It was for the bitfield to occupy a whole 64b word to avoid interferring stores on Alpha (cannot we evaporate this arch with weird implications to C code yet?). But it doesn't work as expected as the padding (tty_struct::unused) is aligned to a 8B boundary too and occupies some bytes from the next word. So make it reliable by: 1) setting __aligned of the struct -- that aligns the start, and 2) making 'unsigned long unused[0]' as the last member of the struct -- pads the end. This is also the perfect time to start the documentation of tty_struct where all this lives. So we start by documenting what these bools actually serve for. And why we do all the alignment dances. Only the few up-to-date information from the Theodore's comment made it into this new Kerneldoc comment. Signed-off-by: Jiri Slaby Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Jonathan Corbet Cc: Arnd Bergmann Cc: Ulf Hansson Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger Cc: Shawn Guo Cc: Sascha Hauer Cc: Vineet Gupta Cc: "Maciej W. Rozycki" Link: https://lore.kernel.org/r/20210505091928.22010-13-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/char/pcmcia/synclink_cs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index 3287a7627ed0..b4707bc3aee8 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -985,7 +985,7 @@ static void tx_done(MGSLPC_INFO *info, struct tty_struct *tty) else #endif { - if (tty && (tty->stopped || tty->hw_stopped)) { + if (tty && (tty->flow.stopped || tty->hw_stopped)) { tx_stop(info); return; } @@ -1005,7 +1005,7 @@ static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty) if (!info->tx_active) return; } else { - if (tty && (tty->stopped || tty->hw_stopped)) { + if (tty && (tty->flow.stopped || tty->hw_stopped)) { tx_stop(info); return; } @@ -1525,7 +1525,7 @@ static void mgslpc_flush_chars(struct tty_struct *tty) if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_chars")) return; - if (info->tx_count <= 0 || tty->stopped || + if (info->tx_count <= 0 || tty->flow.stopped || tty->hw_stopped || !info->tx_buf) return; @@ -1594,7 +1594,7 @@ static int mgslpc_write(struct tty_struct * tty, ret += c; } start: - if (info->tx_count && !tty->stopped && !tty->hw_stopped) { + if (info->tx_count && !tty->flow.stopped && !tty->hw_stopped) { spin_lock_irqsave(&info->lock, flags); if (!info->tx_active) tx_start(info, tty); -- cgit From 03b3b1a2405ccd71570cd5ec1fe4abd7bb4891cb Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:15 +0200 Subject: tty: make tty_operations::write_room return uint Line disciplines expect a positive value or zero returned from tty->ops->write_room (invoked by tty_write_room). So make this assumption explicit by using unsigned int as a return value. Both of tty->ops->write_room and tty_write_room. Signed-off-by: Jiri Slaby Acked-by: Laurentiu Tudor Acked-by: Alex Elder Acked-by: Max Filippov # xtensa Acked-by: David Sterba Acked-By: Anton Ivanov Acked-by: Geert Uytterhoeven Cc: Richard Henderson Cc: Ivan Kokshaysky Cc: Matt Turner Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: Jeff Dike Cc: Richard Weinberger Cc: Chris Zankel Cc: Arnd Bergmann Cc: Samuel Iglesias Gonsalvez Cc: Jens Taprogge Cc: Karsten Keil Cc: Scott Branden Cc: Ulf Hansson Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger Cc: David Lin Cc: Johan Hovold Cc: Jiri Kosina Cc: Shawn Guo Cc: Sascha Hauer Cc: Oliver Neukum Cc: Felipe Balbi Cc: Mathias Nyman Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Link: https://lore.kernel.org/r/20210505091928.22010-23-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/char/pcmcia/synclink_cs.c | 2 +- drivers/char/ttyprintk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index b4707bc3aee8..e4b2c68f44f5 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -1609,7 +1609,7 @@ cleanup: /* Return the count of free bytes in transmit buffer */ -static int mgslpc_write_room(struct tty_struct *tty) +static unsigned int mgslpc_write_room(struct tty_struct *tty) { MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data; int ret; diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c index 93f5d11c830b..e93b0af92339 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -132,7 +132,7 @@ static int tpk_write(struct tty_struct *tty, /* * TTY operations write_room function. */ -static int tpk_write_room(struct tty_struct *tty) +static unsigned int tpk_write_room(struct tty_struct *tty) { return TPK_MAX_ROOM; } -- cgit From fff4ef17a9400fcd276b5c3a00ce5793f6c465e6 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Wed, 5 May 2021 11:19:19 +0200 Subject: tty: make tty_operations::chars_in_buffer return uint tty_operations::chars_in_buffer is another hook which is expected to return values >= 0. So make it explicit by the return type too -- use unsigned int. Signed-off-by: Jiri Slaby Acked-By: Anton Ivanov Acked-by: David Sterba Cc: Jeff Dike Cc: Richard Weinberger Cc: Arnd Bergmann Cc: Samuel Iglesias Gonsalvez Cc: Jens Taprogge Cc: Karsten Keil Cc: Ulf Hansson Cc: "David S. Miller" Cc: Jakub Kicinski Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger Cc: David Lin Cc: Johan Hovold Cc: Alex Elder Cc: Jiri Kosina Cc: Shawn Guo Cc: Sascha Hauer Cc: Oliver Neukum Cc: Felipe Balbi Cc: Mathias Nyman Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Link: https://lore.kernel.org/r/20210505091928.22010-27-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/char/pcmcia/synclink_cs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c index e4b2c68f44f5..9f7420bc5026 100644 --- a/drivers/char/pcmcia/synclink_cs.c +++ b/drivers/char/pcmcia/synclink_cs.c @@ -1637,10 +1637,10 @@ static unsigned int mgslpc_write_room(struct tty_struct *tty) /* Return the count of bytes in transmit buffer */ -static int mgslpc_chars_in_buffer(struct tty_struct *tty) +static unsigned int mgslpc_chars_in_buffer(struct tty_struct *tty) { MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data; - int rc; + unsigned int rc; if (debug_level >= DEBUG_LEVEL_INFO) printk("%s(%d):mgslpc_chars_in_buffer(%s)\n", @@ -1655,7 +1655,7 @@ static int mgslpc_chars_in_buffer(struct tty_struct *tty) rc = info->tx_count; if (debug_level >= DEBUG_LEVEL_INFO) - printk("%s(%d):mgslpc_chars_in_buffer(%s)=%d\n", + printk("%s(%d):mgslpc_chars_in_buffer(%s)=%u\n", __FILE__, __LINE__, info->device_name, rc); return rc; -- cgit From bf3d6ab9bc1295fdf37cbc363ba9f7dfa14a84b8 Mon Sep 17 00:00:00 2001 From: Samo Pogačnik Date: Tue, 27 Apr 2021 13:40:51 +0200 Subject: ttyprintk: Add TTY port shutdown callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By adding the TTY port shutdown callback, the final buffer flush has been moved from tpk_close() to tpk_port_shutdown(). This enables buffer flush upon close and hangup as well. The change also removes the specific 'buf == NULL' handling in tpk_printk(), which became useless. Signed-off-by: Samo Pogačnik Link: https://lore.kernel.org/r/f236ea26520fbef176fefec2e06a43548f63fa9c.camel@t-2.net Signed-off-by: Greg Kroah-Hartman --- drivers/char/ttyprintk.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c index e93b0af92339..620065b6cef9 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -54,11 +54,6 @@ static int tpk_printk(const unsigned char *buf, int count) { int i = tpk_curr; - if (buf == NULL) { - tpk_flush(); - return i; - } - for (i = 0; i < count; i++) { if (tpk_curr >= TPK_STR_SIZE) { /* end of tmp buffer reached: cut the message in two */ @@ -100,12 +95,6 @@ static int tpk_open(struct tty_struct *tty, struct file *filp) static void tpk_close(struct tty_struct *tty, struct file *filp) { struct ttyprintk_port *tpkp = tty->driver_data; - unsigned long flags; - - spin_lock_irqsave(&tpkp->spinlock, flags); - /* flush tpk_printk buffer */ - tpk_printk(NULL, 0); - spin_unlock_irqrestore(&tpkp->spinlock, flags); tty_port_close(&tpkp->port, tty, filp); } @@ -168,6 +157,20 @@ static void tpk_hangup(struct tty_struct *tty) tty_port_hangup(&tpkp->port); } +/* + * TTY port operations shutdown function. + */ +static void tpk_port_shutdown(struct tty_port *tport) +{ + struct ttyprintk_port *tpkp = + container_of(tport, struct ttyprintk_port, port); + unsigned long flags; + + spin_lock_irqsave(&tpkp->spinlock, flags); + tpk_flush(); + spin_unlock_irqrestore(&tpkp->spinlock, flags); +} + static const struct tty_operations ttyprintk_ops = { .open = tpk_open, .close = tpk_close, @@ -177,7 +180,9 @@ static const struct tty_operations ttyprintk_ops = { .hangup = tpk_hangup, }; -static const struct tty_port_operations null_ops = { }; +static const struct tty_port_operations tpk_port_ops = { + .shutdown = tpk_port_shutdown, +}; static struct tty_driver *ttyprintk_driver; @@ -195,7 +200,7 @@ static int __init ttyprintk_init(void) return PTR_ERR(ttyprintk_driver); tty_port_init(&tpk_port.port); - tpk_port.port.ops = &null_ops; + tpk_port.port.ops = &tpk_port_ops; ttyprintk_driver->driver_name = "ttyprintk"; ttyprintk_driver->name = "ttyprintk"; -- cgit From 2fee8811219793cb16ed3f09b5629bb5c78e7dbb Mon Sep 17 00:00:00 2001 From: Samo Pogačnik Date: Tue, 27 Apr 2021 13:43:26 +0200 Subject: ttyprintk: Removed unnecessary TTY ioctl callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turns-out, that TIOCCONS is completely handled in tty_io.c, so the current local ioctl callback is of no real use. Signed-off-by: Samo Pogačnik Link: https://lore.kernel.org/r/1502946c760b1aae3ad9cffcf4ea3b9f37206585.camel@t-2.net Signed-off-by: Greg Kroah-Hartman --- drivers/char/ttyprintk.c | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'drivers/char') diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c index 620065b6cef9..219fa1382396 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -109,7 +109,6 @@ static int tpk_write(struct tty_struct *tty, unsigned long flags; int ret; - /* exclusive use of tpk_printk within this tty */ spin_lock_irqsave(&tpkp->spinlock, flags); ret = tpk_printk(buf, count); @@ -126,27 +125,6 @@ static unsigned int tpk_write_room(struct tty_struct *tty) return TPK_MAX_ROOM; } -/* - * TTY operations ioctl function. - */ -static int tpk_ioctl(struct tty_struct *tty, - unsigned int cmd, unsigned long arg) -{ - struct ttyprintk_port *tpkp = tty->driver_data; - - if (!tpkp) - return -EINVAL; - - switch (cmd) { - /* Stop TIOCCONS */ - case TIOCCONS: - return -EOPNOTSUPP; - default: - return -ENOIOCTLCMD; - } - return 0; -} - /* * TTY operations hangup function. */ @@ -176,7 +154,6 @@ static const struct tty_operations ttyprintk_ops = { .close = tpk_close, .write = tpk_write, .write_room = tpk_write_room, - .ioctl = tpk_ioctl, .hangup = tpk_hangup, }; -- cgit From 18c092e5c35ece7fa1fe0b2c6f8c4a13da3fc641 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Tue, 18 May 2021 19:21:26 +0100 Subject: ttyprintk: remove redundant initialization of variable i The variable i is being initialized with a value that is never read, it is being updated later on. The assignment is redundant and can be removed. Signed-off-by: Colin Ian King Addresses-Coverity: ("Unused value") Link: https://lore.kernel.org/r/20210518182126.140978-1-colin.king@canonical.com Signed-off-by: Greg Kroah-Hartman --- drivers/char/ttyprintk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/char') diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c index 219fa1382396..230b2c9b3e3c 100644 --- a/drivers/char/ttyprintk.c +++ b/drivers/char/ttyprintk.c @@ -52,7 +52,7 @@ static void tpk_flush(void) static int tpk_printk(const unsigned char *buf, int count) { - int i = tpk_curr; + int i; for (i = 0; i < count; i++) { if (tpk_curr >= TPK_STR_SIZE) { -- cgit From 3ec2ff37230e1c961d4b0d0118dd23c46b5bcdbb Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Thu, 10 Jun 2021 11:02:47 +0200 Subject: 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. Cc: Arnd Bergmann Cc: David Lin Cc: Johan Hovold Cc: Alex Elder Cc: Shawn Guo Cc: Sascha Hauer Cc: Andy Gross Cc: Bjorn Andersson Cc: Maxime Coquelin Cc: Alexandre Torgue Cc: Oliver Neukum Acked-by: Alex Elder Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20210610090247.2593-4-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- drivers/char/pcmcia/synclink_cs.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'drivers/char') 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; -- cgit