21
21
#include "osdep_intf.h"
22
22
#include "usb_ops.h"
23
23
24
+ #include <linux/usb.h>
24
25
#include <linux/ieee80211.h>
25
26
26
27
static const u8 P802_1H_OUI [P80211_OUI_LEN ] = {0x00 , 0x00 , 0xf8 };
@@ -55,6 +56,7 @@ int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
55
56
sint i ;
56
57
struct xmit_buf * pxmitbuf ;
57
58
struct xmit_frame * pxframe ;
59
+ int j ;
58
60
59
61
memset ((unsigned char * )pxmitpriv , 0 , sizeof (struct xmit_priv ));
60
62
spin_lock_init (& pxmitpriv -> lock );
@@ -117,25 +119,26 @@ int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
117
119
_init_queue (& pxmitpriv -> pending_xmitbuf_queue );
118
120
pxmitpriv -> pallocated_xmitbuf =
119
121
kmalloc (NR_XMITBUFF * sizeof (struct xmit_buf ) + 4 , GFP_ATOMIC );
120
- if (!pxmitpriv -> pallocated_xmitbuf ) {
121
- kfree (pxmitpriv -> pallocated_frame_buf );
122
- pxmitpriv -> pallocated_frame_buf = NULL ;
123
- return - ENOMEM ;
124
- }
122
+ if (!pxmitpriv -> pallocated_xmitbuf )
123
+ goto clean_up_frame_buf ;
125
124
pxmitpriv -> pxmitbuf = pxmitpriv -> pallocated_xmitbuf + 4 -
126
125
((addr_t )(pxmitpriv -> pallocated_xmitbuf ) & 3 );
127
126
pxmitbuf = (struct xmit_buf * )pxmitpriv -> pxmitbuf ;
128
127
for (i = 0 ; i < NR_XMITBUFF ; i ++ ) {
129
128
INIT_LIST_HEAD (& pxmitbuf -> list );
130
129
pxmitbuf -> pallocated_buf =
131
130
kmalloc (MAX_XMITBUF_SZ + XMITBUF_ALIGN_SZ , GFP_ATOMIC );
132
- if (!pxmitbuf -> pallocated_buf )
133
- return - ENOMEM ;
131
+ if (!pxmitbuf -> pallocated_buf ) {
132
+ j = 0 ;
133
+ goto clean_up_alloc_buf ;
134
+ }
134
135
pxmitbuf -> pbuf = pxmitbuf -> pallocated_buf + XMITBUF_ALIGN_SZ -
135
136
((addr_t ) (pxmitbuf -> pallocated_buf ) &
136
137
(XMITBUF_ALIGN_SZ - 1 ));
137
- if (r8712_xmit_resource_alloc (padapter , pxmitbuf ))
138
- return - ENOMEM ;
138
+ if (r8712_xmit_resource_alloc (padapter , pxmitbuf )) {
139
+ j = 1 ;
140
+ goto clean_up_alloc_buf ;
141
+ }
139
142
list_add_tail (& pxmitbuf -> list ,
140
143
& (pxmitpriv -> free_xmitbuf_queue .queue ));
141
144
pxmitbuf ++ ;
@@ -146,6 +149,28 @@ int _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv,
146
149
init_hwxmits (pxmitpriv -> hwxmits , pxmitpriv -> hwxmit_entry );
147
150
tasklet_setup (& pxmitpriv -> xmit_tasklet , r8712_xmit_bh );
148
151
return 0 ;
152
+
153
+ clean_up_alloc_buf :
154
+ if (j ) {
155
+ /* failure happened in r8712_xmit_resource_alloc()
156
+ * delete extra pxmitbuf->pallocated_buf
157
+ */
158
+ kfree (pxmitbuf -> pallocated_buf );
159
+ }
160
+ for (j = 0 ; j < i ; j ++ ) {
161
+ int k ;
162
+
163
+ pxmitbuf -- ; /* reset pointer */
164
+ kfree (pxmitbuf -> pallocated_buf );
165
+ for (k = 0 ; k < 8 ; k ++ ) /* delete xmit urb's */
166
+ usb_free_urb (pxmitbuf -> pxmit_urb [k ]);
167
+ }
168
+ kfree (pxmitpriv -> pallocated_xmitbuf );
169
+ pxmitpriv -> pallocated_xmitbuf = NULL ;
170
+ clean_up_frame_buf :
171
+ kfree (pxmitpriv -> pallocated_frame_buf );
172
+ pxmitpriv -> pallocated_frame_buf = NULL ;
173
+ return - ENOMEM ;
149
174
}
150
175
151
176
void _free_xmit_priv (struct xmit_priv * pxmitpriv )
0 commit comments