Skip to content

Commit

Permalink
ifnet: make if_alloc_domain() never fail
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
glebius committed Nov 23, 2021
1 parent 1e3ca25 commit 4787572
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions sys/net/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ ifindex_alloc(void **old)
}

static void
ifindex_free_locked(u_short idx)
ifindex_free(u_short idx)
{

IFNET_WLOCK_ASSERT();
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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();

/*
Expand Down

0 comments on commit 4787572

Please sign in to comment.