1 From 34b9c77c9ab2794d4e912461e4c1080c4b1f6184 Mon Sep 17 00:00:00 2001
2 From: Shaun Ruffell <sruffell@sruffell.net>
3 Date: Sun, 23 Feb 2020 19:39:24 -0600
4 Subject: [PATCH 05/12] Use proc_ops on kernels >= 5.6
6 In commit (d56c0d45f0e27 "proc: decouple proc from VFS with "struct proc_ops"")
7 [1], proc_create_data no longer takes a file_operations structure, but instead
8 takes a struct proc_ops in order to conserve memory in the kernel.
10 This change is necessary for DAHDI to work with kernels >= 5.6
12 [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d56c0d45f0e27f814e87a1676b6bd
14 Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
16 drivers/dahdi/dahdi-base.c | 9 +++++
17 drivers/dahdi/dahdi_dynamic_ethmf.c | 18 +++++++--
18 drivers/dahdi/xpp/card_bri.c | 23 ++++++++---
19 drivers/dahdi/xpp/card_fxo.c | 25 +++++++++---
20 drivers/dahdi/xpp/card_fxs.c | 35 +++++++++++++---
21 drivers/dahdi/xpp/xbus-core.c | 62 ++++++++++++++++++++++++-----
22 drivers/dahdi/xpp/xpp_dahdi.c | 23 ++++++++---
23 drivers/dahdi/xpp/xpp_usb.c | 26 +++++++++---
24 include/dahdi/kernel.h | 11 +++--
25 9 files changed, 187 insertions(+), 45 deletions(-)
27 --- a/drivers/dahdi/dahdi-base.c
28 +++ b/drivers/dahdi/dahdi-base.c
29 @@ -1015,6 +1015,14 @@ static int dahdi_proc_open(struct inode
30 return single_open(file, dahdi_seq_show, PDE_DATA(inode));
33 +#ifdef DAHDI_HAVE_PROC_OPS
34 +static const struct proc_ops dahdi_proc_ops = {
35 + .proc_open = dahdi_proc_open,
36 + .proc_read = seq_read,
37 + .proc_lseek = seq_lseek,
38 + .proc_release = single_release,
41 static const struct file_operations dahdi_proc_ops = {
43 .open = dahdi_proc_open,
44 @@ -1022,6 +1030,7 @@ static const struct file_operations dahd
46 .release = single_release,
48 +#endif /* DAHDI_HAVE_PROC_OPS */
52 --- a/drivers/dahdi/dahdi_dynamic_ethmf.c
53 +++ b/drivers/dahdi/dahdi_dynamic_ethmf.c
54 @@ -733,12 +733,22 @@ static int ztdethmf_proc_open(struct ino
55 return single_open(file, ztdethmf_proc_show, NULL);
58 +#ifdef DAHDI_HAVE_PROC_OPS
59 +static const struct proc_ops ztdethmf_proc_fops = {
60 + .proc_open = ztdethmf_proc_open,
61 + .proc_read = seq_read,
62 + .proc_lseek = seq_lseek,
63 + .proc_release = seq_release,
66 static const struct file_operations ztdethmf_proc_fops = {
67 - .open = ztdethmf_proc_open,
69 - .llseek = seq_lseek,
70 - .release = seq_release,
71 + .owner = THIS_MODULE,
72 + .open = ztdethmf_proc_open,
74 + .llseek = seq_lseek,
75 + .release = seq_release,
77 +#endif /* DAHDI_HAVE_PROC_OPS */
80 static int __init ztdethmf_init(void)
81 --- a/drivers/dahdi/xpp/card_bri.c
82 +++ b/drivers/dahdi/xpp/card_bri.c
83 @@ -153,8 +153,12 @@ static int write_state_register(xpd_t *x
84 static bool bri_packet_is_valid(xpacket_t *pack);
85 static void bri_packet_dump(const char *msg, xpacket_t *pack);
87 +#ifdef DAHDI_HAVE_PROC_OPS
88 +static const struct proc_ops proc_bri_info_ops;
90 static const struct file_operations proc_bri_info_ops;
93 static int bri_spanconfig(struct file *file, struct dahdi_span *span,
94 struct dahdi_lineconfig *lc);
95 static int bri_chanconfig(struct file *file, struct dahdi_chan *chan,
96 @@ -1740,13 +1744,22 @@ static int proc_bri_info_open(struct ino
97 return single_open(file, proc_bri_info_show, PDE_DATA(inode));
100 +#ifdef DAHDI_HAVE_PROC_OPS
101 +static const struct proc_ops proc_bri_info_ops = {
102 + .proc_open = proc_bri_info_open,
103 + .proc_read = seq_read,
104 + .proc_lseek = seq_lseek,
105 + .proc_release = single_release,
108 static const struct file_operations proc_bri_info_ops = {
109 - .owner = THIS_MODULE,
110 - .open = proc_bri_info_open,
112 - .llseek = seq_lseek,
113 - .release = single_release,
114 + .owner = THIS_MODULE,
115 + .open = proc_bri_info_open,
117 + .llseek = seq_lseek,
118 + .release = single_release,
120 +#endif /* DAHDI_HAVE_PROC_OPS */
123 static int bri_xpd_probe(struct device *dev)
124 --- a/drivers/dahdi/xpp/card_fxo.c
125 +++ b/drivers/dahdi/xpp/card_fxo.c
126 @@ -107,9 +107,13 @@ enum fxo_leds {
127 static bool fxo_packet_is_valid(xpacket_t *pack);
128 static void fxo_packet_dump(const char *msg, xpacket_t *pack);
129 #ifdef CONFIG_PROC_FS
130 +#ifdef DAHDI_HAVE_PROC_OPS
131 +static const struct proc_ops proc_fxo_info_ops;
133 static const struct file_operations proc_fxo_info_ops;
136 -static const struct file_operations proc_xpd_metering_ops;
137 +static const struct proc_ops proc_xpd_metering_ops;
140 static void dahdi_report_battery(xpd_t *xpd, lineno_t chan);
141 @@ -1484,13 +1488,22 @@ static int proc_fxo_info_open(struct ino
142 return single_open(file, proc_fxo_info_show, PDE_DATA(inode));
145 +#ifdef DAHDI_HAVE_PROC_OPS
146 +static const struct proc_ops proc_fxo_info_ops = {
147 + .proc_open = proc_fxo_info_open,
148 + .proc_read = seq_read,
149 + .proc_lseek = seq_lseek,
150 + .proc_release = single_release,
153 static const struct file_operations proc_fxo_info_ops = {
154 - .owner = THIS_MODULE,
155 - .open = proc_fxo_info_open,
157 - .llseek = seq_lseek,
158 - .release = single_release,
159 + .owner = THIS_MODULE,
160 + .open = proc_fxo_info_open,
162 + .llseek = seq_lseek,
163 + .release = single_release,
168 static int proc_xpd_metering_show(struct seq_file *sfile, void *not_used)
169 --- a/drivers/dahdi/xpp/card_fxs.c
170 +++ b/drivers/dahdi/xpp/card_fxs.c
171 @@ -160,11 +160,19 @@ enum neon_state {
172 static bool fxs_packet_is_valid(xpacket_t *pack);
173 static void fxs_packet_dump(const char *msg, xpacket_t *pack);
174 #ifdef CONFIG_PROC_FS
175 +#ifdef DAHDI_HAVE_PROC_OPS
176 +static const struct proc_ops proc_fxs_info_ops;
178 static const struct file_operations proc_fxs_info_ops;
181 +#ifdef DAHDI_HAVE_PROC_OPS
182 +static const struct proc_ops proc_xpd_metering_ops;
184 static const struct file_operations proc_xpd_metering_ops;
188 static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos);
190 #define PROC_FXS_INFO_FNAME "fxs_info"
191 @@ -2115,13 +2123,22 @@ static int proc_fxs_info_open(struct ino
192 return single_open(file, proc_fxs_info_show, PDE_DATA(inode));
195 +#ifdef DAHDI_HAVE_PROC_OPS
196 +static const struct proc_ops proc_fxs_info_ops = {
197 + .proc_open = proc_fxs_info_open,
198 + .proc_read = seq_read,
199 + .proc_lseek = seq_lseek,
200 + .proc_release = single_release,
203 static const struct file_operations proc_fxs_info_ops = {
204 - .owner = THIS_MODULE,
205 - .open = proc_fxs_info_open,
207 - .llseek = seq_lseek,
208 - .release = single_release,
209 + .owner = THIS_MODULE,
210 + .open = proc_fxs_info_open,
212 + .llseek = seq_lseek,
213 + .release = single_release,
218 static ssize_t proc_xpd_metering_write(struct file *file,
219 @@ -2165,12 +2182,20 @@ static int proc_xpd_metering_open(struct
220 file->private_data = PDE_DATA(inode);
223 +#ifdef DAHDI_HAVE_PROC_OPS
224 +static const struct proc_ops proc_xpd_metering_ops = {
225 + .proc_open = proc_xpd_metering_open,
226 + .proc_write = proc_xpd_metering_write,
227 + .proc_release = single_release,
230 static const struct file_operations proc_xpd_metering_ops = {
231 .owner = THIS_MODULE,
232 .open = proc_xpd_metering_open,
233 .write = proc_xpd_metering_write,
234 .release = single_release,
236 +#endif /* DAHDI_HAVE_PROC_OPS */
240 --- a/drivers/dahdi/xpp/xbus-core.c
241 +++ b/drivers/dahdi/xpp/xbus-core.c
242 @@ -51,8 +51,15 @@ static const char rcsid[] = "$Id$";
243 #ifdef PROTOCOL_DEBUG
244 #ifdef CONFIG_PROC_FS
245 #define PROC_XBUS_COMMAND "command"
247 +#ifdef DAHDI_HAVE_PROC_OPS
248 +static const struct proc_ops proc_xbus_command_ops;
250 static const struct file_operations proc_xbus_command_ops;
251 +#endif /* DAHDI_HAVE_PROC_OPS */
257 /* Command line parameters */
258 @@ -66,8 +73,15 @@ static DEF_PARM_BOOL(dahdi_autoreg, 0, 0
259 "Register devices automatically (1) or not (0). UNUSED.");
261 #ifdef CONFIG_PROC_FS
263 +#ifdef DAHDI_HAVE_PROC_OPS
264 +static const struct proc_ops xbus_read_proc_ops;
266 static const struct file_operations xbus_read_proc_ops;
268 +#endif /* DAHDI_HAVE_PROC_OPS */
270 +#endif /* CONFIG_PROC_FS */
272 static void transport_init(xbus_t *xbus, struct xbus_ops *ops,
273 ushort max_send_size,
274 struct device *transport_device, void *priv);
275 @@ -1831,13 +1845,22 @@ static int xbus_read_proc_open(struct in
276 return single_open(file, xbus_proc_show, PDE_DATA(inode));
279 +#ifdef DAHDI_HAVE_PROC_OPS
280 +static const struct proc_ops xbus_read_proc_ops = {
281 + .proc_open = xbus_read_proc_open,
282 + .proc_read = seq_read,
283 + .proc_lseek = seq_lseek,
284 + .proc_release = single_release,
287 static const struct file_operations xbus_read_proc_ops = {
288 - .owner = THIS_MODULE,
289 - .open = xbus_read_proc_open,
291 - .llseek = seq_lseek,
292 - .release = single_release,
293 + .owner = THIS_MODULE,
294 + .open = xbus_read_proc_open,
296 + .llseek = seq_lseek,
297 + .release = single_release,
299 +#endif /* DAHDI_HAVE_PROC_OPS */
301 #ifdef PROTOCOL_DEBUG
302 static ssize_t proc_xbus_command_write(struct file *file,
303 @@ -1930,11 +1953,19 @@ static int proc_xbus_command_open(struct
307 +#ifdef DAHDI_HAVE_PROC_OPS
308 +static const struct proc_ops proc_xbus_command_ops = {
309 + .proc_open = proc_xbus_command_open,
310 + .proc_write = proc_xbus_command_write,
313 static const struct file_operations proc_xbus_command_ops = {
314 .owner = THIS_MODULE,
315 .open = proc_xbus_command_open,
316 .write = proc_xbus_command_write,
318 +#endif /* DAHDI_HAVE_PROC_OPS */
322 static int xpp_proc_read_show(struct seq_file *sfile, void *data)
323 @@ -1964,13 +1995,22 @@ static int xpp_proc_read_open(struct ino
324 return single_open(file, xpp_proc_read_show, PDE_DATA(inode));
327 +#ifdef DAHDI_HAVE_PROC_OPS
328 +static const struct proc_ops xpp_proc_read_ops = {
329 + .proc_open = xpp_proc_read_open,
330 + .proc_read = seq_read,
331 + .proc_lseek = seq_lseek,
332 + .proc_release = single_release,
335 static const struct file_operations xpp_proc_read_ops = {
336 - .owner = THIS_MODULE,
337 - .open = xpp_proc_read_open,
339 - .llseek = seq_lseek,
340 - .release = single_release,
341 + .owner = THIS_MODULE,
342 + .open = xpp_proc_read_open,
344 + .llseek = seq_lseek,
345 + .release = single_release,
347 +#endif /* DAHDI_HAVE_PROC_OPS */
351 --- a/drivers/dahdi/xpp/xpp_dahdi.c
352 +++ b/drivers/dahdi/xpp/xpp_dahdi.c
353 @@ -103,8 +103,12 @@ int total_registered_spans(void)
356 #ifdef CONFIG_PROC_FS
357 +#ifdef DAHDI_HAVE_PROC_OPS
358 +static const struct proc_ops xpd_read_proc_ops;
360 static const struct file_operations xpd_read_proc_ops;
364 /*------------------------- XPD Management -------------------------*/
366 @@ -392,13 +396,22 @@ static int xpd_read_proc_open(struct ino
367 return single_open(file, xpd_read_proc_show, PDE_DATA(inode));
370 +#ifdef DAHDI_HAVE_PROC_OPS
371 +static const struct proc_ops xpd_read_proc_ops = {
372 + .proc_open = xpd_read_proc_open,
373 + .proc_read = seq_read,
374 + .proc_lseek = seq_lseek,
375 + .proc_release = single_release,
378 static const struct file_operations xpd_read_proc_ops = {
379 - .owner = THIS_MODULE,
380 - .open = xpd_read_proc_open,
382 - .llseek = seq_lseek,
383 - .release = single_release,
384 + .owner = THIS_MODULE,
385 + .open = xpd_read_proc_open,
387 + .llseek = seq_lseek,
388 + .release = single_release,
394 --- a/drivers/dahdi/xpp/xpp_usb.c
395 +++ b/drivers/dahdi/xpp/xpp_usb.c
396 @@ -232,9 +232,14 @@ static void xpp_receive_callback(struct
397 static int xusb_probe(struct usb_interface *interface,
398 const struct usb_device_id *id);
399 static void xusb_disconnect(struct usb_interface *interface);
400 -#ifdef CONFIG_PROC_FS
402 +#ifdef CONFIG_PROC_FS
403 +#ifdef DAHDI_HAVE_PROC_OPS
404 +static const struct proc_ops xusb_read_proc_ops;
406 static const struct file_operations xusb_read_proc_ops;
410 /*------------------------------------------------------------------*/
412 @@ -1113,13 +1118,22 @@ static int xusb_read_proc_open(struct in
413 return single_open(file, xusb_read_proc_show, PDE_DATA(inode));
416 +#ifdef DAHDI_HAVE_PROC_OPS
417 +static const struct proc_ops xusb_read_proc_ops = {
418 + .proc_open = xusb_read_proc_open,
419 + .proc_read = seq_read,
420 + .proc_lseek = seq_lseek,
421 + .proc_release = single_release,
424 static const struct file_operations xusb_read_proc_ops = {
425 - .owner = THIS_MODULE,
426 - .open = xusb_read_proc_open,
428 - .llseek = seq_lseek,
429 - .release = single_release,
430 + .owner = THIS_MODULE,
431 + .open = xusb_read_proc_open,
433 + .llseek = seq_lseek,
434 + .release = single_release,
440 --- a/include/dahdi/kernel.h
441 +++ b/include/dahdi/kernel.h
443 #define HAVE_NET_DEVICE_OPS
446 +#define DAHDI_HAVE_PROC_OPS
448 /* __dev* were removed in 3.8. They still have effect in 2.6.18. */
451 @@ -1375,6 +1377,10 @@ static inline short dahdi_txtone_nextsam
452 /*! Maximum audio mask */
453 #define DAHDI_FORMAT_AUDIO_MASK ((1 << 16) - 1)
455 +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
457 +#undef DAHDI_HAVE_PROC_OPS
459 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
461 #ifndef TIMER_DATA_TYPE
462 @@ -1485,14 +1491,13 @@ static inline void *PDE_DATA(const struc
466 -#else /* >= 4.15.0 */
470 #ifndef TIMER_DATA_TYPE
471 #define TIMER_DATA_TYPE struct timer_list *
476 #ifndef dahdi_ktime_equal
477 static inline int dahdi_ktime_equal(const ktime_t cmp1, const ktime_t cmp2)