mbox series

[0/8] Get rid of old tty_driver functions

Message ID 20210723074317.32690-1-jslaby@suse.cz
Headers show
Series Get rid of old tty_driver functions | expand

Message

Jiri Slaby July 23, 2021, 7:43 a.m. UTC
This series converts the rest of the drivers to use:
* tty_alloc_driver instead of alloc_tty_driver, and
* tty_driver_kref_put instead of put_tty_driver.

They were more of less interchangeable, alloc_tty_driver() and
put_tty_driver() are older interfaces which weren't eliminated until
now.

There are few fix and cleanup patches around tty_driver too.

Jiri Slaby (8):
  xtensa: ISS: don't panic in rs_init
  hvsi: don't panic on tty_register_driver failure
  tty: don't store semi-state into tty drivers
  tty: stop using alloc_tty_driver
  tty: drop alloc_tty_driver
  tty: make tty_set_operations an inline
  tty: drop put_tty_driver
  tty: pdc_cons, free tty_driver upon failure

 arch/alpha/kernel/srmcons.c            |  8 ++--
 arch/m68k/emu/nfcon.c                  | 30 +++++++-------
 arch/parisc/kernel/pdc_cons.c          | 34 ++++++++--------
 arch/um/drivers/line.c                 | 13 +++---
 arch/xtensa/platforms/iss/console.c    | 45 +++++++++++++--------
 drivers/char/pcmcia/synclink_cs.c      |  4 +-
 drivers/char/ttyprintk.c               |  4 +-
 drivers/ipack/devices/ipoctal.c        | 13 +++---
 drivers/isdn/capi/capi.c               | 14 +++----
 drivers/misc/bcm-vk/bcm_vk_tty.c       |  8 ++--
 drivers/mmc/core/sdio_uart.c           | 12 +++---
 drivers/net/usb/hso.c                  | 12 +++---
 drivers/s390/char/con3215.c            | 11 +++---
 drivers/s390/char/sclp_tty.c           | 15 ++++---
 drivers/s390/char/sclp_vt220.c         |  9 ++---
 drivers/s390/char/tty3270.c            |  4 +-
 drivers/staging/fwserial/fwserial.c    |  8 ++--
 drivers/staging/gdm724x/gdm_tty.c      | 13 +++---
 drivers/staging/greybus/uart.c         |  4 +-
 drivers/tty/amiserial.c                | 42 ++++++++++----------
 drivers/tty/ehv_bytechan.c             | 34 +++++++++-------
 drivers/tty/goldfish.c                 | 18 ++++-----
 drivers/tty/hvc/hvc_console.c          | 10 ++---
 drivers/tty/hvc/hvcs.c                 | 12 +++---
 drivers/tty/hvc/hvsi.c                 | 55 ++++++++++++++++----------
 drivers/tty/ipwireless/tty.c           | 12 +++---
 drivers/tty/mips_ejtag_fdc.c           |  2 +-
 drivers/tty/moxa.c                     |  4 +-
 drivers/tty/mxser.c                    | 12 +++---
 drivers/tty/n_gsm.c                    | 13 +++---
 drivers/tty/nozomi.c                   | 12 +++---
 drivers/tty/serial/kgdb_nmi.c          | 11 +++---
 drivers/tty/serial/serial_core.c       | 12 +++---
 drivers/tty/synclink_gt.c              | 12 +++---
 drivers/tty/tty_io.c                   | 13 ------
 drivers/tty/ttynull.c                  |  4 +-
 drivers/tty/vcc.c                      |  4 +-
 drivers/tty/vt/vt.c                    |  6 +--
 drivers/usb/class/cdc-acm.c            | 14 +++----
 drivers/usb/gadget/function/u_serial.c | 36 +++++++++--------
 drivers/usb/host/xhci-dbgtty.c         |  4 +-
 drivers/usb/serial/usb-serial.c        | 13 +++---
 include/linux/tty_driver.h             | 21 +++-------
 net/bluetooth/rfcomm/tty.c             | 12 +++---
 44 files changed, 330 insertions(+), 319 deletions(-)

Comments

