From 4787572d0580c6fdf818fd64efa3089de88720f0 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Mon, 22 Nov 2021 19:49:57 -0800 Subject: [PATCH] ifnet: make if_alloc_domain() never fail The last consumer of if_com_alloc() is firewire. It never fails to allocate. Most likely the if_com_alloc() KPI will go away together with if_fwip(), less likely new consumers of if_com_alloc() will be added, but they would need to follow the no fail KPI. --- sys/net/if.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index f840fa369474..9f971d958030 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -406,7 +406,7 @@ ifindex_alloc(void **old) } static void -ifindex_free_locked(u_short idx) +ifindex_free(u_short idx) { IFNET_WLOCK_ASSERT(); @@ -417,15 +417,6 @@ ifindex_free_locked(u_short idx) V_if_index--; } -static void -ifindex_free(u_short idx) -{ - - IFNET_WLOCK(); - ifindex_free_locked(idx); - IFNET_WUNLOCK(); -} - static void ifnet_setbyindex(u_short idx, struct ifnet *ifp) { @@ -636,11 +627,8 @@ if_alloc_domain(u_char type, int numa_domain) #endif if (if_com_alloc[type] != NULL) { ifp->if_l2com = if_com_alloc[type](type, ifp); - if (ifp->if_l2com == NULL) { - free(ifp, M_IFNET); - ifindex_free(idx); - return (NULL); - } + KASSERT(ifp->if_l2com, ("%s: if_com_alloc[%u] failed", __func__, + type)); } IF_ADDR_LOCK_INIT(ifp); @@ -735,7 +723,7 @@ if_free(struct ifnet *ifp) KASSERT(ifp == ifnet_byindex(ifp->if_index), ("%s: freeing unallocated ifnet", ifp->if_xname)); - ifindex_free_locked(ifp->if_index); + ifindex_free(ifp->if_index); IFNET_WUNLOCK(); if (refcount_release(&ifp->if_refcount)) @@ -1356,7 +1344,7 @@ if_vmove(struct ifnet *ifp, struct vnet *new_vnet) * or we'd lock on one vnet and unlock on another. */ IFNET_WLOCK(); - ifindex_free_locked(ifp->if_index); + ifindex_free(ifp->if_index); IFNET_WUNLOCK(); /*