Merge pull request #831 from micmac1/fs-vpx-CVE-2023-5217
[feed/telephony.git] / libs / dahdi-linux / patches / 140-Use-proc_ops-on-kernels-5.6.patch
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
5
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.
9
10 This change is necessary for DAHDI to work with kernels >= 5.6
11
12 [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d56c0d45f0e27f814e87a1676b6bd
13
14 Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
15 ---
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(-)
26
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));
31 }
32
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,
39 +};
40 +#else
41 static const struct file_operations dahdi_proc_ops = {
42 .owner = THIS_MODULE,
43 .open = dahdi_proc_open,
44 @@ -1022,6 +1030,7 @@ static const struct file_operations dahd
45 .llseek = seq_lseek,
46 .release = single_release,
47 };
48 +#endif /* DAHDI_HAVE_PROC_OPS */
49
50 #endif
51
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);
56 }
57
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,
64 +};
65 +#else
66 static const struct file_operations ztdethmf_proc_fops = {
67 - .open = ztdethmf_proc_open,
68 - .read = seq_read,
69 - .llseek = seq_lseek,
70 - .release = seq_release,
71 + .owner = THIS_MODULE,
72 + .open = ztdethmf_proc_open,
73 + .read = seq_read,
74 + .llseek = seq_lseek,
75 + .release = seq_release,
76 };
77 +#endif /* DAHDI_HAVE_PROC_OPS */
78 #endif
79
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);
86 #ifdef CONFIG_PROC_FS
87 +#ifdef DAHDI_HAVE_PROC_OPS
88 +static const struct proc_ops proc_bri_info_ops;
89 +#else
90 static const struct file_operations proc_bri_info_ops;
91 #endif
92 +#endif
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));
98 }
99
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,
106 +};
107 +#else
108 static const struct file_operations proc_bri_info_ops = {
109 - .owner = THIS_MODULE,
110 - .open = proc_bri_info_open,
111 - .read = seq_read,
112 - .llseek = seq_lseek,
113 - .release = single_release,
114 + .owner = THIS_MODULE,
115 + .open = proc_bri_info_open,
116 + .read = seq_read,
117 + .llseek = seq_lseek,
118 + .release = single_release,
119 };
120 +#endif /* DAHDI_HAVE_PROC_OPS */
121 #endif
122
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;
132 +#else
133 static const struct file_operations proc_fxo_info_ops;
134 +#endif
135 #ifdef WITH_METERING
136 -static const struct file_operations proc_xpd_metering_ops;
137 +static const struct proc_ops proc_xpd_metering_ops;
138 #endif
139 #endif
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));
143 }
144
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,
151 +};
152 +#else
153 static const struct file_operations proc_fxo_info_ops = {
154 - .owner = THIS_MODULE,
155 - .open = proc_fxo_info_open,
156 - .read = seq_read,
157 - .llseek = seq_lseek,
158 - .release = single_release,
159 + .owner = THIS_MODULE,
160 + .open = proc_fxo_info_open,
161 + .read = seq_read,
162 + .llseek = seq_lseek,
163 + .release = single_release,
164 };
165 +#endif
166
167 #ifdef WITH_METERING
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;
177 +#else
178 static const struct file_operations proc_fxs_info_ops;
179 +#endif
180 #ifdef WITH_METERING
181 +#ifdef DAHDI_HAVE_PROC_OPS
182 +static const struct proc_ops proc_xpd_metering_ops;
183 +#else
184 static const struct file_operations proc_xpd_metering_ops;
185 #endif
186 #endif
187 +#endif
188 static void start_stop_vm_led(xbus_t *xbus, xpd_t *xpd, lineno_t pos);
189
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));
193 }
194
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,
201 +};
202 +#else
203 static const struct file_operations proc_fxs_info_ops = {
204 - .owner = THIS_MODULE,
205 - .open = proc_fxs_info_open,
206 - .read = seq_read,
207 - .llseek = seq_lseek,
208 - .release = single_release,
209 + .owner = THIS_MODULE,
210 + .open = proc_fxs_info_open,
211 + .read = seq_read,
212 + .llseek = seq_lseek,
213 + .release = single_release,
214 };
215 +#endif
216
217 #ifdef WITH_METERING
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);
221 }
222
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,
228 +};
229 +#else
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,
235 };
236 +#endif /* DAHDI_HAVE_PROC_OPS */
237 #endif
238 #endif
239
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"
246 +
247 +#ifdef DAHDI_HAVE_PROC_OPS
248 +static const struct proc_ops proc_xbus_command_ops;
249 +#else
250 static const struct file_operations proc_xbus_command_ops;
251 +#endif /* DAHDI_HAVE_PROC_OPS */
252 +
253 #endif
254 +
255 #endif
256
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.");
260
261 #ifdef CONFIG_PROC_FS
262 +
263 +#ifdef DAHDI_HAVE_PROC_OPS
264 +static const struct proc_ops xbus_read_proc_ops;
265 +#else
266 static const struct file_operations xbus_read_proc_ops;
267 -#endif
268 +#endif /* DAHDI_HAVE_PROC_OPS */
269 +
270 +#endif /* CONFIG_PROC_FS */
271 +
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));
277 }
278
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,
285 +};
286 +#else
287 static const struct file_operations xbus_read_proc_ops = {
288 - .owner = THIS_MODULE,
289 - .open = xbus_read_proc_open,
290 - .read = seq_read,
291 - .llseek = seq_lseek,
292 - .release = single_release,
293 + .owner = THIS_MODULE,
294 + .open = xbus_read_proc_open,
295 + .read = seq_read,
296 + .llseek = seq_lseek,
297 + .release = single_release,
298 };
299 +#endif /* DAHDI_HAVE_PROC_OPS */
300
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
304 return 0;
305 }
306
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,
311 +};
312 +#else
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,
317 };
318 +#endif /* DAHDI_HAVE_PROC_OPS */
319 +
320 #endif
321
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));
325 }
326
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,
333 +};
334 +#else
335 static const struct file_operations xpp_proc_read_ops = {
336 - .owner = THIS_MODULE,
337 - .open = xpp_proc_read_open,
338 - .read = seq_read,
339 - .llseek = seq_lseek,
340 - .release = single_release,
341 + .owner = THIS_MODULE,
342 + .open = xpp_proc_read_open,
343 + .read = seq_read,
344 + .llseek = seq_lseek,
345 + .release = single_release,
346 };
347 +#endif /* DAHDI_HAVE_PROC_OPS */
348
349 #endif
350
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)
354 }
355
356 #ifdef CONFIG_PROC_FS
357 +#ifdef DAHDI_HAVE_PROC_OPS
358 +static const struct proc_ops xpd_read_proc_ops;
359 +#else
360 static const struct file_operations xpd_read_proc_ops;
361 #endif
362 +#endif
363
364 /*------------------------- XPD Management -------------------------*/
365
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));
368 }
369
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,
376 +};
377 +#else
378 static const struct file_operations xpd_read_proc_ops = {
379 - .owner = THIS_MODULE,
380 - .open = xpd_read_proc_open,
381 - .read = seq_read,
382 - .llseek = seq_lseek,
383 - .release = single_release,
384 + .owner = THIS_MODULE,
385 + .open = xpd_read_proc_open,
386 + .read = seq_read,
387 + .llseek = seq_lseek,
388 + .release = single_release,
389 };
390 +#endif
391
392 #endif
393
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
401 +
402 +#ifdef CONFIG_PROC_FS
403 +#ifdef DAHDI_HAVE_PROC_OPS
404 +static const struct proc_ops xusb_read_proc_ops;
405 +#else
406 static const struct file_operations xusb_read_proc_ops;
407 #endif
408 +#endif
409
410 /*------------------------------------------------------------------*/
411
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));
414 }
415
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,
422 +};
423 +#else
424 static const struct file_operations xusb_read_proc_ops = {
425 - .owner = THIS_MODULE,
426 - .open = xusb_read_proc_open,
427 - .read = seq_read,
428 - .llseek = seq_lseek,
429 - .release = single_release,
430 + .owner = THIS_MODULE,
431 + .open = xusb_read_proc_open,
432 + .read = seq_read,
433 + .llseek = seq_lseek,
434 + .release = single_release,
435 };
436 +#endif
437
438
439 #endif
440 --- a/include/dahdi/kernel.h
441 +++ b/include/dahdi/kernel.h
442 @@ -68,6 +68,8 @@
443 #define HAVE_NET_DEVICE_OPS
444 #endif
445
446 +#define DAHDI_HAVE_PROC_OPS
447 +
448 /* __dev* were removed in 3.8. They still have effect in 2.6.18. */
449 #ifndef __devinit
450 # define __devinit
451 @@ -1375,6 +1377,10 @@ static inline short dahdi_txtone_nextsam
452 /*! Maximum audio mask */
453 #define DAHDI_FORMAT_AUDIO_MASK ((1 << 16) - 1)
454
455 +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
456 +
457 +#undef DAHDI_HAVE_PROC_OPS
458 +
459 #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 15, 0)
460
461 #ifndef TIMER_DATA_TYPE
462 @@ -1485,14 +1491,13 @@ static inline void *PDE_DATA(const struc
463 #endif /* 4.10.0 */
464 #endif /* 4.11.0 */
465 #endif /* 4.13.0 */
466 -#else /* >= 4.15.0 */
467 +#endif /* 4.15.0 */
468 +#endif /* 5.6 */
469
470 #ifndef TIMER_DATA_TYPE
471 #define TIMER_DATA_TYPE struct timer_list *
472 #endif
473
474 -#endif /* 4.15.0 */
475 -
476 #ifndef dahdi_ktime_equal
477 static inline int dahdi_ktime_equal(const ktime_t cmp1, const ktime_t cmp2)
478 {