Samuel Iglesias Gonsálvez July 23, 2021, 7:49 a.m. UTC | #1
On Fri, 2021-07-23 at 09:43 +0200, Jiri Slaby wrote:
> alloc_tty_driver was deprecated by tty_alloc_driver in commit
> 7f0bc6a68ed9 (TTY: pass flags to alloc_tty_driver) in 2012.
> 
> I never got into eliminating alloc_tty_driver until now. So we still
> have two functions for allocating drivers which might be confusing.
> So
> get rid of alloc_tty_driver uses to eliminate it for good in the next
> patch.
> 
> Note we need to switch return value checking as tty_alloc_driver uses
> ERR_PTR. And flags are now a parameter of tty_alloc_driver.
> 
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Richard Henderson <rth@twiddle.net>(odd fixer:ALPHA PORT)
> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
> Cc: Matt Turner <mattst88@gmail.com>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Jeff Dike <jdike@addtoit.com>
> Cc: Richard Weinberger <richard@nod.at>
> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Samuel Iglesias Gonsalvez <siglesias@igalia.com>
> Cc: Jens Taprogge <jens.taprogge@taprogge.org>
> Cc: Karsten Keil <isdn@linux-pingi.de>
> Cc: Ulf Hansson <ulf.hansson@linaro.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Heiko Carstens <hca@linux.ibm.com>
> Cc: Vasily Gorbik <gor@linux.ibm.com>
> Cc: Christian Borntraeger <borntraeger@de.ibm.com>
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Cc: Jiri Kosina <jikos@kernel.org>
> Cc: David Sterba <dsterba@suse.com>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: Sascha Hauer <s.hauer@pengutronix.de>
> Cc: Oliver Neukum <oneukum@suse.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> Cc: Johan Hovold <johan@kernel.org>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
> ---
>  arch/alpha/kernel/srmcons.c            |  6 +++---
>  arch/m68k/emu/nfcon.c                  |  7 +++----
>  arch/parisc/kernel/pdc_cons.c          |  9 ++++-----
>  arch/um/drivers/line.c                 | 11 ++++++-----
>  arch/xtensa/platforms/iss/console.c    |  7 +++----
>  drivers/ipack/devices/ipoctal.c        |  9 ++++-----
>  drivers/isdn/capi/capi.c               | 10 ++++------
>  drivers/mmc/core/sdio_uart.c           |  8 ++++----
>  drivers/net/usb/hso.c                  |  8 ++++----
>  drivers/s390/char/con3215.c            |  7 +++----
>  drivers/s390/char/sclp_tty.c           |  7 +++----
>  drivers/s390/char/sclp_vt220.c         |  7 +++----
>  drivers/staging/gdm724x/gdm_tty.c      |  9 ++++-----
>  drivers/tty/amiserial.c                |  7 +++----
>  drivers/tty/ehv_bytechan.c             |  8 ++++----
>  drivers/tty/goldfish.c                 | 14 +++++++-------
>  drivers/tty/hvc/hvc_console.c          |  8 ++++----
>  drivers/tty/hvc/hvcs.c                 |  8 ++++----
>  drivers/tty/hvc/hvsi.c                 |  7 +++----
>  drivers/tty/ipwireless/tty.c           |  8 ++++----
>  drivers/tty/mxser.c                    |  8 ++++----
>  drivers/tty/n_gsm.c                    |  9 ++++-----
>  drivers/tty/nozomi.c                   |  8 ++++----
>  drivers/tty/serial/kgdb_nmi.c          |  7 +++----
>  drivers/tty/serial/serial_core.c       |  8 +++++---
>  drivers/tty/synclink_gt.c              |  8 ++++----
>  drivers/tty/vt/vt.c                    |  6 +++---
>  drivers/usb/class/cdc-acm.c            |  8 ++++----
>  drivers/usb/gadget/function/u_serial.c |  8 ++++----
>  drivers/usb/serial/usb-serial.c        |  9 ++++-----
>  net/bluetooth/rfcomm/tty.c             |  8 ++++----
>  31 files changed, 120 insertions(+), 132 deletions(-)

For ipack changes:

Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>

Sam
Max Filippov July 23, 2021, 10:18 a.m. UTC | #2
On Fri, Jul 23, 2021 at 12:43 AM Jiri Slaby <jslaby@suse.cz> wrote:
>
> While alloc_tty_driver failure in rs_init would mean we have much bigger
> problem, there is no reason to panic when tty_register_driver fails
> there. It can fail for various reasons.
>
> So handle the failure gracefully. Actually handle them both while at it.
> This will make at least the console functional as it was enabled earlier
> by console_initcall in iss_console_init. Instead of shooting down the
> whole system.
>
> We move tty_port_init() after alloc_tty_driver(), so that we don't need
> to destroy the port in case the latter function fails.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: linux-xtensa@linux-xtensa.org
> ---
>  arch/xtensa/platforms/iss/console.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)

Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Max Filippov July 23, 2021, 10:30 a.m. UTC | #3
On Fri, Jul 23, 2021 at 12:43 AM Jiri Slaby <jslaby@suse.cz> wrote:
>
> alloc_tty_driver was deprecated by tty_alloc_driver in commit
> 7f0bc6a68ed9 (TTY: pass flags to alloc_tty_driver) in 2012.
>
> I never got into eliminating alloc_tty_driver until now. So we still
> have two functions for allocating drivers which might be confusing. So
> get rid of alloc_tty_driver uses to eliminate it for good in the next
> patch.
>
> Note we need to switch return value checking as tty_alloc_driver uses
> ERR_PTR. And flags are now a parameter of tty_alloc_driver.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>

>  arch/xtensa/platforms/iss/console.c    |  7 +++----

