From 39b7b42be4a82f036c392abc71724b4b7752ac03 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Fri, 23 Jul 2021 09:43:13 +0200 Subject: tty: stop using alloc_tty_driver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Cc: Richard Henderson (odd fixer:ALPHA PORT) Cc: Ivan Kokshaysky Cc: Matt Turner Cc: Geert Uytterhoeven Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: Jeff Dike Cc: Richard Weinberger Cc: Anton Ivanov Cc: Chris Zankel Cc: Max Filippov 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: Laurentiu Tudor Cc: Jiri Kosina Cc: David Sterba Cc: Shawn Guo Cc: Sascha Hauer Cc: Oliver Neukum Cc: Felipe Balbi Cc: Johan Hovold Cc: Marcel Holtmann Cc: Johan Hedberg Cc: Luiz Augusto von Dentz Acked-by: Samuel Iglesias Gonsálvez Acked-by: Max Filippov Acked-by: David Sterba Acked-by: Christian Borntraeger Signed-off-by: Jiri Slaby Link: https://lore.kernel.org/r/20210723074317.32690-5-jslaby@suse.cz Signed-off-by: Greg Kroah-Hartman --- 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 +++--- 14 files changed, 56 insertions(+), 58 deletions(-) (limited to 'drivers/tty') diff --git a/drivers/tty/amiserial.c b/drivers/tty/amiserial.c index bfd3acc1ecfa..50f1a54ef35a 100644 --- a/drivers/tty/amiserial.c +++ b/drivers/tty/amiserial.c @@ -1494,9 +1494,9 @@ static int __init amiga_serial_probe(struct platform_device *pdev) unsigned long flags; int error; - driver = alloc_tty_driver(1); - if (!driver) - return -ENOMEM; + driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW); + if (IS_ERR(driver)) + return PTR_ERR(driver); /* Initialize the tty_driver structure */ @@ -1509,7 +1509,6 @@ static int __init amiga_serial_probe(struct platform_device *pdev) driver->init_termios = tty_std_termios; driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; - driver->flags = TTY_DRIVER_REAL_RAW; tty_set_operations(driver, &serial_ops); memset(state, 0, sizeof(*state)); diff --git a/drivers/tty/ehv_bytechan.c b/drivers/tty/ehv_bytechan.c index 97ae940af478..f580a5de3c98 100644 --- a/drivers/tty/ehv_bytechan.c +++ b/drivers/tty/ehv_bytechan.c @@ -774,9 +774,10 @@ static int __init ehv_bc_init(void) if (!bcs) return -ENOMEM; - driver = alloc_tty_driver(count); - if (!driver) { - ret = -ENOMEM; + driver = tty_alloc_driver(count, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(driver)) { + ret = PTR_ERR(driver); goto err_free_bcs; } @@ -785,7 +786,6 @@ static int __init ehv_bc_init(void) driver->type = TTY_DRIVER_TYPE_CONSOLE; driver->subtype = SYSTEM_TYPE_CONSOLE; driver->init_termios = tty_std_termios; - driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; tty_set_operations(driver, &ehv_bc_ops); ret = tty_register_driver(driver); diff --git a/drivers/tty/goldfish.c b/drivers/tty/goldfish.c index ccb683a6e6f5..853083fcebb8 100644 --- a/drivers/tty/goldfish.c +++ b/drivers/tty/goldfish.c @@ -253,18 +253,18 @@ static int goldfish_tty_create_driver(void) ret = -ENOMEM; goto err_alloc_goldfish_ttys_failed; } - tty = alloc_tty_driver(goldfish_tty_line_count); - if (tty == NULL) { - ret = -ENOMEM; - goto err_alloc_tty_driver_failed; + tty = tty_alloc_driver(goldfish_tty_line_count, + TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(tty)) { + ret = PTR_ERR(tty); + goto err_tty_alloc_driver_failed; } tty->driver_name = "goldfish"; tty->name = "ttyGF"; tty->type = TTY_DRIVER_TYPE_SERIAL; tty->subtype = SERIAL_TYPE_NORMAL; tty->init_termios = tty_std_termios; - tty->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | - TTY_DRIVER_DYNAMIC_DEV; tty_set_operations(tty, &goldfish_tty_ops); ret = tty_register_driver(tty); if (ret) @@ -275,7 +275,7 @@ static int goldfish_tty_create_driver(void) err_tty_register_driver_failed: put_tty_driver(tty); -err_alloc_tty_driver_failed: +err_tty_alloc_driver_failed: kfree(goldfish_ttys); goldfish_ttys = NULL; err_alloc_goldfish_ttys_failed: diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 5bb8c4e44961..9215dd4bd9f0 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c @@ -1021,9 +1021,10 @@ static int hvc_init(void) int err; /* We need more than hvc_count adapters due to hotplug additions. */ - drv = alloc_tty_driver(HVC_ALLOC_TTY_ADAPTERS); - if (!drv) { - err = -ENOMEM; + drv = tty_alloc_driver(HVC_ALLOC_TTY_ADAPTERS, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_RESET_TERMIOS); + if (IS_ERR(drv)) { + err = PTR_ERR(drv); goto out; } @@ -1033,7 +1034,6 @@ static int hvc_init(void) drv->minor_start = HVC_MINOR; drv->type = TTY_DRIVER_TYPE_SYSTEM; drv->init_termios = tty_std_termios; - drv->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS; tty_set_operations(drv, &hvc_ops); /* Always start the kthread because there can be hotplug vty adapters diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c index fe5e6b4f43de..23aebc964201 100644 --- a/drivers/tty/hvc/hvcs.c +++ b/drivers/tty/hvc/hvcs.c @@ -1445,10 +1445,11 @@ static int hvcs_initialize(void) } else num_ttys_to_alloc = hvcs_parm_num_devs; - hvcs_tty_driver = alloc_tty_driver(num_ttys_to_alloc); - if (!hvcs_tty_driver) { + hvcs_tty_driver = tty_alloc_driver(num_ttys_to_alloc, + TTY_DRIVER_REAL_RAW); + if (IS_ERR(hvcs_tty_driver)) { mutex_unlock(&hvcs_init_mutex); - return -ENOMEM; + return PTR_ERR(hvcs_tty_driver); } if (hvcs_alloc_index_list(num_ttys_to_alloc)) { @@ -1473,7 +1474,6 @@ static int hvcs_initialize(void) * throw us into a horrible recursive echo-echo-echo loop. */ hvcs_tty_driver->init_termios = hvcs_tty_termios; - hvcs_tty_driver->flags = TTY_DRIVER_REAL_RAW; tty_set_operations(hvcs_tty_driver, &hvcs_ops); diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c index bfde7b1936a5..aa81f4835fef 100644 --- a/drivers/tty/hvc/hvsi.c +++ b/drivers/tty/hvc/hvsi.c @@ -1041,9 +1041,9 @@ static int __init hvsi_init(void) struct tty_driver *driver; int i, ret; - driver = alloc_tty_driver(hvsi_count); - if (!driver) - return -ENOMEM; + driver = tty_alloc_driver(hvsi_count, TTY_DRIVER_REAL_RAW); + if (IS_ERR(driver)) + return PTR_ERR(driver); driver->driver_name = "hvsi"; driver->name = "hvsi"; @@ -1054,7 +1054,6 @@ static int __init hvsi_init(void) driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL; driver->init_termios.c_ispeed = 9600; driver->init_termios.c_ospeed = 9600; - driver->flags = TTY_DRIVER_REAL_RAW; tty_set_operations(driver, &hvsi_ops); for (i=0; i < hvsi_count; i++) { diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c index e3a5a5ba752c..d24404c222e0 100644 --- a/drivers/tty/ipwireless/tty.c +++ b/drivers/tty/ipwireless/tty.c @@ -564,9 +564,10 @@ int ipwireless_tty_init(void) { int result; - ipw_tty_driver = alloc_tty_driver(IPWIRELESS_PCMCIA_MINORS); - if (!ipw_tty_driver) - return -ENOMEM; + ipw_tty_driver = tty_alloc_driver(IPWIRELESS_PCMCIA_MINORS, + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(ipw_tty_driver)) + return PTR_ERR(ipw_tty_driver); ipw_tty_driver->driver_name = IPWIRELESS_PCCARD_NAME; ipw_tty_driver->name = "ttyIPWp"; @@ -574,7 +575,6 @@ int ipwireless_tty_init(void) ipw_tty_driver->minor_start = IPWIRELESS_PCMCIA_START; ipw_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; ipw_tty_driver->subtype = SERIAL_TYPE_NORMAL; - ipw_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; ipw_tty_driver->init_termios = tty_std_termios; ipw_tty_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c index 900ccb2ca166..650fc6fac88e 100644 --- a/drivers/tty/mxser.c +++ b/drivers/tty/mxser.c @@ -1976,9 +1976,10 @@ static int __init mxser_module_init(void) { int retval; - mxvar_sdriver = alloc_tty_driver(MXSER_PORTS); - if (!mxvar_sdriver) - return -ENOMEM; + mxvar_sdriver = tty_alloc_driver(MXSER_PORTS, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(mxvar_sdriver)) + return PTR_ERR(mxvar_sdriver); /* Initialize the tty_driver structure */ mxvar_sdriver->name = "ttyMI"; @@ -1988,7 +1989,6 @@ static int __init mxser_module_init(void) mxvar_sdriver->subtype = SERIAL_TYPE_NORMAL; mxvar_sdriver->init_termios = tty_std_termios; mxvar_sdriver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL; - mxvar_sdriver->flags = TTY_DRIVER_REAL_RAW|TTY_DRIVER_DYNAMIC_DEV; tty_set_operations(mxvar_sdriver, &mxser_ops); retval = tty_register_driver(mxvar_sdriver); diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c index e907b7a5cab5..0308669c21c6 100644 --- a/drivers/tty/n_gsm.c +++ b/drivers/tty/n_gsm.c @@ -3252,10 +3252,11 @@ static int __init gsm_init(void) return status; } - gsm_tty_driver = alloc_tty_driver(256); - if (!gsm_tty_driver) { + gsm_tty_driver = tty_alloc_driver(256, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK); + if (IS_ERR(gsm_tty_driver)) { pr_err("gsm_init: tty allocation failed.\n"); - status = -ENOMEM; + status = PTR_ERR(gsm_tty_driver); goto err_unreg_ldisc; } gsm_tty_driver->driver_name = "gsmtty"; @@ -3264,8 +3265,6 @@ static int __init gsm_init(void) gsm_tty_driver->minor_start = 0; gsm_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; gsm_tty_driver->subtype = SERIAL_TYPE_NORMAL; - gsm_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV - | TTY_DRIVER_HARDWARE_BREAK; gsm_tty_driver->init_termios = tty_std_termios; /* Fixme */ gsm_tty_driver->init_termios.c_lflag &= ~ECHO; diff --git a/drivers/tty/nozomi.c b/drivers/tty/nozomi.c index 0c80f25c8c3d..f3eb0aaec79b 100644 --- a/drivers/tty/nozomi.c +++ b/drivers/tty/nozomi.c @@ -1824,16 +1824,16 @@ static __init int nozomi_init(void) { int ret; - ntty_driver = alloc_tty_driver(NTTY_TTY_MAXMINORS); - if (!ntty_driver) - return -ENOMEM; + ntty_driver = tty_alloc_driver(NTTY_TTY_MAXMINORS, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(ntty_driver)) + return PTR_ERR(ntty_driver); ntty_driver->driver_name = NOZOMI_NAME_TTY; ntty_driver->name = "noz"; ntty_driver->major = 0; ntty_driver->type = TTY_DRIVER_TYPE_SERIAL; ntty_driver->subtype = SERIAL_TYPE_NORMAL; - ntty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; ntty_driver->init_termios = tty_std_termios; ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \ HUPCL | CLOCAL; diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c index 3e7c6ee8e4b3..9209573a7e37 100644 --- a/drivers/tty/serial/kgdb_nmi.c +++ b/drivers/tty/serial/kgdb_nmi.c @@ -330,17 +330,16 @@ int kgdb_register_nmi_console(void) if (!arch_kgdb_ops.enable_nmi) return 0; - kgdb_nmi_tty_driver = alloc_tty_driver(1); - if (!kgdb_nmi_tty_driver) { + kgdb_nmi_tty_driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW); + if (IS_ERR(kgdb_nmi_tty_driver)) { pr_err("%s: cannot allocate tty\n", __func__); - return -ENOMEM; + return PTR_ERR(kgdb_nmi_tty_driver); } kgdb_nmi_tty_driver->driver_name = "ttyNMI"; kgdb_nmi_tty_driver->name = "ttyNMI"; kgdb_nmi_tty_driver->num = 1; kgdb_nmi_tty_driver->type = TTY_DRIVER_TYPE_SERIAL; kgdb_nmi_tty_driver->subtype = SERIAL_TYPE_NORMAL; - kgdb_nmi_tty_driver->flags = TTY_DRIVER_REAL_RAW; kgdb_nmi_tty_driver->init_termios = tty_std_termios; tty_termios_encode_baud_rate(&kgdb_nmi_tty_driver->init_termios, KGDB_NMI_BAUD, KGDB_NMI_BAUD); diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 79bd2f44d765..eb1401b61a90 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -2530,9 +2530,12 @@ int uart_register_driver(struct uart_driver *drv) if (!drv->state) goto out; - normal = alloc_tty_driver(drv->nr); - if (!normal) + normal = tty_alloc_driver(drv->nr, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(normal)) { + retval = PTR_ERR(normal); goto out_kfree; + } drv->tty_driver = normal; @@ -2545,7 +2548,6 @@ int uart_register_driver(struct uart_driver *drv) normal->init_termios = tty_std_termios; normal->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; normal->init_termios.c_ispeed = normal->init_termios.c_ospeed = 9600; - normal->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; normal->driver_state = drv; tty_set_operations(normal, &uart_ops); diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c index 5bb928b7873e..525f3a568c32 100644 --- a/drivers/tty/synclink_gt.c +++ b/drivers/tty/synclink_gt.c @@ -3689,10 +3689,11 @@ static int __init slgt_init(void) printk(KERN_INFO "%s\n", driver_name); - serial_driver = alloc_tty_driver(MAX_DEVICES); - if (!serial_driver) { + serial_driver = tty_alloc_driver(MAX_DEVICES, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_DYNAMIC_DEV); + if (IS_ERR(serial_driver)) { printk("%s can't allocate tty driver\n", driver_name); - return -ENOMEM; + return PTR_ERR(serial_driver); } /* Initialize the tty_driver structure */ @@ -3708,7 +3709,6 @@ static int __init slgt_init(void) B9600 | CS8 | CREAD | HUPCL | CLOCAL; serial_driver->init_termios.c_ispeed = 9600; serial_driver->init_termios.c_ospeed = 9600; - serial_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; tty_set_operations(serial_driver, &ops); if ((rc = tty_register_driver(serial_driver)) < 0) { DBGERR(("%s can't register serial driver\n", driver_name)); diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c index 484eda1958f5..23230cf44b1f 100644 --- a/drivers/tty/vt/vt.c +++ b/drivers/tty/vt/vt.c @@ -3576,8 +3576,9 @@ int __init vty_init(const struct file_operations *console_fops) vcs_init(); - console_driver = alloc_tty_driver(MAX_NR_CONSOLES); - if (!console_driver) + console_driver = tty_alloc_driver(MAX_NR_CONSOLES, TTY_DRIVER_REAL_RAW | + TTY_DRIVER_RESET_TERMIOS); + if (IS_ERR(console_driver)) panic("Couldn't allocate console driver\n"); console_driver->name = "tty"; @@ -3588,7 +3589,6 @@ int __init vty_init(const struct file_operations *console_fops) console_driver->init_termios = tty_std_termios; if (default_utf8) console_driver->init_termios.c_iflag |= IUTF8; - console_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_RESET_TERMIOS; tty_set_operations(console_driver, &con_ops); if (tty_register_driver(console_driver)) panic("Couldn't register console driver\n"); -- cgit v1.2.3