Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Sep 2019 14:06:04 -0000
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r345794 - stable/12/sys/net
Message-ID:  <201904020931.x329VcSY053467@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Tue Apr  2 09:31:38 2019
New Revision: 345794
URL: https://svnweb.freebsd.org/changeset/base/345794

Log:
  MFC r345292:
    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.

Modified:
  stable/12/sys/net/bpf.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/net/bpf.c
==============================================================================
--- stable/12/sys/net/bpf.c	Tue Apr  2 08:43:19 2019	(r345793)
+++ stable/12/sys/net/bpf.c	Tue Apr  2 09:31:38 2019	(r345794)
@@ -2592,24 +2592,22 @@ bpfattach2(struct ifnet *ifp, u_int dlt, u_int hdrlen,
 {
 	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;
 
 	BPF_LOCK();
 	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");





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904020931.x329VcSY053467>