@@ -69,7 +69,7 @@ static netdev_tx_t nsim_start_xmit(struct sk_buff *skb, struct net_device *dev)
69
69
rxq = skb_get_queue_mapping (skb );
70
70
if (rxq >= peer_dev -> num_rx_queues )
71
71
rxq = rxq % peer_dev -> num_rx_queues ;
72
- rq = & peer_ns -> rq [rxq ];
72
+ rq = peer_ns -> rq [rxq ];
73
73
74
74
skb_tx_timestamp (skb );
75
75
if (unlikely (nsim_forward_skb (peer_dev , skb , rq ) == NET_RX_DROP ))
@@ -388,13 +388,13 @@ static int nsim_init_napi(struct netdevsim *ns)
388
388
int err , i ;
389
389
390
390
for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
391
- rq = & ns -> rq [i ];
391
+ rq = ns -> rq [i ];
392
392
393
393
netif_napi_add_config (dev , & rq -> napi , nsim_poll , i );
394
394
}
395
395
396
396
for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
397
- rq = & ns -> rq [i ];
397
+ rq = ns -> rq [i ];
398
398
399
399
err = nsim_create_page_pool (rq );
400
400
if (err )
@@ -405,12 +405,12 @@ static int nsim_init_napi(struct netdevsim *ns)
405
405
406
406
err_pp_destroy :
407
407
while (i -- ) {
408
- page_pool_destroy (ns -> rq [i ]. page_pool );
409
- ns -> rq [i ]. page_pool = NULL ;
408
+ page_pool_destroy (ns -> rq [i ]-> page_pool );
409
+ ns -> rq [i ]-> page_pool = NULL ;
410
410
}
411
411
412
412
for (i = 0 ; i < dev -> num_rx_queues ; i ++ )
413
- __netif_napi_del (& ns -> rq [i ]. napi );
413
+ __netif_napi_del (& ns -> rq [i ]-> napi );
414
414
415
415
return err ;
416
416
}
@@ -421,7 +421,7 @@ static void nsim_enable_napi(struct netdevsim *ns)
421
421
int i ;
422
422
423
423
for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
424
- struct nsim_rq * rq = & ns -> rq [i ];
424
+ struct nsim_rq * rq = ns -> rq [i ];
425
425
426
426
netif_queue_set_napi (dev , i , NETDEV_QUEUE_TYPE_RX , & rq -> napi );
427
427
napi_enable (& rq -> napi );
@@ -448,16 +448,16 @@ static void nsim_del_napi(struct netdevsim *ns)
448
448
int i ;
449
449
450
450
for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
451
- struct nsim_rq * rq = & ns -> rq [i ];
451
+ struct nsim_rq * rq = ns -> rq [i ];
452
452
453
453
napi_disable (& rq -> napi );
454
454
__netif_napi_del (& rq -> napi );
455
455
}
456
456
synchronize_net ();
457
457
458
458
for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
459
- page_pool_destroy (ns -> rq [i ]. page_pool );
460
- ns -> rq [i ]. page_pool = NULL ;
459
+ page_pool_destroy (ns -> rq [i ]-> page_pool );
460
+ ns -> rq [i ]-> page_pool = NULL ;
461
461
}
462
462
}
463
463
@@ -628,7 +628,7 @@ nsim_pp_hold_write(struct file *file, const char __user *data,
628
628
if (!netif_running (ns -> netdev ) && val ) {
629
629
ret = - ENETDOWN ;
630
630
} else if (val ) {
631
- ns -> page = page_pool_dev_alloc_pages (ns -> rq [0 ]. page_pool );
631
+ ns -> page = page_pool_dev_alloc_pages (ns -> rq [0 ]-> page_pool );
632
632
if (!ns -> page )
633
633
ret = - ENOMEM ;
634
634
} else {
@@ -677,27 +677,40 @@ static int nsim_queue_init(struct netdevsim *ns)
677
677
struct net_device * dev = ns -> netdev ;
678
678
int i ;
679
679
680
- ns -> rq = kvcalloc (dev -> num_rx_queues , sizeof (* ns -> rq ),
681
- GFP_KERNEL_ACCOUNT | __GFP_RETRY_MAYFAIL );
680
+ ns -> rq = kcalloc (dev -> num_rx_queues , sizeof (* ns -> rq ),
681
+ GFP_KERNEL_ACCOUNT );
682
682
if (!ns -> rq )
683
683
return - ENOMEM ;
684
684
685
- for (i = 0 ; i < dev -> num_rx_queues ; i ++ )
686
- skb_queue_head_init (& ns -> rq [i ].skb_queue );
685
+ for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
686
+ ns -> rq [i ] = kzalloc (sizeof (* * ns -> rq ), GFP_KERNEL_ACCOUNT );
687
+ if (!ns -> rq [i ])
688
+ goto err_free_prev ;
689
+
690
+ skb_queue_head_init (& ns -> rq [i ]-> skb_queue );
691
+ }
687
692
688
693
return 0 ;
694
+
695
+ err_free_prev :
696
+ while (i -- )
697
+ kfree (ns -> rq [i ]);
698
+ kfree (ns -> rq );
699
+ return - ENOMEM ;
689
700
}
690
701
691
702
static void nsim_queue_free (struct netdevsim * ns )
692
703
{
693
704
struct net_device * dev = ns -> netdev ;
694
705
int i ;
695
706
696
- for (i = 0 ; i < dev -> num_rx_queues ; i ++ )
697
- skb_queue_purge_reason (& ns -> rq [i ]. skb_queue ,
707
+ for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
708
+ skb_queue_purge_reason (& ns -> rq [i ]-> skb_queue ,
698
709
SKB_DROP_REASON_QUEUE_PURGE );
710
+ kfree (ns -> rq [i ]);
711
+ }
699
712
700
- kvfree (ns -> rq );
713
+ kfree (ns -> rq );
701
714
ns -> rq = NULL ;
702
715
}
703
716
0 commit comments