@@ -97,16 +97,6 @@ static void free_netvsc_device_rcu(struct netvsc_device *nvdev)
97
97
call_rcu (& nvdev -> rcu , free_netvsc_device );
98
98
}
99
99
100
- static struct netvsc_device * get_outbound_net_device (struct hv_device * device )
101
- {
102
- struct netvsc_device * net_device = hv_device_to_netvsc_device (device );
103
-
104
- if (net_device && net_device -> destroy )
105
- net_device = NULL ;
106
-
107
- return net_device ;
108
- }
109
-
110
100
static void netvsc_destroy_buf (struct hv_device * device )
111
101
{
112
102
struct nvsp_message * revoke_packet ;
@@ -243,18 +233,15 @@ static void netvsc_destroy_buf(struct hv_device *device)
243
233
kfree (net_device -> send_section_map );
244
234
}
245
235
246
- static int netvsc_init_buf (struct hv_device * device )
236
+ static int netvsc_init_buf (struct hv_device * device ,
237
+ struct netvsc_device * net_device )
247
238
{
248
239
int ret = 0 ;
249
- struct netvsc_device * net_device ;
250
240
struct nvsp_message * init_packet ;
251
241
struct net_device * ndev ;
252
242
size_t map_words ;
253
243
int node ;
254
244
255
- net_device = get_outbound_net_device (device );
256
- if (!net_device )
257
- return - ENODEV ;
258
245
ndev = hv_get_drvdata (device );
259
246
260
247
node = cpu_to_node (device -> channel -> target_cpu );
@@ -285,9 +272,7 @@ static int netvsc_init_buf(struct hv_device *device)
285
272
286
273
/* Notify the NetVsp of the gpadl handle */
287
274
init_packet = & net_device -> channel_init_pkt ;
288
-
289
275
memset (init_packet , 0 , sizeof (struct nvsp_message ));
290
-
291
276
init_packet -> hdr .msg_type = NVSP_MSG1_TYPE_SEND_RECV_BUF ;
292
277
init_packet -> msg .v1_msg .send_recv_buf .
293
278
gpadl_handle = net_device -> recv_buf_gpadl_handle ;
@@ -486,20 +471,15 @@ static int negotiate_nvsp_ver(struct hv_device *device,
486
471
return ret ;
487
472
}
488
473
489
- static int netvsc_connect_vsp (struct hv_device * device )
474
+ static int netvsc_connect_vsp (struct hv_device * device ,
475
+ struct netvsc_device * net_device )
490
476
{
491
- int ret ;
492
- struct netvsc_device * net_device ;
493
- struct nvsp_message * init_packet ;
494
- int ndis_version ;
495
477
const u32 ver_list [] = {
496
478
NVSP_PROTOCOL_VERSION_1 , NVSP_PROTOCOL_VERSION_2 ,
497
- NVSP_PROTOCOL_VERSION_4 , NVSP_PROTOCOL_VERSION_5 };
498
- int i ;
499
-
500
- net_device = get_outbound_net_device (device );
501
- if (!net_device )
502
- return - ENODEV ;
479
+ NVSP_PROTOCOL_VERSION_4 , NVSP_PROTOCOL_VERSION_5
480
+ };
481
+ struct nvsp_message * init_packet ;
482
+ int ndis_version , i , ret ;
503
483
504
484
init_packet = & net_device -> channel_init_pkt ;
505
485
@@ -549,7 +529,7 @@ static int netvsc_connect_vsp(struct hv_device *device)
549
529
net_device -> recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE ;
550
530
net_device -> send_buf_size = NETVSC_SEND_BUFFER_SIZE ;
551
531
552
- ret = netvsc_init_buf (device );
532
+ ret = netvsc_init_buf (device , net_device );
553
533
554
534
cleanup :
555
535
return ret ;
@@ -843,7 +823,7 @@ int netvsc_send(struct hv_device *device,
843
823
struct hv_page_buffer * * pb ,
844
824
struct sk_buff * skb )
845
825
{
846
- struct netvsc_device * net_device ;
826
+ struct netvsc_device * net_device = hv_device_to_netvsc_device ( device ) ;
847
827
int ret = 0 ;
848
828
struct netvsc_channel * nvchan ;
849
829
u32 pktlen = packet -> total_data_buflen , msd_len = 0 ;
@@ -854,15 +834,15 @@ int netvsc_send(struct hv_device *device,
854
834
bool try_batch ;
855
835
bool xmit_more = (skb != NULL ) ? skb -> xmit_more : false;
856
836
857
- net_device = get_outbound_net_device ( device );
858
- if (! net_device )
837
+ /* If device is rescinded, return error and packet will get dropped. */
838
+ if (unlikely ( net_device -> destroy ) )
859
839
return - ENODEV ;
860
840
861
841
/* We may race with netvsc_connect_vsp()/netvsc_init_buf() and get
862
842
* here before the negotiation with the host is finished and
863
843
* send_section_map may not be allocated yet.
864
844
*/
865
- if (!net_device -> send_section_map )
845
+ if (unlikely ( !net_device -> send_section_map ) )
866
846
return - EAGAIN ;
867
847
868
848
nvchan = & net_device -> chan_table [packet -> q_idx ];
@@ -1349,7 +1329,7 @@ int netvsc_device_add(struct hv_device *device,
1349
1329
rcu_assign_pointer (net_device_ctx -> nvdev , net_device );
1350
1330
1351
1331
/* Connect with the NetVsp */
1352
- ret = netvsc_connect_vsp (device );
1332
+ ret = netvsc_connect_vsp (device , net_device );
1353
1333
if (ret != 0 ) {
1354
1334
netdev_err (ndev ,
1355
1335
"unable to connect to NetVSP - %d\n" , ret );
@@ -1368,4 +1348,5 @@ int netvsc_device_add(struct hv_device *device,
1368
1348
free_netvsc_device (& net_device -> rcu );
1369
1349
1370
1350
return ret ;
1351
+
1371
1352
}
0 commit comments