Skip to content

Instantly share code, notes, and snippets.

@pandax381
Last active September 5, 2023 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandax381/baabf73fa4dc9d4efd51db2ae382fd39 to your computer and use it in GitHub Desktop.
Save pandax381/baabf73fa4dc9d4efd51db2ae382fd39 to your computer and use it in GitHub Desktop.
Patch for Perle TruePort Daemon and Driver for Linux (trueport-6.10.0) with kernel 5.19.0 through 6.2.0
diff -uprN trueport-6.10.0/ptyx/ptyc.c trueport-6.10.0-mod/ptyx/ptyc.c
--- trueport-6.10.0/ptyx/ptyc.c 2020-05-28 20:56:32.000000000 +0900
+++ trueport-6.10.0-mod/ptyx/ptyc.c 2023-09-06 04:52:31.273527237 +0900
@@ -93,7 +93,11 @@ static void ptyx_ctrl_close(struct tty_s
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+static unsigned int ptyx_ctrl_write_room(struct tty_struct *tty)
+#else
static int ptyx_ctrl_write_room(struct tty_struct *tty)
+#endif
{
struct ptyx_struct *ptyx_info;
@@ -102,7 +106,11 @@ static int ptyx_ctrl_write_room(struct t
ptyx_info = (struct ptyx_struct *) tty->driver_data;
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+ if (!tty || tty->flow.stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#else
if (!tty || tty->stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#endif
return 0;
return RECEIVE_ROOM(tty);
@@ -111,7 +119,11 @@ static int ptyx_ctrl_write_room(struct t
// The Control tty will pass all statuses in raw mode to the dameon
// so in this case we can return the true count in the buffer.
//
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+static unsigned int ptyx_ctrl_chars_in_buffer(struct tty_struct *tty)
+#else
static int ptyx_ctrl_chars_in_buffer(struct tty_struct *tty)
+#endif
{
return 0;
}
diff -uprN trueport-6.10.0/ptyx/ptym.c trueport-6.10.0-mod/ptyx/ptym.c
--- trueport-6.10.0/ptyx/ptym.c 2020-05-28 20:56:32.000000000 +0900
+++ trueport-6.10.0-mod/ptyx/ptym.c 2023-09-06 05:18:43.492701215 +0900
@@ -175,7 +175,11 @@ static int ptyx_master_write(struct tty_
s_tty = ptyx_info->s_tty;
PTYX_UNLOCK(&ptyx_info->port_lock, flags);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+ if (!s_tty || tty->flow.stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#else
if (!s_tty || tty->stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#endif
return 0;
if (from_user)
@@ -245,7 +249,11 @@ static int ptyx_master_write(struct tty_
s_tty = ptyx_info->s_tty;
PTYX_UNLOCK(&ptyx_info->port_lock, flags);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+ if (!s_tty || tty->flow.stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#else
if (!s_tty || tty->stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#endif
return 0;
if (count > 0)
@@ -266,7 +274,11 @@ static int ptyx_master_write(struct tty_
}
#endif
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+static unsigned int ptyx_master_write_room(struct tty_struct *tty)
+#else
static int ptyx_master_write_room(struct tty_struct *tty)
+#endif
{
struct ptyx_struct *ptyx_info;
struct tty_struct *s_tty;
@@ -281,7 +293,11 @@ static int ptyx_master_write_room(struct
s_tty = ptyx_info->s_tty;
PTYX_UNLOCK(&ptyx_info->port_lock, flags);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+ if (!s_tty || tty->flow.stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#else
if (!s_tty || tty->stopped || (ptyx_info->flags & SLAVE_CLOSING) )
+#endif
return 0;
return RECEIVE_ROOM(s_tty);
@@ -301,7 +317,11 @@ static int ptyx_master_write_room(struct
* read. (The N_TTY ldisc.chars_in_buffer now knows this.)
*
*/
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+static unsigned int ptyx_master_chars_in_buffer(struct tty_struct *tty)
+#else
static int ptyx_master_chars_in_buffer(struct tty_struct *tty)
+#endif
{
return 0;
}
@@ -396,7 +416,9 @@ static int ptyx_master_ioctl(struct tty_
// slave not open so use the slave's default termios
tmp_termios = &ptyx_info->s_driver->init_termios;
}
-#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)) // Greater than 2.6.23
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6,1,0))
+ if (copy_to_user((struct termios *)arg, tmp_termios, sizeof(*tmp_termios)))
+#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)) // Greater than 2.6.23
#ifdef TCGETS2
if (kernel_termios_to_user_termios_1((struct termios *)arg, tmp_termios))
#else
@@ -705,8 +727,11 @@ out:
return retval;
}
-
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,0,0)
+static void ptyx_master_set_termios(struct tty_struct *tty, const STRUCT_TERMIOS *old_termios)
+#else
static void ptyx_master_set_termios(struct tty_struct *tty, STRUCT_TERMIOS *old_termios)
+#endif
{
ptyx_print(PTYX_DEBUG_TERMIOS, ("ptyx_master_set_termios: called current->state=%lx\n",current->state));
diff -uprN trueport-6.10.0/ptyx/ptymod.c trueport-6.10.0-mod/ptyx/ptymod.c
--- trueport-6.10.0/ptyx/ptymod.c 2020-05-28 20:56:32.000000000 +0900
+++ trueport-6.10.0-mod/ptyx/ptymod.c 2023-09-06 05:15:12.866407777 +0900
@@ -286,24 +286,39 @@ static int __init ptyx_init(void)
goto init_out;
}
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0))
+ ptyx_master_driver = tty_alloc_driver(max_installed_ports,0);
+ if (IS_ERR(ptyx_master_driver))
+#else
ptyx_master_driver = alloc_tty_driver(max_installed_ports);
if (!ptyx_master_driver)
+#endif
{
printk("Couldn't allocate ptyx master driver \n");
retval = -ENOMEM;
goto init_out;
}
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0))
+ ptyx_slave_driver = tty_alloc_driver(max_installed_ports,0);
+ if (IS_ERR(ptyx_slave_driver))
+#else
ptyx_slave_driver = alloc_tty_driver(max_installed_ports);
if (!ptyx_slave_driver)
+#endif
{
printk("Couldn't allocate ptyx slave driver \n");
retval = -ENOMEM;
goto init_out;
}
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0))
+ ptyx_control_driver = tty_alloc_driver(max_installed_ports,0);
+ if (IS_ERR(ptyx_control_driver))
+#else
ptyx_control_driver = alloc_tty_driver(max_installed_ports);
if (!ptyx_control_driver)
+#endif
{
printk("Couldn't allocate ptyx ctrl status driver \n");
retval = -ENOMEM;
@@ -351,7 +366,9 @@ static int __init ptyx_init(void)
// Master Driver
ptyx_master_driver->owner = THIS_MODULE;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(6,1,0))
ptyx_master_driver->magic = TTY_DRIVER_MAGIC;
+#endif
ptyx_master_driver->driver_name = "ptyx_master";
ptyx_master_driver->name = PTYX_MASTER_NAME;
ptyx_master_driver->major = PTYX_MASTER_MAJOR;
@@ -370,7 +387,9 @@ static int __init ptyx_init(void)
// Slave driver
ptyx_slave_driver->owner = THIS_MODULE;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(6,1,0))
ptyx_slave_driver->magic = TTY_DRIVER_MAGIC;
+#endif
ptyx_slave_driver->driver_name = "ptyx_slave";
ptyx_slave_driver->name = PTYX_SLAVE_NAME;
ptyx_slave_driver->major = PTYX_SLAVE_MAJOR;
@@ -385,7 +404,9 @@ static int __init ptyx_init(void)
// Control status Driver
ptyx_control_driver->owner = THIS_MODULE;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(6,1,0))
ptyx_control_driver->magic = TTY_DRIVER_MAGIC;
+#endif
ptyx_control_driver->driver_name = "ptyx_control";
ptyx_control_driver->name = PTYX_CTRL_NAME;
ptyx_control_driver->major = PTYX_CTRL_MAJOR;
@@ -403,20 +424,32 @@ static int __init ptyx_init(void)
if ( (retval = tty_register_driver(ptyx_control_driver)) < 0 )
{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0))
+ tty_driver_kref_put(ptyx_control_driver);
+#else
put_tty_driver(ptyx_control_driver);
+#endif
printk("Couldn't register ptyx control status driver, retval=%d3 \n", retval);
}
if ( (retval = tty_register_driver(ptyx_slave_driver)) < 0 )
{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0))
+ tty_driver_kref_put(ptyx_slave_driver);
+#else
put_tty_driver(ptyx_slave_driver);
+#endif
printk("Couldn't register ptyx slave driver, retval=%d \n", retval);
goto init_out;
}
if ( (retval = tty_register_driver(ptyx_master_driver)) < 0 )
{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,15,0))
+ tty_driver_kref_put(ptyx_slave_driver);
+#else
put_tty_driver(ptyx_slave_driver);
+#endif
printk("Couldn't register ptyx master driver, retval=%d \n", retval);
}
@@ -427,27 +460,55 @@ init_out:
static void __exit ptyx_finish(void)
{
- int e1, i;
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,13,0))
+ int e1;
+#endif
+ int i;
ptyx_print(PTYX_DEBUG_MISC, ("ptyx_finish(): unregistering driver \n"));
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,13,0))
if ( (e1 = tty_unregister_driver(ptyx_master_driver)) )
{
printk("ptyx_finish(): ptyx faied to unregister master TTY driver (%d) \n", e1);
}
+#else
+ tty_unregister_driver(ptyx_master_driver);
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0))
put_tty_driver(ptyx_master_driver);
+#else
+ tty_driver_kref_put(ptyx_master_driver);
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,13,0))
if ( (e1 = tty_unregister_driver(ptyx_slave_driver)) )
{
printk("ptyx_finish(): ptyx faied to unregister slave TTY driver (%d) \n", e1);
}
+#else
+ tty_unregister_driver(ptyx_slave_driver);
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0))
put_tty_driver(ptyx_slave_driver);
+#else
+ tty_driver_kref_put(ptyx_slave_driver);
+#endif
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,13,0))
if ( (e1 = tty_unregister_driver(ptyx_control_driver)) )
{
printk("ptyx_finish(): ptyx faied to unregister control status TTY driver (%d) \n", e1);
}
+#else
+ tty_unregister_driver(ptyx_control_driver);
+#endif
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(5,15,0))
put_tty_driver(ptyx_control_driver);
+#else
+ tty_driver_kref_put(ptyx_control_driver);
+#endif
if (pty_state_table)
{
diff -uprN trueport-6.10.0/ptyx/ptys.c trueport-6.10.0-mod/ptyx/ptys.c
--- trueport-6.10.0/ptyx/ptys.c 2020-05-28 20:56:32.000000000 +0900
+++ trueport-6.10.0-mod/ptyx/ptys.c 2023-09-06 05:19:07.664603123 +0900
@@ -225,7 +225,11 @@ static int ptyx_slave_write(struct tty_s
m_tty = ptyx_info->m_tty;
PTYX_UNLOCK(&ptyx_info->port_lock, flags);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+ if ( !m_tty || tty->flow.stopped )
+#else
if ( !m_tty || tty->stopped )
+#endif
return 0;
if (from_user)
@@ -309,7 +313,11 @@ static int ptyx_slave_write(struct tty_s
m_tty = ptyx_info->m_tty;
PTYX_UNLOCK(&ptyx_info->port_lock, flags);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+ if ( !m_tty || tty->flow.stopped )
+#else
if ( !m_tty || tty->stopped )
+#endif
return 0;
if (!slave_dump_data(ptyx_info))
@@ -339,7 +347,11 @@ static int ptyx_slave_write(struct tty_s
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+static unsigned int ptyx_slave_write_room(struct tty_struct *tty)
+#else
static int ptyx_slave_write_room(struct tty_struct *tty)
+#endif
{
struct ptyx_struct *ptyx_info;
struct tty_struct *m_tty;
@@ -355,7 +367,11 @@ static int ptyx_slave_write_room(struct
m_tty = ptyx_info->m_tty;
PTYX_UNLOCK(&ptyx_info->port_lock, flags);
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+ if (!m_tty || tty->flow.stopped)
+#else
if (!m_tty || tty->stopped)
+#endif
return 0;
return RECEIVE_ROOM(m_tty);
@@ -367,7 +383,11 @@ static int ptyx_slave_write_room(struct
* buffer where they can be read immediately, so in this case we can
* return the true count in the buffer.
*/
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0))
+static unsigned int ptyx_slave_chars_in_buffer(struct tty_struct *tty)
+#else
static int ptyx_slave_chars_in_buffer(struct tty_struct *tty)
+#endif
{
return 0;
}
@@ -489,6 +509,10 @@ static void ptyx_slave_start(struct tty_
//
//*****************************************************************************
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,13,0))
+int tty_check_change(struct tty_struct *tty);
+#endif
+
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39)) // Less than 2.6.39
static int ptyx_slave_ioctl(struct tty_struct *tty, struct file *file,
unsigned int cmd, unsigned long arg)
@@ -1085,7 +1109,11 @@ out:
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,0,0)
+static void ptyx_slave_set_termios(struct tty_struct *tty, const STRUCT_TERMIOS *old_termios)
+#else
static void ptyx_slave_set_termios(struct tty_struct *tty, STRUCT_TERMIOS *old_termios)
+#endif
{
struct ptyx_struct *ptyx_info = (struct ptyx_struct *)tty->driver_data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment