sllin: add patches for newer kernels
[AGL/meta-agl-demo.git] / recipes-kernel / sllin / files / 0006-Fix-build-with-5.14-kernel.patch
1 Updates for 5.14
2
3 The 5.14 kernel reworked the tty register and unregister call
4 arguments, and made one of the arguments to the receive_buf
5 callback const, add some kernel version conditionals to handle
6 those.
7
8 Upstream-Status: Inappropriate [no upstream]
9 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
10
11 ---
12  sllin/sllin.c | 29 ++++++++++++++++++++++++-----
13  1 file changed, 24 insertions(+), 5 deletions(-)
14
15 diff --git a/sllin/sllin.c b/sllin/sllin.c
16 index 904cff9..b89d06d 100644
17 --- a/sllin/sllin.c
18 +++ b/sllin/sllin.c
19 @@ -72,6 +72,12 @@
20  #include <linux/version.h>
21  #include "linux/lin_bus.h"
22  
23 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
24 +#define FP_CONST const
25 +#else
26 +#define FP_CONST
27 +#endif
28 +
29  /* Should be in include/linux/tty.h */
30  #define N_SLLIN                        25
31  /* -------------------------------- */
32 @@ -185,9 +191,9 @@ struct sllin {
33  static struct net_device **sllin_devs;
34  static int sllin_configure_frame_cache(struct sllin *sl, struct can_frame *cf);
35  static void sllin_slave_receive_buf(struct tty_struct *tty,
36 -                             const unsigned char *cp, char *fp, int count);
37 +                             const unsigned char *cp, FP_CONST char *fp, int count);
38  static void sllin_master_receive_buf(struct tty_struct *tty,
39 -                             const unsigned char *cp, char *fp, int count);
40 +                             const unsigned char *cp, FP_CONST char *fp, int count);
41  
42  
43  /* Values of two parity bits in LIN Protected
44 @@ -492,7 +498,7 @@ static void sll_setup(struct net_device *dev)
45    Routines looking at TTY side.
46   ******************************************/
47  static void sllin_master_receive_buf(struct tty_struct *tty,
48 -                             const unsigned char *cp, char *fp, int count)
49 +                             const unsigned char *cp, FP_CONST char *fp, int count)
50  {
51         struct sllin *sl = (struct sllin *) tty->disc_data;
52  
53 @@ -735,7 +741,7 @@ static void sllin_slave_finish_rx_msg(struct sllin *sl)
54  }
55  
56  static void sllin_slave_receive_buf(struct tty_struct *tty,
57 -                             const unsigned char *cp, char *fp, int count)
58 +                             const unsigned char *cp, FP_CONST char *fp, int count)
59  {
60         struct sllin *sl = (struct sllin *) tty->disc_data;
61         int lin_id;
62 @@ -842,7 +848,7 @@ static void sllin_slave_receive_buf(struct tty_struct *tty,
63  }
64  
65  static void sllin_receive_buf(struct tty_struct *tty,
66 -                             const unsigned char *cp, char *fp, int count)
67 +                             const unsigned char *cp, FP_CONST char *fp, int count)
68  {
69         struct sllin *sl = (struct sllin *) tty->disc_data;
70         netdev_dbg(sl->dev, "sllin_receive_buf invoked, count = %u\n", count);
71 @@ -1619,6 +1625,9 @@ static int sllin_ioctl(struct tty_struct *tty, struct file *file,
72  
73  static struct tty_ldisc_ops sll_ldisc = {
74         .owner          = THIS_MODULE,
75 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
76 +       .num            = N_SLLIN,
77 +#endif
78  #if LINUX_VERSION_CODE < KERNEL_VERSION(5,13,0)
79         .magic          = TTY_LDISC_MAGIC,
80  #endif
81 @@ -1648,7 +1657,11 @@ static int __init sllin_init(void)
82         }
83  
84         /* Fill in our line protocol discipline, and register it */
85 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
86 +       status = tty_register_ldisc(&sll_ldisc);
87 +#else
88         status = tty_register_ldisc(N_SLLIN, &sll_ldisc);
89 +#endif
90         if (status)  {
91                 pr_err("sllin: can't register line discipline\n");
92                 kfree(sllin_devs);
93 @@ -1719,9 +1732,15 @@ static void __exit sllin_exit(void)
94         kfree(sllin_devs);
95         sllin_devs = NULL;
96  
97 +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
98 +       tty_unregister_ldisc(&sll_ldisc);
99 +
100 +#else
101         i = tty_unregister_ldisc(N_SLLIN);
102 +
103         if (i)
104                 pr_err("sllin: can't unregister ldisc (err %d)\n", i);
105 +#endif
106  }
107  
108  module_init(sllin_init);