]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/rtl8188eu/os_dep/osdep_service.c
staging: rtl8188eu: os_dep: Remove useless return variables
[karo-tx-linux.git] / drivers / staging / rtl8188eu / os_dep / osdep_service.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20
21
22 #define _OSDEP_SERVICE_C_
23
24 #include <osdep_service.h>
25 #include <osdep_intf.h>
26 #include <drv_types.h>
27 #include <recv_osdep.h>
28 #include <linux/vmalloc.h>
29 #include <rtw_ioctl_set.h>
30
31 /*
32 * Translate the OS dependent @param error_code to OS independent RTW_STATUS_CODE
33 * @return: one of RTW_STATUS_CODE
34 */
35 inline int RTW_STATUS_CODE(int error_code)
36 {
37         if (error_code >= 0)
38                 return _SUCCESS;
39         return _FAIL;
40 }
41
42 u8 *_rtw_malloc(u32 sz)
43 {
44         return kmalloc(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
45 }
46
47 void *rtw_malloc2d(int h, int w, int size)
48 {
49         int j;
50
51         void **a = kzalloc(h*sizeof(void *) + h*w*size, GFP_KERNEL);
52         if (!a) {
53                 pr_info("%s: alloc memory fail!\n", __func__);
54                 return NULL;
55         }
56
57         for (j = 0; j < h; j++)
58                 a[j] = ((char *)(a+h)) + j*w*size;
59
60         return a;
61 }
62
63 u32 _rtw_down_sema(struct semaphore *sema)
64 {
65         if (down_interruptible(sema))
66                 return _FAIL;
67         else
68                 return _SUCCESS;
69 }
70
71 void    _rtw_init_queue(struct __queue *pqueue)
72 {
73         INIT_LIST_HEAD(&(pqueue->queue));
74         spin_lock_init(&(pqueue->lock));
75 }
76
77 struct net_device *rtw_alloc_etherdev_with_old_priv(int sizeof_priv,
78                                                     void *old_priv)
79 {
80         struct net_device *pnetdev;
81         struct rtw_netdev_priv_indicator *pnpi;
82
83         pnetdev = alloc_etherdev_mq(sizeof(struct rtw_netdev_priv_indicator), 4);
84         if (!pnetdev)
85                 goto RETURN;
86
87         pnpi = netdev_priv(pnetdev);
88         pnpi->priv = old_priv;
89         pnpi->sizeof_priv = sizeof_priv;
90
91 RETURN:
92         return pnetdev;
93 }
94
95 void rtw_free_netdev(struct net_device *netdev)
96 {
97         struct rtw_netdev_priv_indicator *pnpi;
98
99         if (!netdev)
100                 goto RETURN;
101
102         pnpi = netdev_priv(netdev);
103
104         if (!pnpi->priv)
105                 goto RETURN;
106
107         vfree(pnpi->priv);
108         free_netdev(netdev);
109
110 RETURN:
111         return;
112 }
113
114 u64 rtw_modular64(u64 x, u64 y)
115 {
116         return do_div(x, y);
117 }
118
119 void rtw_buf_free(u8 **buf, u32 *buf_len)
120 {
121         *buf_len = 0;
122         kfree(*buf);
123         *buf = NULL;
124 }
125
126 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len)
127 {
128         u32 dup_len = 0;
129         u8 *ori = NULL;
130         u8 *dup = NULL;
131
132         if (!buf || !buf_len)
133                 return;
134
135         if (!src || !src_len)
136                 goto keep_ori;
137
138         /* duplicate src */
139         dup = rtw_malloc(src_len);
140         if (dup) {
141                 dup_len = src_len;
142                 memcpy(dup, src, dup_len);
143         }
144
145 keep_ori:
146         ori = *buf;
147
148         /* replace buf with dup */
149         *buf_len = 0;
150         *buf = dup;
151         *buf_len = dup_len;
152
153         /* free ori */
154         kfree(ori);
155 }