@@ -595,6 +595,24 @@ static const struct netdev_stat_ops nsim_stat_ops = {
595
595
.get_base_stats = nsim_get_base_stats ,
596
596
};
597
597
598
+ static struct nsim_rq * nsim_queue_alloc (void )
599
+ {
600
+ struct nsim_rq * rq ;
601
+
602
+ rq = kzalloc (sizeof (* rq ), GFP_KERNEL_ACCOUNT );
603
+ if (!rq )
604
+ return NULL ;
605
+
606
+ skb_queue_head_init (& rq -> skb_queue );
607
+ return rq ;
608
+ }
609
+
610
+ static void nsim_queue_free (struct nsim_rq * rq )
611
+ {
612
+ skb_queue_purge_reason (& rq -> skb_queue , SKB_DROP_REASON_QUEUE_PURGE );
613
+ kfree (rq );
614
+ }
615
+
598
616
static ssize_t
599
617
nsim_pp_hold_read (struct file * file , char __user * data ,
600
618
size_t count , loff_t * ppos )
@@ -683,11 +701,9 @@ static int nsim_queue_init(struct netdevsim *ns)
683
701
return - ENOMEM ;
684
702
685
703
for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
686
- ns -> rq [i ] = kzalloc ( sizeof ( * * ns -> rq ), GFP_KERNEL_ACCOUNT );
704
+ ns -> rq [i ] = nsim_queue_alloc ( );
687
705
if (!ns -> rq [i ])
688
706
goto err_free_prev ;
689
-
690
- skb_queue_head_init (& ns -> rq [i ]-> skb_queue );
691
707
}
692
708
693
709
return 0 ;
@@ -699,16 +715,13 @@ static int nsim_queue_init(struct netdevsim *ns)
699
715
return - ENOMEM ;
700
716
}
701
717
702
- static void nsim_queue_free (struct netdevsim * ns )
718
+ static void nsim_queue_uninit (struct netdevsim * ns )
703
719
{
704
720
struct net_device * dev = ns -> netdev ;
705
721
int i ;
706
722
707
- for (i = 0 ; i < dev -> num_rx_queues ; i ++ ) {
708
- skb_queue_purge_reason (& ns -> rq [i ]-> skb_queue ,
709
- SKB_DROP_REASON_QUEUE_PURGE );
710
- kfree (ns -> rq [i ]);
711
- }
723
+ for (i = 0 ; i < dev -> num_rx_queues ; i ++ )
724
+ nsim_queue_free (ns -> rq [i ]);
712
725
713
726
kfree (ns -> rq );
714
727
ns -> rq = NULL ;
@@ -754,7 +767,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
754
767
nsim_macsec_teardown (ns );
755
768
nsim_bpf_uninit (ns );
756
769
err_rq_destroy :
757
- nsim_queue_free (ns );
770
+ nsim_queue_uninit (ns );
758
771
err_utn_destroy :
759
772
rtnl_unlock ();
760
773
nsim_udp_tunnels_info_destroy (ns -> netdev );
@@ -836,7 +849,7 @@ void nsim_destroy(struct netdevsim *ns)
836
849
nsim_macsec_teardown (ns );
837
850
nsim_ipsec_teardown (ns );
838
851
nsim_bpf_uninit (ns );
839
- nsim_queue_free (ns );
852
+ nsim_queue_uninit (ns );
840
853
}
841
854
rtnl_unlock ();
842
855
if (nsim_dev_port_is_pf (ns -> nsim_dev_port ))
0 commit comments