Acked-by: Max Filippov <jcmvbkbc@gmail.com>
Helge Deller July 23, 2021, 4:37 p.m. UTC | #4
On 7/23/21 9:43 AM, Jiri Slaby wrote:
> When a tty driver pointer is used as a return value of struct
> console's device() hook, don't store a semi-state into global variable
> which holds the tty driver. It could mean console::device() would return
> a bogus value. This is important esp. after the next patch where we
> switch from alloc_tty_driver to tty_alloc_driver. tty_alloc_driver
> returns ERR_PTR in case of error and that might have unexpected results
> as the code doesn't expect this.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
> Cc: Helge Deller <deller@gmx.de>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> Cc: Felipe Balbi <balbi@kernel.org>
> ---
>   arch/m68k/emu/nfcon.c                  | 27 +++++++++++---------
>   arch/parisc/kernel/pdc_cons.c          | 28 +++++++++++----------
>   arch/xtensa/platforms/iss/console.c    | 33 +++++++++++++-----------
>   drivers/tty/amiserial.c                | 35 ++++++++++++++------------
>   drivers/tty/ehv_bytechan.c             | 28 ++++++++++++---------
>   drivers/tty/hvc/hvsi.c                 | 35 ++++++++++++++------------
>   drivers/usb/gadget/function/u_serial.c | 32 ++++++++++++-----------
>   7 files changed, 119 insertions(+), 99 deletions(-)
>
...

You may add:

Acked-by: Helge Deller <deller@gmx.de>	# parisc

to the whole series (specifically patches 3, 4 and 8) regarding the parisc changes.

Thank you!
Helge

>
> diff --git a/arch/parisc/kernel/pdc_cons.c b/arch/parisc/kernel/pdc_cons.c
> index 39ccad063533..650cb01203de 100644
> --- a/arch/parisc/kernel/pdc_cons.c
> +++ b/arch/parisc/kernel/pdc_cons.c
> @@ -138,6 +138,7 @@ static struct tty_driver *pdc_console_tty_driver;
>
>   static int __init pdc_console_tty_driver_init(void)
>   {
> +	struct tty_driver *driver;
>   	int err;
>
>   	/* Check if the console driver is still registered.
> @@ -160,31 +161,32 @@ static int __init pdc_console_tty_driver_init(void)
>   	printk(KERN_INFO "The PDC console driver is still registered, removing CON_BOOT flag\n");
>   	pdc_cons.flags &= ~CON_BOOT;
>
> -	pdc_console_tty_driver = alloc_tty_driver(1);
> -
> -	if (!pdc_console_tty_driver)
> +	driver = alloc_tty_driver(1);
> +	if (!driver)
>   		return -ENOMEM;
>
>   	tty_port_init(&tty_port);
>
> -	pdc_console_tty_driver->driver_name = "pdc_cons";
> -	pdc_console_tty_driver->name = "ttyB";
> -	pdc_console_tty_driver->major = MUX_MAJOR;
> -	pdc_console_tty_driver->minor_start = 0;
> -	pdc_console_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
> -	pdc_console_tty_driver->init_termios = tty_std_termios;
> -	pdc_console_tty_driver->flags = TTY_DRIVER_REAL_RAW |
> +	driver->driver_name = "pdc_cons";
> +	driver->name = "ttyB";
> +	driver->major = MUX_MAJOR;
> +	driver->minor_start = 0;
> +	driver->type = TTY_DRIVER_TYPE_SYSTEM;
> +	driver->init_termios = tty_std_termios;
> +	driver->flags = TTY_DRIVER_REAL_RAW |
>   		TTY_DRIVER_RESET_TERMIOS;
> -	tty_set_operations(pdc_console_tty_driver, &pdc_console_tty_ops);
> -	tty_port_link_device(&tty_port, pdc_console_tty_driver, 0);
> +	tty_set_operations(driver, &pdc_console_tty_ops);
> +	tty_port_link_device(&tty_port, driver, 0);
>
> -	err = tty_register_driver(pdc_console_tty_driver);
> +	err = tty_register_driver(driver);
>   	if (err) {
>   		printk(KERN_ERR "Unable to register the PDC console TTY driver\n");
>   		tty_port_destroy(&tty_port);
>   		return err;
>   	}
>
> +	pdc_console_tty_driver = driver;
> +
>   	return 0;
>   }
>   device_initcall(pdc_console_tty_driver_init);
...
Greg KH July 27, 2021, 10:18 a.m. UTC | #5
On Fri, Jul 23, 2021 at 09:43:09AM +0200, Jiri Slaby wrote:
> This series converts the rest of the drivers to use:

> * tty_alloc_driver instead of alloc_tty_driver, and

> * tty_driver_kref_put instead of put_tty_driver.

> 

> They were more of less interchangeable, alloc_tty_driver() and

> put_tty_driver() are older interfaces which weren't eliminated until

> now.


Nice, thanks for cleaning this up!

greg k-h