Convert allocation of bpf_if in bpfattach2 from M_NOWAIT to M_WAITOK

and remove possible panic condition.

It is already allowed to sleep in bpfattach[2], since BPF_LOCK was
converted to SX lock in r332388. Also move KASSERT() to the top of
function and make full initialization before bpf_if will be linked
to BPF's list of interfaces.

MFC after:	2 weeks
This commit is contained in:
Andrey V. Elsukov 2019-03-19 10:29:32 +00:00
parent 07302582b6
commit c5be49da01
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=345292

View File

@ -2592,16 +2592,16 @@ bpfattach2(struct ifnet *ifp, u_int dlt, u_int hdrlen, struct bpf_if **driverp)
{
struct bpf_if *bp;
bp = malloc(sizeof(*bp), M_BPF, M_NOWAIT | M_ZERO);
if (bp == NULL)
panic("bpfattach");
KASSERT(*driverp == NULL, ("bpfattach2: driverp already initialized"));
bp = malloc(sizeof(*bp), M_BPF, M_WAITOK | M_ZERO);
rw_init(&bp->bif_lock, "bpf interface lock");
LIST_INIT(&bp->bif_dlist);
LIST_INIT(&bp->bif_wlist);
bp->bif_ifp = ifp;
bp->bif_dlt = dlt;
rw_init(&bp->bif_lock, "bpf interface lock");
KASSERT(*driverp == NULL, ("bpfattach2: driverp already initialized"));
bp->bif_hdrlen = hdrlen;
bp->bif_bpf = driverp;
*driverp = bp;
@ -2609,8 +2609,6 @@ bpfattach2(struct ifnet *ifp, u_int dlt, u_int hdrlen, struct bpf_if **driverp)
LIST_INSERT_HEAD(&bpf_iflist, bp, bif_next);
BPF_UNLOCK();
bp->bif_hdrlen = hdrlen;
if (bootverbose && IS_DEFAULT_VNET(curvnet))
if_printf(ifp, "bpf attached\n");
}