tty: fixups for kernels 5.14 and 5.15
alloc_tty_driver was deprecated by tty_alloc_driver in commit 7f0bc6a68ed9 (TTY: pass flags to alloc_tty_driver) in 2012 but first in kernel v5.15 it has been dropped (56ec5880a28e). Switch to tty_alloc_driver when using kernels >= v5.15 As of v5.15, the put_tty_driver alias has been dropped in favor of directly calling tty_driver_kref_put (9f90a4ddef4e). Switch to tty_driver_kref_put when using kernels >= v5.15 As from v5.14 the write_room (03b3b1a2405c) and chars_in_buffer (fff4ef17a940) methods' return type changed from int to unsigned int in struct tty_operations. This has impact on ec_tty_write_room() and ec_tty_chars_in_buffer().
This commit is contained in:
parent
fa890a8b61
commit
96a045e36e
25
tty/module.c
25
tty/module.c
|
|
@ -132,6 +132,7 @@ static const struct tty_operations ec_tty_ops; // see below
|
|||
int __init ec_tty_init_module(void)
|
||||
{
|
||||
int i, ret = 0;
|
||||
unsigned flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
|
||||
|
||||
printk(KERN_INFO PFX "TTY driver %s\n", EC_MASTER_VERSION);
|
||||
|
||||
|
|
@ -141,7 +142,11 @@ int __init ec_tty_init_module(void)
|
|||
ttys[i] = NULL;
|
||||
}
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)
|
||||
tty_driver = tty_alloc_driver(EC_TTY_MAX_DEVICES, flags);
|
||||
#else
|
||||
tty_driver = alloc_tty_driver(EC_TTY_MAX_DEVICES);
|
||||
#endif
|
||||
if (!tty_driver) {
|
||||
printk(KERN_ERR PFX "Failed to allocate tty driver.\n");
|
||||
ret = -ENOMEM;
|
||||
|
|
@ -155,7 +160,9 @@ int __init ec_tty_init_module(void)
|
|||
tty_driver->minor_start = 0;
|
||||
tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
|
||||
tty_driver->subtype = SERIAL_TYPE_NORMAL;
|
||||
tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0)
|
||||
tty_driver->flags = flags;
|
||||
#endif
|
||||
tty_driver->init_termios = ec_tty_std_termios;
|
||||
tty_set_operations(tty_driver, &ec_tty_ops);
|
||||
|
||||
|
|
@ -168,7 +175,11 @@ int __init ec_tty_init_module(void)
|
|||
return ret;
|
||||
|
||||
out_put:
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)
|
||||
tty_driver_kref_put(tty_driver);
|
||||
#else
|
||||
put_tty_driver(tty_driver);
|
||||
#endif
|
||||
out_return:
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -194,7 +205,11 @@ void __exit ec_tty_cleanup_module(void)
|
|||
#endif
|
||||
|
||||
tty_unregister_driver(tty_driver);
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)
|
||||
tty_driver_kref_put(tty_driver);
|
||||
#else
|
||||
put_tty_driver(tty_driver);
|
||||
#endif
|
||||
printk(KERN_INFO PFX "Module unloading.\n");
|
||||
}
|
||||
|
||||
|
|
@ -536,7 +551,11 @@ static void ec_tty_put_char(struct tty_struct *tty, unsigned char ch)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)
|
||||
static unsigned int ec_tty_write_room(struct tty_struct *tty)
|
||||
#else
|
||||
static int ec_tty_write_room(struct tty_struct *tty)
|
||||
#endif
|
||||
{
|
||||
ec_tty_t *t = (ec_tty_t *) tty->driver_data;
|
||||
int ret = ec_tty_tx_space(t);
|
||||
|
|
@ -550,7 +569,11 @@ static int ec_tty_write_room(struct tty_struct *tty)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)
|
||||
static unsigned int ec_tty_chars_in_buffer(struct tty_struct *tty)
|
||||
#else
|
||||
static int ec_tty_chars_in_buffer(struct tty_struct *tty)
|
||||
#endif
|
||||
{
|
||||
ec_tty_t *t = (ec_tty_t *) tty->driver_data;
|
||||
int ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue