Skip to content

Commit a565dd0

Browse files
kuba-mooPaolo Abeni
authored andcommitted
netdevsim: add queue alloc/free helpers
We'll need the code to allocate and free queues in the queue management API, factor it out. Reviewed-by: Willem de Bruijn <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 915c82f commit a565dd0

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

drivers/net/netdevsim/netdev.c

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,24 @@ static const struct netdev_stat_ops nsim_stat_ops = {
595595
.get_base_stats = nsim_get_base_stats,
596596
};
597597

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+
598616
static ssize_t
599617
nsim_pp_hold_read(struct file *file, char __user *data,
600618
size_t count, loff_t *ppos)
@@ -683,11 +701,9 @@ static int nsim_queue_init(struct netdevsim *ns)
683701
return -ENOMEM;
684702

685703
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();
687705
if (!ns->rq[i])
688706
goto err_free_prev;
689-
690-
skb_queue_head_init(&ns->rq[i]->skb_queue);
691707
}
692708

693709
return 0;
@@ -699,16 +715,13 @@ static int nsim_queue_init(struct netdevsim *ns)
699715
return -ENOMEM;
700716
}
701717

702-
static void nsim_queue_free(struct netdevsim *ns)
718+
static void nsim_queue_uninit(struct netdevsim *ns)
703719
{
704720
struct net_device *dev = ns->netdev;
705721
int i;
706722

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]);
712725

713726
kfree(ns->rq);
714727
ns->rq = NULL;
@@ -754,7 +767,7 @@ static int nsim_init_netdevsim(struct netdevsim *ns)
754767
nsim_macsec_teardown(ns);
755768
nsim_bpf_uninit(ns);
756769
err_rq_destroy:
757-
nsim_queue_free(ns);
770+
nsim_queue_uninit(ns);
758771
err_utn_destroy:
759772
rtnl_unlock();
760773
nsim_udp_tunnels_info_destroy(ns->netdev);
@@ -836,7 +849,7 @@ void nsim_destroy(struct netdevsim *ns)
836849
nsim_macsec_teardown(ns);
837850
nsim_ipsec_teardown(ns);
838851
nsim_bpf_uninit(ns);
839-
nsim_queue_free(ns);
852+
nsim_queue_uninit(ns);
840853
}
841854
rtnl_unlock();
842855
if (nsim_dev_port_is_pf(ns->nsim_dev_port))

0 commit comments

Comments
 (0)