hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/strparser/strparser.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Stream Parser
34 *
45 * Copyright (c) 2016 Tom Herbert <tom@herbertland.com>
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2
8
- * as published by the Free Software Foundation.
96 */
107
118 #include <linux/bpf.h>
....@@ -14,7 +11,8 @@
1411 #include <linux/file.h>
1512 #include <linux/in.h>
1613 #include <linux/kernel.h>
17
-#include <linux/module.h>
14
+#include <linux/export.h>
15
+#include <linux/init.h>
1816 #include <linux/net.h>
1917 #include <linux/netdevice.h>
2018 #include <linux/poll.h>
....@@ -29,18 +27,10 @@
2927
3028 static struct workqueue_struct *strp_wq;
3129
32
-struct _strp_msg {
33
- /* Internal cb structure. struct strp_msg must be first for passing
34
- * to upper layer.
35
- */
36
- struct strp_msg strp;
37
- int accum_len;
38
-};
39
-
4030 static inline struct _strp_msg *_strp_msg(struct sk_buff *skb)
4131 {
4232 return (struct _strp_msg *)((void *)skb->cb +
43
- offsetof(struct qdisc_skb_cb, data));
33
+ offsetof(struct sk_skb_cb, strp));
4434 }
4535
4636 /* Lower lock held */
....@@ -159,18 +149,14 @@
159149 return 0;
160150 }
161151
162
- skb = alloc_skb(0, GFP_ATOMIC);
152
+ skb = alloc_skb_for_msg(head);
163153 if (!skb) {
164154 STRP_STATS_INCR(strp->stats.mem_fail);
165155 desc->error = -ENOMEM;
166156 return 0;
167157 }
168
- skb->len = head->len;
169
- skb->data_len = head->len;
170
- skb->truesize = head->truesize;
171
- *_strp_msg(skb) = *_strp_msg(head);
158
+
172159 strp->skb_nextp = &head->next;
173
- skb_shinfo(skb)->frag_list = head;
174160 strp->skb_head = skb;
175161 head = skb;
176162 } else {
....@@ -297,7 +283,7 @@
297283 break;
298284 }
299285
300
- /* Positive extra indicates ore bytes than needed for the
286
+ /* Positive extra indicates more bytes than needed for the
301287 * message
302288 */
303289
....@@ -545,17 +531,12 @@
545531 }
546532 EXPORT_SYMBOL_GPL(strp_check_rcv);
547533
548
-static int __init strp_mod_init(void)
534
+static int __init strp_dev_init(void)
549535 {
550536 strp_wq = create_singlethread_workqueue("kstrp");
537
+ if (unlikely(!strp_wq))
538
+ return -ENOMEM;
551539
552540 return 0;
553541 }
554
-
555
-static void __exit strp_mod_exit(void)
556
-{
557
- destroy_workqueue(strp_wq);
558
-}
559
-module_init(strp_mod_init);
560
-module_exit(strp_mod_exit);
561
-MODULE_LICENSE("GPL");
542
+device_initcall(strp_dev_init);