This source file includes following definitions.
- _rtw_malloc
- _rtw_init_queue
- rtw_alloc_etherdev_with_old_priv
- rtw_free_netdev
- rtw_buf_free
- rtw_buf_update
1
2
3
4
5
6
7 #define _OSDEP_SERVICE_C_
8
9 #include <osdep_service.h>
10 #include <osdep_intf.h>
11 #include <drv_types.h>
12 #include <recv_osdep.h>
13 #include <linux/vmalloc.h>
14 #include <rtw_ioctl_set.h>
15
16 u8 *_rtw_malloc(u32 sz)
17 {
18 return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
19 }
20
21 void _rtw_init_queue(struct __queue *pqueue)
22 {
23 INIT_LIST_HEAD(&pqueue->queue);
24 spin_lock_init(&pqueue->lock);
25 }
26
27 struct net_device *rtw_alloc_etherdev_with_old_priv(void *old_priv)
28 {
29 struct net_device *pnetdev;
30 struct rtw_netdev_priv_indicator *pnpi;
31
32 pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4);
33 if (!pnetdev)
34 goto RETURN;
35
36 pnpi = netdev_priv(pnetdev);
37 pnpi->priv = old_priv;
38
39 RETURN:
40 return pnetdev;
41 }
42
43 void rtw_free_netdev(struct net_device *netdev)
44 {
45 struct rtw_netdev_priv_indicator *pnpi;
46
47 if (!netdev)
48 goto RETURN;
49
50 pnpi = netdev_priv(netdev);
51
52 if (!pnpi->priv)
53 goto RETURN;
54
55 vfree(pnpi->priv);
56 free_netdev(netdev);
57
58 RETURN:
59 return;
60 }
61
62 void rtw_buf_free(u8 **buf, u32 *buf_len)
63 {
64 *buf_len = 0;
65 kfree(*buf);
66 *buf = NULL;
67 }
68
69 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
70 {
71 u32 dup_len = 0;
72 u8 *ori = NULL;
73 u8 *dup = NULL;
74
75 if (!buf || !buf_len)
76 return;
77
78 if (!src || !src_len)
79 goto keep_ori;
80
81
82 dup = rtw_malloc(src_len);
83 if (dup) {
84 dup_len = src_len;
85 memcpy(dup, src, dup_len);
86 }
87
88 keep_ori:
89 ori = *buf;
90
91
92 *buf_len = 0;
93 *buf = dup;
94 *buf_len = dup_len;
95
96
97 kfree(ori);
98 }